You are on page 1of 65

CHAPTER 1

INTRODUCTION
1.1 Introduction:

The health monitoring and controlling system in the hospital need to be


continuously monitor by the doctors or others staff of the hospital. These health monitoring
system include heart beat monitoring system, oxygen monitoring system, saline monitoring
system, blood pressure monitoring and many such system where continuous monitoring and
parameter checking required. Most of the current health monitoring and controlling system
having interfaces like monitor, LCD display and some control switches. It is impossible for
the doctors and nurses and other hospital staff to continuously work only for single patient.
These interfaces are fixed and connected to the health monitoring and controlling system
using wires. We can provide these interfaces to the doctor using wireless network link like
ZigBee. The charecterstics of ZigBee like low power , low cost, range upto 100 meter and
network forming ability make ZigBee technology an ideal choice for wireless monitoring and
controlling network in health monitoring systems.
In our proposed system we are using ZigBee module, 8051 microcontroller system and
one temperature sensor who monitor the temperature contineouly. This module continuously
send the temperature to the doctor who having ZigBee enbabled 8051 microcontroller
system.The doctor can set certain parameters in the microcontroller program so if the
temperature range exceeds that parameter it will give alert message.The doctor will send
corrective control code from his wireless terminal to patient terminal.

SOFTWARE: Embedded ‘C’


TOOLS: Keil , Flash magic
TARGET DEVICE: 8051 microcontroller.
APPLICATIONS: Real time to track the assets.
ADVANTAGES: Low cost, automated operation, Low Power consumption,
security.
REFERENCE: The 8051 micro controller and embedded systems by Mazidi .

1
1.2 BLOCK DIAGRAM:

In this chapter the block diagram of the project and design aspect of independent
modules are considered. Block diagram is shown in the below fig

Figure (i): Block diagram representing the transmitter section of the project present at
the Stable Patient monitoring system

Figure (ii): Block diagram representing the receiver section of the project present at the
Doctors Mobile monitoring terminal

1.3 Project overview:


2
An embedded system is a combination of software and hardware to perform a
dedicated task. Some of the main devices used in embedded products are Microprocessors and
Microcontrollers. Microprocessors are commonly referred to as general purpose processors as
they simply accept the inputs, process it and give the output. In contrast, a microcontroller not
only accepts the data as inputs but also manipulates it, interfaces the data with various devices,
controls the data and thus finally gives the result.

The project zigbee device access control and reliable data transmission in zigbee based
health monitoring system is constructed by using Atmel AT 89S52. Microcontroller and is an
exclusive project that is used to provide health monitoring system.

CHAPTER 2
EMBEDDED SYSTEMS

3
2.1 Embedded systems:

An embedded system is a special-purpose computer system designed to perform one or


a few dedicated functions, sometimes with real-time computing constraints. It is usually
embedded as part of a complete device including hardware and mechanical parts. In contrast,
a general-purpose computer, such as a personal computer, can do many different tasks
depending on programming. Embedded systems have become very important today as they
control many of the common devices we use.

Since the embedded system is dedicated to specific tasks, design engineers can
optimize it, reducing the size and cost of the product, or increasing the reliability and
performance. Some embedded systems are mass-produced, benefiting from economies of
scale.

Physically, embedded systems range from portable devices such as digital watches and
MP3 players, to large stationary installations like traffic lights, factory controllers, or the
systems controlling nuclear power plants. Complexity varies from low, with a single
microcontroller chip, to very high with multiple units, peripherals and networks mounted
inside a large chassis or enclosure.

In general, "embedded system" is not an exactly defined term, as many systems have
some element of programmability. For example, Handheld computers share some elements
with embedded systems — such as the operating systems and microprocessors which power
them — but are not truly embedded systems, because they allow different applications to be
loaded and peripherals to be connected.

An embedded system is some combination of computer hardware and software, either


fixed in capability or programmable, that is specifically designed for a particular kind of
application device. Industrial machines, automobiles, medical equipment, cameras, household
appliances, airplanes, vending machines, and toys (as well as the more obvious cellular phone
and PDA) are among the myriad possible hosts of an embedded system. Embedded systems
that are programmable are provided with a programming interface, and embedded systems
programming is a specialized occupation.

2.2 Need for embedded systems:


4
The uses of embedded systems are virtually limitless, because every day new products
are introduced to the market that utilizes embedded computers in novel ways. In recent years,
hardware such as microprocessors, microcontrollers, and FPGA chips have become much
cheaper. So when implementing a new form of control, it's wiser to just buy the generic chip
and write your own custom software for it. Producing a custom-made chip to handle a
particular task or set of tasks costs far more time and money. Many embedded computers even
come with extensive libraries, so that "writing your own software" becomes a very trivial task
indeed. From an implementation viewpoint, there is a major difference between a computer
and an embedded system. Embedded systems are often required to provide Real-Time
response. The main elements that make embedded systems unique are its reliability and ease
in debugging.

2.3 Microcontroller versus microprocessor:

What is the difference between a Microprocessor and Microcontroller? By


microprocessor is meant the general purpose Microprocessors such as Intel's X86 family
(8086, 80286, 80386, 80486, and the Pentium) or Motorola's 680X0 family (68000, 68010,
68020, 68030, 68040, etc). These microprocessors contain no RAM, no ROM, and no I/O
ports on the chip itself. For this reason, they are commonly referred to as general-purpose
Microprocessors.

A system designer using a general-purpose microprocessor such as the Pentium or the


68040 must add RAM, ROM, I/O ports, and timers externally to make them functional.
Although the addition of external RAM, ROM, and I/O ports makes these systems bulkier and
much more expensive, they have the advantage of versatility such that the designer can decide
on the amount of RAM, ROM and I/O ports needed to fit the task at hand. This is not the case
with Microcontrollers.

A Microcontroller has a CPU (a microprocessor) in addition to a fixed amount of


RAM, ROM, I/O ports, and a timer all on a single chip. In other words, the processor, the
RAM, ROM, I/O ports and the timer are all embedded together on one chip; therefore, the
designer cannot add any external memory, I/O ports, or timer to it. The fixed amount of on-
chip ROM, RAM, and number of I/O ports in Microcontrollers makes them ideal for many
applications in which cost and space are critical.

5
In many applications, for example a TV remote control, there is no need for the
computing power of a 486 or even an 8086 microprocessor. These applications most often
require some I/O operations to read signals and turn on and off certain bits.

microcontrollers for embedded systems

In the Literature discussing microprocessors, we often see the term Embedded System.
Microprocessors and Microcontrollers are widely used in embedded system products. An
embedded system product uses a microprocessor (or Microcontroller) to do one task only. A
printer is an example of embedded system since the processor inside it performs one task only;
namely getting the data and printing it. Contrast this with a Pentium based PC. A PC can be
used for any number of applications such as word processor, print-server, bank teller terminal,
Video game, network server, or Internet terminal. Software for a variety of applications can be
loaded and run. Of course the reason a pc can perform myriad tasks is that it has RAM
memory and an operating system that loads the application software into RAM memory and
lets the CPU run it.

In an Embedded system, there is only one application software that is typically burned
into ROM. An x86 PC contains or is connected to various embedded products such as
keyboard, printer, modem, disk controller, sound card, CD-ROM drives, mouse, and so on.
Each one of these peripherals has a Microcontroller inside it that performs only one task. For
example, inside every mouse there is a Microcontroller to perform the task of finding the
mouse position and sending it to the PC.

CHAPTER 3
HARDWARE DESCRIPTION
3.1 Working explanation:
6
Mainly the block diagram consists of following parts:

 Power supply circuit


 AT 89S52 controller
 ZigBee module(transceiver)
 Max-232
 Lcd
 Temperature sensor
Generally we get 230v of power supply but we need only 3.3v to generate the micro
controller so before giving the power supply directly to it we will use transformer, capacitive
filters , generators to convert 230v of power supply to the required amount to provide required
supply to the micro controller. Here we are the adjusting the output voltage to our required
amount. Here we are using 8051 micro controller so it requires only 3.3v so we use another
module to get 3.3v supply to the 8051.

Here we are using graphical LCD as the output to display the data. The graphical LCD is
used to display the images so we are using graphical LCD here. To connect the LCD to the
8051 it contains four data pins for getting data from the micro controller and to display data on
LCD. We connect four data pins to port0 as shown below which is used to transfer the data
and to display it on the LCD.

P0.4 --> D0
P0.5 --> D1
P0.6 --> D2
P0.7 --> D3
To enable the LCD we use enable pin to set the enable pin we use IOSET to enable the pin
P0.22 to display data on the LCD. We can also used to set read and read and write pins enable
by using IOSET the pins are P0.23, P0.24.

Here we are using Zigbee is connected to the UART0 to the pins TXD0, RXD0 pins that
is pins 19, 20 respectively. Here TXD pin is used to transmit data and RXD pins to receive
data. Here zigbee module is interfaced serially with the micro controller to either transmit or
to receive data.

This project Zigbee device access control and reliable data transmission based health
monitoring system will be used to monitor patient’s condition in the hospital. Where it

7
impossible for the doctor to check each and every patient at every minute this project be used
efficiently where more no people’s health monitored. In this the Transmitting section will be
placed in the each patient room which consisting of Different sensors like Heart beat
monitoring and Temperature sensor etc. in our case we are considering the temperature sensor
to monitor the patient body temperature which indicates Fever status of the patient and if the
patient’s body temperature increases at a certain point immediately that information will be
transmitted to the Receiving section which presents in the Doctor’s room. So doctor will come
and immediately checks the patient.
Here at receiving section in the doctors PC consists of a VB software based GUI by this
the doctor will see that sensed information.

3.2 MICROCONTROLLER:

Fig: 3.1: Microcontroller

3.2.1 Introduction to Microcontroller:

Circumstances that we find ourselves in today in the field of microcontrollers had their
beginnings in the development of technology of integrated circuits. This development has
made it possible to store hundreds of thousands of transistors into one chip. That was a
prerequisite for production of microprocessors, and the first computers were made by adding
external peripherals such as memory, input-output lines, timers and other. Further increasing
of the volume of the package resulted in creation of integrated circuits. These integrated
circuits contained both processor and peripherals. That is how the first chip containing a
microcomputer, or what would later be known as a microcontroller came about.

Microprocessors and microcontrollers are widely used in embedded systems products.


Microcontroller is a programmable device. A microcontroller has a CPU in addition to a fixed

8
amount of RAM, ROM, I/O ports and a timer embedded all on a single chip. The fixed
amount of on-chip ROM, RAM and number of I/O ports in microcontrollers makes them ideal
for many applications in which cost and space are critical.

3.2.2 Description of AT 89S52 microcontroller:

The AT89S52 is a low-power, high-performance CMOS 8-bit microcontroller with 8K


bytes of in-system programmable Flash memory. The device is manufactured using Atmel’s
high-density non-volatile memory technology and is compatible with the industry-standard
80C51 instruction set and pin out. The on-chip Flash allows the program memory to be
reprogrammed in-system or by a conventional non-volatile memory programmer. By
combining a versatile 8-bit CPU with in-system programmable Flash on a monolithic chip, the
Atmel AT89S52 is a powerful microcontroller which provides a highly-flexible and cost-
effective solution to many embedded control applications.

The AT89S52 provides the following standard features: 8K bytes of Flash, 256 bytes
of RAM, 32 I/O lines, Watchdog timer, two data pointers, three 16-bit timer/counters, a six-
vector two-level interrupt architecture, a full duplex serial port, on-chip oscillator, and clock
circuitry. In addition, the AT89S52 is designed with static logic for operation down to zero
frequency and supports two software selectable power saving modes. The Idle Mode stops the
CPU while allowing the RAM, timer/counters, serial port, and interrupt system to continue
functioning. The Power-down mode saves the RAM contents but freezes the oscillator,
disabling all other chip functions until the next interrupt or hardware reset.

3.2.3 Features of AT89S52 architecture:

 8K Bytes of In-System Programmable (ISP) Flash Memory

--Endurance: 1000 Write/Erase Cycles

 4.0V to 5.5V Operating Range

 Fully Static Operation: 0 Hz to 33 MHz

 Three-level Program Memory Lock

 256 x 8-bit Internal RAM

9
 32 Programmable I/O Lines

 Three 16-bit Timer/Counters

 Eight Interrupt Sources

 Full Duplex UART Serial Channel

 Low-power Idle and Power-down Modes

 Interrupt Recovery from Power-down Mode

 Watchdog Timer

 Dual Data Pointer

 Power-off Flag

Now we may be wondering about the non-mentioning of memory space meant for
the program storage, the most important part of any embedded controller. Originally
this AT 89S52 architecture was introduced with on-chip, ‘one time programmable’
version of Program Memory of size 8K X 8. Intel delivered all these
microcontrollers (AT 89S52) with user’s program fused inside the device. The
memory portion was mapped at the lower end of the Program Memory area. But, after
getting devices, customers couldn’t change anything in their program code, which
was already made available inside during device fabrication.

3.2.4 Pin Configuration:

10
Figure 3.2: Pin diagram of AT 89S52 microcontroller

Vcc: Pin 40 provides supply voltage to the chip. The voltage source is +5v.

Gnd: Pin 20 is the ground.

Ports 0, 1, 2 and 3:

As shown in pin diagram, the four ports P0, P1, P2, and P3 each with 8 pins, make the
8-bit ports. All the ports upon Reset are configured as input, since P0-P3 have FFH on them.

Port 0:

Port 0 occupies a total of 8 pins (pins 32-33). It can be used for input or output. Port0
is also designated as AD0-AD7, allowing it to be used for both address and data. When
connecting an AT 89S52 to an external memory, port 0 provides both address and data. The
AT 89S52 multiplexes address and data through port 0 to save pins. ALE=0, it provides data
D0-D7, but when ALE=1, it has address A0-A7. Therefore, ALE is used for demultiplexing

11
address and data with the help of a 74LS373 latch. In the AT 89S52-based systems where
there is no external memory connection, the pins of P0 must be connected externally to a 10k
–ohm pull-up resistor. With external pull-up resistors connected to P0, it can be used as a
simple I/O port, just like P1 and P2. In contrast to Port 0, ports p1, p2, and p3 do not need any
pull-up resistors since they already have pull-up resistors internally. Upon reset, ports p1, p2,
and p3 are configured as input ports.

Port 0 can also be configured to be the multiplexed low order address/data bus during
accesses to external program and data memory. In this mode, P0 has internal pull-ups. Port 0
also receives the code bytes during Flash programming and outputs the code bytes during
program verification. External pull-ups are required during program verification.

Port 1:

Port 1 is an 8-bit bidirectional I/O port with internal pull-ups. The Port 1 output buffers
can sink/source four TTL inputs. When 1s are written to Port 1 pins, they are pulled high by
the internal pullups and can be used as inputs. As inputs, Port 1 pins that are externally being
pulled low will source current (IIL) because of the internal pullups. In addition, P1.0 and P1.1
can be configured to be the timer/counter 2 external count input (P1.0/T2) and the
timer/counter 2 trigger input (P1.1/T2EX), respectively, as shown in the following table. Port
1 also receives the low-order address bytes during Flash programming and verification.

Table 3.1: Port1 pins of microcontroller

Port 2:

12
Port 2 occupies a total 8 pins (pins 21-28). It can be used as input or output. However,
in 8031-based systems, port2 is also designated as A8-A15, indicating its dual function. Since
an AT 89S52/31 is capable of accessing 64K bytes of external memory, it needs a path for the
16 bits of the address. While P0 provides the lower 8 bits via A0-A7, it is the job of p2 is
used for the upper 8 bits of the 16-bit address, and it cannot be used for I/O. Just like P1, port
2 does not need any pull-up resistors since it already has pull-up resistors internally. Upon
reset, port2 is configured as an input port.

Port 2 is an 8-bit bidirectional I/O port with internal pull-ups. The Port 2 output buffers
can sink/source four TTL inputs. When 1s are written to Port 2 pins, they are pulled high by
the internal pullups and can be used as inputs. As inputs, Port 2 pins that are externally being
pulled low will source current (IIL) because of the internal pull-ups. Port 2 emits the high-
order address byte during fetches from external program memory and during accesses to
external data memory that uses 16-bit addresses (MOVX @ DPTR). In this application, Port 2
uses strong internal pull-ups when emitting 1s. During accesses to external data memory that
uses 8-bit addresses (MOVX @ RI), Port 2 emits the contents of the P2 Special Function
Register. Port 2 also receives the high-order address bits and some control signals during
Flash programming and verification.

Port 3:

Port 3 occupies a total of 8 pins (pins 10-17). It can be used as input or output. P3
does not need any pull-up resistors, just as P1 and P2 did not. Although Port 3 is configured
as an input port upon reset, this is not the way it is most commonly used. Port 3 has the
additional function of providing some extremely important signals such as interrupts. The
below table provides these alternate functions of P3. This is information applies to both AT
89S52 and 8031 chips.

13
Table 3.2: Port3 pins of microcontroller

Alternate Functions of Port 3:

Port 3 also receives some control signals for Flash programming and verification.

RST:

Reset input. A high on this pin for two machine cycles while the oscillator is running
resets the device. This pin drives High for 96 oscillator periods after the Watchdog times out.
The DISRTO bit in SFR AUXR (address 8EH) can be used to disable this feature. In the
default state of bit DISRTO, the RESET HIGH out feature is enabled.

Address Latch Enable (ALE) is an output pulse for latching the low byte of the address

during accesses to external memory. This pin is also the program pulse input
during Flash programming. In normal operation, ALE is emitted at a constant rate of 1/6 the
oscillator frequency and may be used for external timing or clocking purposes. Note, however,
that one ALE pulse is skipped during each access to external data memory. If desired, ALE
operation can be disabled by setting bit 0 of SFR location 8EH. With the bit set, ALE is active
only during a MOVX or MOVC instruction. Otherwise, the pin is weakly pulled high. Setting
the ALE-disable bit has no effect if the microcontroller is in external execution mode.

14
:

Program Store Enable is the read strobe to external Program Memory. When the
device is executing out of external Program Memory, this port is activated twice each machine
cycle (except that two PSEN activations are skipped during accesses to external Data
Memory). PSEN is not activated when the device is executing out of internal Program
Memory.

When EA is held high the CPU executes out of internal Program Memory (unless the
Program Counter exceeds 0FFFH in the AT 89S52). Holding EA low forces the CPU to
execute out of external memory regardless of the Program Counter value. In the 80C31, EA
must be externally wired low. In the EPROM devices, this pin also receives the programming
supply voltage (VPP) during EPROM programming.

XTAL1:

Input to the inverting oscillator amplifier and input to the internal clock operating
circuit.

XTAL2:

Output from the inverting oscillator amplifier.

The AT 89S52’s I/O port structure is extremely versatile and flexible. The
device has 32 I/O pins configured as four eight bit parallel ports (P0, P1, P2 and P3).
Each pin can be used as an input or as an output under the software control. These
I/O pins can be accessed directly by memory instructions during program execution
to get required flexibility.

These port lines can be operated in different modes and all the pins can be made
to do many different tasks apart from their regular I/O function executions.
Instructions, which access external memory, use port P0 as a multiplexed
address/data bus. At the beginning of an external memory cycle, low order 8 bits of
the address bus are output on P0. The same pins transfer data byte at the later stage of
the instruction execution.

15
Also, any instruction that accesses external Program Memory will output the
higher order byte on P2 during read cycle. Remaining ports, P1 and P3 are available
for standard I/O functions. But all the 8 lines of P3 support special functions: Two
external interrupt lines, two counter inputs, serial port’s two data lines and two timing
control strobe lines are designed to use P3 port lines. When you don’t use these
special functions, you can use corresponding port lines as a standard I/O. Even within
a single port, I/O operations may be combined in many ways. Different pins can be
configured as input or outputs independent of each other or the same pin can be used as
an input or as output at different times. You can comfortably combine I/O operations
and special operations for Port 3 lines.

3.2.5 Memory organisation:

MCS-51 devices have a separate address space for Program and Data Memory. Up to
64K bytes each of external Program and Data Memory can be addressed.

Program Memory

If the EA pin is connected to GND, all program fetches are directed to external
memory. On the AT89S52, if EA is connected to VCC, program fetches to addresses 0000H
through 1FFFH are directed to internal memory and fetches to addresses 2000H through
FFFFH are to external memory.

Data Memory

The AT89S52 implements 256 bytes of on-chip RAM. The upper 128 bytes occupy a
parallel address space to the Special Function Registers. This means that the upper 128 bytes
have the same addresses as the SFR space but are physically separate from SFR space. When
an instruction accesses an internal location above address 7FH, the address mode used in the
instruction specifies whether the CPU accesses the upper 128 bytes of RAM or the SFR space.
Instructions which use direct addressing access of the SFR space. For example, the following
direct addressing instruction accesses the SFR at location 0A0H (which is P2).

MOV 0A0H, #data

16
Instructions that use indirect addressing access the upper 128 bytes of RAM. For
example, the following indirect addressing instruction, where R0 contains 0A0H, accesses the
data byte at address 0A0H, rather than P2 (whose address is 0A0H).

MOV @R0, #data

Note that stack operations are examples of indirect addressing, so the upper 128 bytes
of data RAM are available as stack space.

3.2.6 Basic registers:

In the CPU, registers are used to store information temporarily. That information
could be a byte of data to be processed, or an address pointing to the data to be fetched. The
vast majority of AT 89S52 registers are 8–bit registers. In the AT 89S52 there is only one
data type: 8bits. The 8 bits of a register are shall be in the diagram from the MSB (most
significant bit) D7 to the LSB (least significant bit) D0. With an 8-bit data type, any data
larger than 8bits must be broken into 8-bit chunks before it is processed.

The most widely used registers of the AT 89S52 are A(accumulator), B, R0, R1, R2,
R3, R4, R5, R6, R7, DPTR(data pointer), and PC(program counter). All of the above registers
are 8-bits, except DPTR and the program counter.

The Accumulator:

If you've worked with any other assembly language you will be familiar with the
concept of an accumulator register.

The Accumulator, as its name suggests, is used as a general register to accumulate the
results of a large number of instructions. It can hold an 8-bit (1-byte) value and is the most
versatile register the AT 89S52 has due to the sheer number of instructions that make use of
the accumulator. More than half of the AT 89S52's 255 instructions manipulate or use the
Accumulator in some way. For example, if you want to add the number 10 and 20, the
resulting 30 will be stored in the Accumulator. Once you have a value in the Accumulator you
may continue processing the value or you may store it in another register or in memory.

17
The "R" Registers:

The "R" registers are sets of eight registers that are named R0, R1, through R7. These
registers are used as auxiliary registers in many operations. To continue with the above
example, perhaps you are adding 10 and 20. The original number 10 may be stored in the
Accumulator whereas the value 20 may be stored in, say, register R4. To process the addition
you would execute the command:

 ADD A, R4

After executing this instruction the Accumulator will contain the value 30. You may
think of the "R" registers as very important auxiliary, or "helper", registers. The Accumulator
alone would not be very useful if it were not for these "R" registers.

The "R" registers are also used to store values temporarily. For example, let’s say you
want to add the values in R1 and R2 together and then subtract the values of R3 and R4. One
way to do this would be:

MOV A, R3                ; Move the value of R3 to accumulator

ADD A, R4                ; add the value of R4

MOV R5, A                ; Store the result in R5

MOV A, R1                ; Move the value of R1 to Acc

ADD A, R2                ; add the value of R2 with A

SUBB A, R5                ; Subtract the R5 (which has R3+R4)

As you can see, we used R5 to temporarily hold the sum of R3 and R4. Of course, this
isn't the most efficient way to calculate (R1+R2) - (R3 +R4) but it does illustrate the use of the
"R" registers as a way to store values temporarily.

As mentioned earlier, there are four sets of "R" registers-register bank 0, 1, 2, and 3.
When the 8052 is first powered up, register bank 0 (addresses 00h through 07h) is used by
default. In this case, for example, R4 is the same as Internal RAM address 04h. However, your
program may instruct the 8052 to use one of the alternate register banks; i.e., register banks 1,
2, or 3. In this case, R4 will no longer be the same as Internal RAM address 04h. For example,
if your program instructs the 8052 to use register bank 1, register R4 will now be synonymous

18
with Internal RAM address 0Ch. If you select register bank 2, R4 is synonymous with 14h,
and if you select register bank 3 it is synonymous with address 1Ch.

The concept of register banks adds a great level of flexibility to the 8052, especially
when dealing with interrupts (we'll talk about interrupts later). However, always remember
that the register banks really reside in the first 32 bytes of Internal RAM.

The B Register:

The "B" register is very similar to the Accumulator in the sense that it may hold an 8-
bit (1-byte) value. The "B" register is only used implicitly by two AT 89S52 instructions:
MUL AB and DIV AB. Thus, if you want to quickly and easily multiply or divide A by
another number, you may store the other number in "B" and make use of these two
instructions.

Aside from the MUL and DIV instructions, the "B" register are often used as yet
another temporary storage register much like a ninth "R" register.

The Program Counter:

The Program Counter (PC) is a 2-byte address that tells the AT 89S52 where the next
instruction to execute is found in memory. When the AT 89S52 is initialized PC always starts
at 0000h and is incremented each time an instruction is executed. It is important to note that
PC isn't always incremented by one. Since some instructions are 2 or 3 bytes in length the PC
will be incremented by 2 or 3 in these cases.

The Program Counter is special in that there is no way to directly modify its value.
That is to say, you can't do something like PC=2430h. On the other hand, if you execute
LJMP 2430h you've effectively accomplished the same thing.

It is also interesting to note that while you may change the value of PC (by executing a
jump instruction, etc.) there is no way to read the value of PC. That is to say, there is no way
to ask the 8052 "What address are you about to execute?" As it turns out, this is not
completely true: There is one trick that may be used to determine the current value of PC.

19
The Data Pointer:

The Data Pointer (DPTR) in the AT 89S52 is only user-accessible 16-bit (2-byte)
register. The Accumulator, "R" registers, and "B" register are all 1-byte values. The PC just
described is a 16-bit value but isn't directly user-accessible as a working register.

DPTR, as the name suggests, is used to point to data. It is used by a number of


commands that allow the AT 89S52 to access external memory. When the AT 89S52 accesses
external memory it accesses the memory at the address indicated by DPTR.

While DPTR is most often used to point to data in external memory or code memory,
many developers take advantage of the fact that it's the only true 16-bit register available. It is
often used to store 2-byte values that have nothing to do with memory locations.

The Stack Pointer:

The Stack Pointer, like all registers except DPTR and PC, may hold an 8-bit (1-byte)
value. The Stack Pointer is used to indicate where the next value to be removed from the stack
should be taken from.

When you push a value onto the stack, the AT 89S52 first increments the value of SP
and then stores the value at the resulting memory location. When you pop a value off the
stack, the AT 89S52 returns the value from the memory location indicated by SP and then
decrements the value of SP.

This order of operation is important. When the AT 89S52 is initialized SP will be


initialized to 07h. If you immediately push a value onto the stack, the value will be stored in
Internal RAM address 08h. This makes sense taking into account what was mentioned two
paragraphs above: First the AT 89S52 will increment the value of SP (from 07h to 08h) and
then will store the pushed value at that memory address (08h).

Register Instructions:

The register banks, containing registers R0 through R7, can be accessed by certain
instructions which carry a 3-bit register specification within the opcode of the instruction.
Instructions that access the registers this way are code efficient, since this mode eliminates an
address byte. When the instruction is executed, one of the eight registers in the selected bank

20
is accessed. One of four banks is selected at execution time by the two bank select bits in the
PSW.

Register-Specific Instructions:

Some instructions are specific to a certain register. For example, some instructions
always operate on the Accumulator, or Data Pointer, etc., so no address byte is needed to point
to it. The opcode itself does that. Instructions that refer to the Accumulator as A assemble as
accumulator specific opcodes.

Immediate Constants:

The value of a constant can follow the opcode in Program Memory. For example,

MOV A, #100

loads the Accumulator with the decimal number 100. The same number could be specified in
hex digits as 64H.

3.2.7 Central processing unit:

The CPU is the brain of the microcontrollers reading user’s programs and
executing the expected task as per instructions stored there in. Its primary elements
are an 8 bit Arithmetic Logic Unit (ALU ) , Accumulator (Acc ) , few more 8 bit
registers , B register, Stack Pointer (SP ) , Program Status Word (PSW) and 16 bit
registers, Program Counter (PC) and Data Pointer Register (DPTR).

The ALU (Acc) performs arithmetic and logic functions on 8 bit input
variables. Arithmetic operations include basic addition, subtraction, and multiplication
and division. Logical operations are AND, OR, Exclusive OR as well as rotate, clear,
complement and etc. Apart from all the above, ALU is responsible in conditional
branching decisions, and provides a temporary place in data transfer operations
within the device.

B-register is mainly used in multiply and divides operations. During


execution, B register either keeps one of the two inputs or then retains a portion of the
result. For other instructions, it can be used as another general purpose register.

Program Status Word (PSW) keeps the current status of the ALU in different
21
bits. Stack Pointer (SP) is an 8 bit register. This pointer keeps track of memory space
where the important register information is stored when the program flow gets into
executing a subroutine. The stack portion may be placed in any where in the on-
chip RAM. But normally SP is initialized to 07H after a device reset and grows up
from the location 08H. The Stack Pointer is automatically incremented or
decremented for all PUSH or POP instructions and for all subroutine calls and
returns.

Program Counter (PC) is the 16 bit register giving address of next instruction
to be executed during program execution and it always points to the Program
Memory space. Data Pointer (DPTR) is another 16 bit addressing register that can be
used to fetch any 8 bit data from the data memory space. When it is not being used
for this purpose, it can be used as two eight bit registers.

3.2.8 Timers/counters:

Watchdog Timer (One-time Enabled with Reset-out):

The WDT is intended as a recovery method in situations where the CPU may be
subjected to software upsets. The WDT consists of a 13-bit counter and the Watchdog Timer
Reset (WDTRST) SFR. The WDT is defaulted to disable from exiting reset. To enable the
WDT, a user must write 01EH and 0E1H in sequence to the WDTRST register (SFR location
0A6H). When the WDT is enabled, it will increment every machine cycle while the oscillator
is running. The WDT timeout period is dependent on the external clock frequency. There is no
way to disable the WDT except through reset (either hardware reset or WDT overflow reset).
When WDT overflows, it will drive an output RESET HIGH pulse at the RST pin.

Using the WDT:

To enable the WDT, a user must write 01EH and 0E1H in sequence to the WDTRST
register (SFR location 0A6H). When the WDT is enabled, the user needs to service it by
writing 01EH and 0E1H to WDTRST to avoid a WDT overflow. The 13-bit counter
overflows when it reaches 8191 (1FFFH), and this will reset the device. When the WDT is
enabled, it will increment every machine cycle while the oscillator is running. This means the
user must reset the WDT at least every 8191 machine cycles. To reset the WDT the user must
write 01EH and 0E1H to WDTRST. WDTRST is a write-only register. The WDT counter

22
cannot be read or written. When WDT overflows, it will generate an output RESET pulse at
the RST pin. The RESET pulse duration is 96xTOSC, where TOSC=1/FOSC. To make the
best use of the WDT, it should be serviced in those sections of code that will periodically be
executed within the time required to prevent a WDT reset.

Timer 0 and 1:
Timer 0 and Timer 1 in the AT89S52 operate the same way as Timer 0 and Timer 1 in
the AT89C51 and AT89C52.

Timer 2:
Timer 2 is a 16-bit Timer/Counter that can operate as either a timer or an event
counter. The type of operation is selected by bit C/T2 in the SFR T2CON. Timer 2 has three
operating modes: capture, auto-reload (up or down counting), and baud rate generator. The
Modes are selected by bits in T2CON. Timer 2 consists of two 8-bit registers, TH2 and TL2.
In the Timer function, the TL2 register is incremented every machine cycle. Since a machine
cycle consists of 12 oscillator periods, the count rate is 1/12 of the oscillator frequency.

3.2.9 Serial ports:

Each AT 89S52 microcomputer contains a high speed full duplex (means you
can simultaneously use the same port for both transmitting and receiving purposes)
serial port which is software configurable in 4 basic modes: 8 bit UART; 9 bit
UART; inter processor Communications link or as shift register I/O expander.

For the standard serial communication facility, AT 89S52 can be programmed for
UART operations and can be connected with regular personal computers, teletype
writers, modem at data rates between 122 bauds and 31 kilo bauds. Getting this
facility is made very simple using simple routines with option to elect even or odd
parity. You can also establish a kind of Inter processor communication facility among
many microcomputers in a distributed environment with automatic recognition of
address/data. Apart from all above, you can also get super fast I/O lines using low
cost simple TTL or CMOS shift registers.

3.2.10 Interrupts:

23
The AT89S52 has a total of six interrupt vectors: two external interrupts (INT0 and
INT1), three timer interrupts (Timers 0, 1, and 2), and the serial port interrupt. Each of these
interrupt sources can be individually enabled or disabled by setting or clearing a bit in Special
Function Register IE. IE also contains a global disable bit, EA, which disables all interrupts at
once. Note that Table 5 shows that bit position IE.6 is unimplemented.In the AT89S52, bit
position IE.5 is also unimplemented. User software should not write 1s to these bit positions,
since they may be used in future AT89 products. Timer 2 interrupt is generated by the logical
OR of bits TF2 and EXF2 in register T2CON. Neither of these flags is cleared by hardware
when the service routine is vectored to. In fact, the service routine may have to determine
whether it was TF2 or EXF2 that generated the interrupt, and that bit will have to be cleared in
software. The Timer 0 and Timer 1 flags, TF0 and TF1, are set at S5P2 of the cycle in which
the timers overflow. The values are then polled by the circuitry in the next cycle. However,
the Timer 2 flag, TF2, is set at S2P2 and is polled in the same cycle in which the timer
overflows.

Table 3.3: Interrupt enable(IE) register

24
Table 3.4: Interrupt Enable (IE) register Functions.

3.2.11 Oscillator Characteristics:

XTAL1 and XTAL2 are the input and output, respectively, of an inverting amplifier
that can be configured for use as an on-chip oscillator. Either a quartz crystal or ceramic
resonator may be used. To drive the device from an external clock source, XTAL2 should be
left unconnected while XTAL1 is driven. There are no requirements on the duty cycle of the
external clock signal, since the input to the internal clocking circuitry is through a divide-by-
two flip-flop, but minimum and maximum voltage high and low time specifications must be
observed.

25
Figure3.3 (a): Oscillator connections. Figure3.3(b): External clock drive
configuration.

3.2.12 Idle Mode:

In idle mode, the CPU puts itself to sleep while all the on chip peripherals remain
active. The mode is invoked by software. The content of the on-chip RAM and all the special
functions registers remain unchanged during this mode. The idle mode can be terminated by
any enabled interrupt or by a hardware reset. Note that when idle mode is terminated by a
hardware reset, the device normally resumes program execution from where it left off, up to
two machine cycles before the internal reset algorithm takes control. On-chip hardware
inhibits access to internal RAM in this event, but access to the port pins is not inhibited. To
eliminate the possibility of an unexpected write to a port pin when idle mode is terminated by
a reset, the instruction following the one that invokes idle mode should not write to a port pin
or to external memory.

3.2.13 Power-down Mode:

In the Power-down mode, the oscillator is stopped, and the instruction that invokes
Power-down is the last instruction executed. The on-chip RAM and Special Function
Registers retain their values until the Power-down mode is terminated. Exit from Power-down
mode can be initiated either by a hardware reset or by an enabled external interrupt. Reset
redefines the SFRs but does not change the on-chip RAM. The reset should not be activated

26
before VCC is restored to its normal operating level and must be held active long enough to
allow the oscillator to restart and stabilize.

Table 3.5 Status of external pins in idle and power down mode

3.2.14 Criteria in choosing a microcontroller:

1. The first and foremost criterion in choosing a microcontroller is that it must meet task at
hands efficiently and cost effectively. In analyzing the needs of a microcontroller based
project we must first see whether it is an 8-bit, 16-bit or 32-bit microcontroller and how
best it can handle the computing needs of the task most effectively. The other
considerations in this category are:

(a) Speed: The highest speed that the microcontroller supports

(b) Packaging: Is it 40-pin DIP or QPF or some other packaging format? This is
important in terms of space, assembling and prototyping the End product.

(c) Power Consumption: This is especially critical for battery-powered Products.

(d) The amount of RAM and ROM on chip

(e) The number of I/O pins and timers on the chip.

(f) Cost per unit: This is important in terms of final product in which a
microcontroller is used.

2. The second criteria in choosing a microcontroller are how easy it is to develop products
around it. Key considerations include the availability of an assembler, debugger, a code
efficient ‘C’ language compiler, emulator, technical support and both in house and outside
expertise. In many cases third party vendor support for chip is required.
27
3. The third criteria in choosing a microcontroller is it readily available in needed quantities
both now and in future. For some designers this is even more important than first two
criteria’s. Currently, of leading 8–bit microcontrollers, the AT 89S52 family has the
largest number of diversified (multiple source) suppliers. By suppliers meant a producer
besides the originator of microcontroller in the case of the AT 89S52, which was
originated by Intel, several companies are also currently producing the AT 89S52. Viz:
INTEL, PHILIPS, These companies include PHILIPS, SIEMENS, and DALLAS-
SEMICONDUCTOR. It should be noted that Motorola, Zilog and Microchip
Technologies have all dedicated massive resource as to ensure wide and timely
availability of their product since their product is stable, mature and single sourced. In
recent years they also have begun to sell the ASIC library cell of the microcontroller.

3.3 Regulated power supply:

3.3.1 Introduction:

Power supply is a supply of electrical power. A device or system that


supplies electrical or other types of energy to an output load or group of loads is called a 
power supply unit or PSU. The term is most commonly applied to electrical energy supplies,
less often to mechanical ones, and rarely to others. A power supply may include a power
distribution system as well as primary or secondary sources of energy such as

 Conversion of one form of electrical power to another desired form and voltage,
typically involving converting AC line voltage to a well-regulated lower-
voltage DC for electronic devices.
 Low voltage, low power DC power supply units are commonly integrated with the
devices they supply, such as computers and household electronics.
 Batteries.
 Chemical fuel cells and other forms of energy storage systems.
 Solar power.
 Generators or alternators.

3.3.2 Block Diagram:

28
Figure 3.4: Regulated Power Supply

The basic circuit diagram of a regulated power supply (DC O/P) with led connected as
load is shown in fig: 3.6

Figure 3.5: Circuit diagram of Regulated Power Supply with Led connection

The components mainly used in above figure are

 230v AC mains

 Transformer

 Bridge rectifier(diodes)

 Capacitor

 Voltage regulator(IC 7805)

 Resistor

 LED(light emitting diode)

3.3.3 Transformation:

29
The process of transforming energy from one device to another is called
transformation. For transforming energy we use transformers.

Transformers:

A transformer is a device that transfers electrical energy from one circuit to another


through inductively coupled conductors without changing its frequency. A varying current in
the first or primary winding creates a varying magnetic flux in the transformer's core, and thus
a varying magnetic field through the secondary winding. This varying magnetic
field induces a varying electromotive force (EMF) or "voltage" in the secondary winding. This
effect is called mutual induction.

If a load is connected to the secondary, an electric current will flow in the secondary
winding and electrical energy will be transferred from the primary circuit through the
transformer to the load. This field is made up from lines of force and has the same shape as a
bar magnet.

If another coil is placed adjacent to the first coil then, as the field moves out or in, the
moving lines of force will "cut" the turns of the second coil. As it does this, a voltage is
induced in the second coil. With the 50 Hz AC mains supply, this will happen 50 times a
second. This is called MUTUAL INDUCTION and forms the basis of the transformer.

The input coil is called the PRIMARY WINDING; the output coil is the
SECONDARY WINDING.

Figure 3.6: Step-Down Transformer

The voltage induced in the secondary is determined by the TURNS RATIO.

30
For example, if the secondary has half the primary turns; the secondary will have half
the primary voltage.

Another example is if the primary has 5000 turns and the secondary has 500 turns,
then the turn’s ratio is 10:1.

If the primary voltage is 240 volts then the secondary voltage will be x 10 smaller = 24
volts. Assuming a perfect transformer, the power provided by the primary must equal the
power taken by a load on the secondary. If a 24-watt lamp is connected across a 24 volt
secondary, then the primary must supply 24 watts.

To aid magnetic coupling between primary and secondary, the coils are wound on a
metal CORE. Since the primary would induce power, called EDDY CURRENTS, into this
core, the core is LAMINATED. This means that it is made up from metal sheets insulated
from each other. Transformers to work at higher frequencies have an iron dust core or no core
at all.

Note that the transformer only works on AC, which has a constantly changing current
and moving field. DC has a steady current and therefore a steady field and there would be no
induction.

Some transformers have an electrostatic screen between primary and secondary. This
is to prevent some types of interference being fed from the equipment down into the mains
supply, or in the other direction. Transformers are sometimes used for IMPEDANCE
MATCHING.

Step Up transformer:

In case of step up transformer, primary windings are every less compared to secondary
winding. Because of having more turns secondary winding accepts more energy, and it
releases more voltage at the output side.

Step down transformer:

31
In case of step down transformer, Primary winding induces more flux than the
secondary winding, and secondary winding is having less number of turns because of that it
accepts less number of flux, and releases less amount of voltage.

3.3.4 Rectification:

The process of converting an alternating current to a pulsating direct current is called


as rectification. For rectification purpose we use rectifiers.

Rectifiers:

A rectifier is an electrical device that converts alternating current (AC) to direct


current (DC), a process known as rectification. Rectifiers have many uses including as
components of power supplies and as detectors of radio signals. Rectifiers may be made of
solid-state diodes, vacuum tube diodes, mercury arc valves, and other components.

When only one diode is used to rectify AC (by blocking the negative or positive
portion of the waveform), the difference between the term diode and the term rectifier is
merely one of usage, i.e., the term rectifier describes a diode that is being used to convert AC
to DC. Almost all rectifiers comprise a number of diodes in a specific arrangement for more
efficiently converting AC to DC than is possible with only one diode. Before the development
of silicon semiconductor rectifiers, vacuum tube diodes and copper (I) oxide or selenium
rectifier stacks were used.

Bridge full wave rectifier:

The Bridge rectifier circuit is shown in fig: 3.10, which converts an ac voltage to dc
voltage using both half cycles of the input ac voltage. The Bridge rectifier circuit is shown in
the figure. The circuit has four diodes connected to form a bridge. The ac input voltage is
applied to the diagonally opposite ends of the bridge. The load resistance is connected
between the other two ends of the bridge.

For the positive half cycle of the input ac voltage, diodes D1 and D3 conduct, whereas
diodes D2 and D4 remain in the OFF state. The conducting diodes will be in series with the
load resistance RL and hence the load current flows through RL.

For the negative half cycle of the input ac voltage, diodes D2 and D4 conduct whereas,
D1 and D3 remain OFF. The conducting diodes D2 and D4 will be in series with the load
32
resistance RL and hence the current flows through RL in the same direction as in the previous
half cycle. Thus a bi-directional wave is converted into a unidirectional wave.

Input Output

Figure 3.7: Bridge rectifier: a full-wave rectifier using 4 diodes

3.3.5 Filtration:

The process of converting a pulsating direct current to a pure direct current using
filters is called as filtration.

Filters:

Electronic filters are electronic circuits, which perform signal-processing functions,


specifically to remove unwanted frequency components from the signal, to enhance wanted
ones.

Regulation:

The process of converting a varying voltage to a constant regulated voltage is called as


regulation. For the process of regulation we use voltage regulators.

3.3.6 Voltage Regulator:

A voltage regulator (also called a ‘regulator’) with only three terminals appears to be a
simple device, but it is in fact a very complex integrated circuit. It converts a varying input
voltage into a constant ‘regulated’ output voltage. Voltage Regulators are available in a
variety of outputs like 5V, 6V, 9V, 12V and 15V. The LM78XX series of voltage regulators
are designed for positive input. For applications requiring negative input, the LM79XX series
is used. Using a pair of ‘voltage-divider’ resistors can increase the output voltage of a
regulator circuit.
33
Figure 3.8: Voltage Regulator

It is not possible to obtain a voltage lower than the stated rating. You cannot use a 12V
regulator to make a 5V power supply. Voltage regulators are very robust. These can withstand
over-current draw due to short circuits and also over-heating. In both cases, the regulator will
cut off before any damage occurs. The only way to destroy a regulator is to apply reverse
voltage to its input. Reverse polarity destroys the regulator almost instantly. Fig: 3.11 shows
voltage regulator.

3.4 ZigBee Technology

3.4.1 Introduction:

When we hold the TV remote and wish to use it we have to necessarily point our
control at the device. This one-way, line-of-sight, short-range communication uses infrared
(IR) sensors to enable communication and control and it is possible to operate the TV
remotely only with its control unit.

Add other home theatre modules, an air- conditioner and remotely enabled fans and
lights to our room, and we become a juggler who has to handle not only these remotes, but
also more numbers that will accompany other home appliances we are likely to use.

Some remotes do serve to control more than one device after ‘memorizing' access
codes, but this interoperability is restricted to LOS, that too only for a set of related
equipment, like the different units of a home entertainment system

34
Now picture a home with entertainment units, security systems including fire alarm,
smoke detector and burglar alarm, air-conditioners and kitchen appliances all within
whispering distance from each other and imagine a single unit that talks with all the devices,
no longer depending on line-of-sight, and traffic no longer being one-way.

This means that the devices and the control unit would all need a common standard to
enable intelligible communication. ZigBee is such a standard for embedded application
software and has been ratified in late 2004 under IEEE 802.15.4 Wireless Networking
Standards.

ZigBee is an established set of specifications for wireless personal area networking


(WPAN), i.e., digital radio connections between computers and related devices. This kind of
network eliminates use of physical data buses like USB and Ethernet cables. The devices
could include telephones, hand-held digital assistants, sensors and controls located within a
few meters of each other.

ZigBee is one of the global standards of communication protocol formulated by the


relevant task force under the IEEE 802.15 working group. The fourth in the series, WPAN
Low Rate/ZigBee is the newest and provides specifications for devices that have low data
rates, consume very low power and are thus characterized by long battery life. Other standards
like Blue tooth and IrDA address high data rate applications such as voice, video and LAN
communications.

The ZigBee Alliance has been set up as “an association of companies working together
to enable reliable, cost-effective, low-power, wirelessly networked, monitoring and control
products based on an open global standard”.

Once a manufacturer enrolls in this Alliance for a fee, he can have access to the
standard and implement it in his products in the form of ZigBee chipsets that would be built
into the end devices. Philips, Motorola, Intel, HP are all members of the Alliance. The goal is
“to provide the consumer with ultimate flexibility, mobility, and ease of use by building
wireless intelligence and capabilities into every day devices.

ZigBee technology will be embedded in a wide range of products and applications


across consumer, commercial, industrial and government markets worldwide. For the first

35
time, companies will have a standards-based wireless platform optimized for the unique needs
of remote monitoring and control applications, including simplicity, reliability, low-cost and
low-power”.

The target networks encompass a wide range of devices with low data rates in the
Industrial, Scientific and Medical (ISM) radio bands, with building-automation controls like
intruder/fire alarms, thermostats and remote (wireless) switches, video/audio remote controls
likely to be the most popular applications. So far sensor and control devices have been
marketed as proprietary items for want of a standard. With acceptance and implementation of
ZigBee, interoperability will be enabled in multi-purpose, self-organizing mesh networks.

3.4.2 ZigBee Characteristics:

The focus of network applications under the IEEE 802.15.4 / ZigBee standard include
the features of low power consumption, needed for only two major modes (Tx/Rx or Sleep),
high density of nodes per network, low costs and simple implementation.

These features are enabled by the following characteristics:

• 2.4GHz and 868/915 MHz dual PHY modes: - This represents three license-free bands:
2.4-2.4835 GHz, 868-870 MHz and 902-928 MHz. The number of channels allotted to
each frequency band is fixed at sixteen (numbered 11-26), one (numbered 0) and ten
(numbered 1-10) respectively. The higher frequency band is applicable worldwide, and
the lower band in the areas of North America, Europe, Australia and New Zealand.
• Low power consumption, with battery life ranging from months to years. Considering
the number of devices with remotes in use at present, it is easy to see that more numbers
of batteries need to be provisioned every so often, entailing regular (as well as timely),
recurring expenditure. In the ZigBee standard, longer battery life is achievable by either
of two means: continuous network connection and slow but sure battery drain, or
intermittent connection and even slower battery drain.

 Maximum data rates allowed for each of these frequency bands are fixed as 250 kbps
@2.4 GHz, 40 kbps @ 915 MHz, and 20 kbps @868 MHz
 High throughput and low latency for low duty-cycle applications (<0.1%)
 Channel access using Carrier Sense Multiple Access with Collision Avoidance (CSMA -
CA)
36
 Addressing space of up to 64 bit IEEE address devices, 65,535 networks
 50m typical range
 Fully reliable “hand-shacked” data transfer protocol.
 Different topologies as illustrated below: star, peer-to-peer, mesh.

3.4.3 Traffic Types:

ZigBee/IEEE 802.15.4 addresses three typical traffic types.

1. Data is periodic: The application dictates the rate, and the sensor activates, checks for data
and deactivates.

Figure 3.9: ZigBee Topologies

2. Data is intermittent: The application, or other stimulus, determines the rate, as in the case
of say smoke detectors. The device needs to connect to the network only when communication
is necessitated. This type enables optimum saving on energy.

3. Data is repetitive: and the rate is fixed a priori. Depending on allotted time slots, called
GTS (guaranteed time slot), devices operate for fixed durations.

ZigBee employs either of two modes, beacon or non-beacon to enable the to-and-fro
data traffic. Beacon mode is used when the coordinator runs on batteries and thus offers

37
maximum power savings, whereas the non-beacon mode finds favor when the coordinator is
mains-powered.

In the beacon mode, a device watches out for the coordinator's beacon that gets
transmitted at periodically, locks on and looks for messages addressed to it. If message
transmission is complete, the coordinator dictates a schedule for the next beacon so that the
device ‘goes to sleep'; in fact, the coordinator itself switches to sleep mode.

While using the beacon mode, all the devices in a mesh network know when to
communicate with each other. In this mode, necessarily, the timing circuits have to be quite
accurate, or wake up sooner to be sure not to miss the beacon. This in turn means an increase
in power consumption by the coordinator's receiver, entailing an optimal increase in costs.

Figure 3.10: Beacon Network Communication

The non-beacon mode will be included in a system where devices are ‘asleep' nearly
always, as in smoke detectors and burglar alarms. The devices wake up and confirm their
continued presence in the network at random intervals.

On detection of activity, the sensors ‘spring to attention', as it were, and transmit to the
ever-waiting coordinator's receiver (since it is mains-powered). However, there is the remotest
of chances that a sensor finds the channel busy, in which case the receiver unfortunately
would ‘miss a call'.

38
Figure 3.11: Non-Beacon Network Communication

Network Model:

The functions of the Coordinator, which usually remains in the receptive mode,
encompass network set-up, beacon transmission, node management, storage of node
information and message routing between nodes.

Figure 3.12: ZigBee Network Model

The network node, however, is meant to save energy (and so ‘sleeps' for long periods)
and its functions include searching for network availability, data transfer, checks for pending
data and queries for data from the coordinator.

For the sake of simplicity without jeopardizing robustness, this particular IEEE
standard defines a quartet frame structure and a super-frame structure used optionally only by
the coordinator.

The four frame structures are


39
 Beacon frame for transmission of beacons

 Data frame for all data transfers

 Acknowledgement frame for successful frame receipt confirmations


 MAC command frame

These frame structures and the coordinator's super-frame structure play critical roles in
security of data and integrity in transmission. All protocol layers contribute headers and
footers to the frame structure, such that the total overheads for each data packet range are from
15 octets (for short addresses) to 31 octets (for 64-bit addresses).

The coordinator lays down the format for the super-frame for sending beacons after
every 15.38 ms or/and multiples thereof, up to 252s.

This interval is determined a priori and the coordinator thus enables sixteen time slots
of identical width between beacons so that channel access is contention-less. Within each time
slot, access is contention-based. Nonetheless, the coordinator provides as many as seven GTS
(guaranteed time slots) for every beacon interval to ensure better quality.

3.4.4 Technology Comparisons:

The “Why ZigBee” question has always had an implied, but never quite worded
follower phrase “…when there is Blue tooth”. A comparative study of the two can be found in
ZigBee: 'Wireless Control That Simply Works’.

The bandwidth of Blue tooth is 1 Mbps; Zigbee’s is one-fourth of this value. The
strength of Blue tooth lies in its ability to allow interoperability and replacement of cables,
Zigbee’s, of course, is low costs and long battery life.

In terms of protocol stack size, Zigbee’s 32 KB is about one-third of the stack size
necessary in other wireless technologies (for limited capability end devices, the stack size is as
low as 4 KB).

Most important in any meaningful comparison are the diverse application areas of all
the different wireless technologies. Blue tooth is meant for such target areas as wireless

40
USB's, handsets and headsets, whereas ZigBee is meant to cater to the sensors and remote
controls market and other battery operated products.

In a gist, it may be said that they are neither complementary standards nor competitors,
but just essential standards for different targeted applications. The earlier Blue tooth targets
interfaces between PDA and other device (mobile phone / printer etc) and cordless audio
applications.

The IEEE 802.15.4–based ZigBee is designed for remote controls and sensors, which
are very many in number, but need only small data packets and, mainly, extremely low power
consumption for (long) life. Therefore they are naturally different in their approach to their
respective application arenas.

3.4.5 Software and hardware:

The software is designed to be easy to develop on small, inexpensive microprocessors.


The radio design used by ZigBee has been carefully optimized for low cost in large scale
production. It has few analog stages and uses digital circuits wherever possible.

Even though the radios themselves are inexpensive, the ZigBee Qualification Process
involves a full validation of the requirements of the physical layer. This amount of concern
about the Physical Layer has multiple benefits, since all radios derived from that
semiconductor mask set would enjoy the same RF characteristics. On the other hand, an
uncertified physical layer that malfunctions could cripple the battery lifespan of other devices
on a ZigBee network. Where other protocols can mask poor sensitivity or other esoteric
problems in a fade compensation response, ZigBee radios have very tight engineering
constraints: they are both power and bandwidth constrained. Thus, radios are tested to the ISO
17025 standard with guidance given by Clause 6 of the 802.15.4-2006 Standard. Most vendors
plan to integrate the radio and microcontroller onto a single chip.

3.4.6 Controversy:

An academic research group has examined the Zigbee address formation algorithm in
the 2006 specification, and argues[6] that the network will isolate many units that could be
connected. The group proposed an alternative algorithm with similar complexity in time and
space.

41
A white paper published by a European manufacturing group (associated with the
development of a competing standard, Z-Wave) claims that wireless technologies such as
ZigBee, which operate in the 2.4 GHz RF band, are subject to significant interference -
enough to make them unusable. It claims that this is due to the presence of other wireless
technologies like Wireless LAN in the same RF band. The ZigBee Alliance released a white
paper refuting these claims. After a technical analysis, this paper concludes that ZigBee
devices continue to communicate effectively and robustly even in the presence of large
amounts of interference.

3.4.7 ZigBee Applications:

The ZigBee Alliance targets applications "across consumer, commercial, industrial and
government markets worldwide". Unwired applications are highly sought after in many
networks that are characterized by numerous nodes consuming minimum power and enjoying
long battery lives.

ZigBee technology is designed to best suit these applications, for the reason that it
enables reduced costs of development, very fast market adoption, and rapid ROI. Airbee
Wireless Inc has tied up with Radio crafts AS to deliver "out-of-the-box" ZigBee-ready
solutions, the former supplying the software and the latter making the module platforms. With
even light controls and thermostat producers joining the ZigBee Alliance, the list is growing
healthily and includes big OEM names like HP, Philips, Motorola and Intel.

With ZigBee designed to enable two-way communications, not only will the consumer
be able to monitor and keep track of domestic utilities usage, but also feed it to a computer
system for data analysis.

A recent analyst report issued by West Technology Research Solutions estimates that
by the year 2008, "annual shipments for ZigBee chipsets into the home automation segment
alone will exceed 339 million units," and will show up in "light switches, fire and smoke
detectors, thermostats, appliances in the kitchen, video and audio remote controls,
landscaping, and security systems."

Advantages:

42
 low cost allows the technology to be widely deployed in wireless control and
monitoring applications.
 low power-usage allows longer life with smaller batteries,.
 mesh networking provides high reliability and larger range.

3.5 LCD INTERFACING

Introduction
The most commonly used Character based LCDs are based on Hitachi's HD44780
controller or other which are compatible with HD44580. In this tutorial, we will discuss about
character based LCDs, their interfacing with various microcontrollers, various interfaces (8-
bit/4-bit), programming, special stuff and tricks you can do with these simple looking LCDs
which can give a new look to your application.

Pin Description

The most commonly used LCD’s found in the market today are 1 Line, 2 Line or 4
Line LCDs which have only 1 controller and support at most of 80 characters, whereas LCDs
supporting more than 80 characters make use of 2 HD44780 controllers.
Most LCDs with 1 controller has 14 Pins and LCDs with 2 controller has 16 Pins (two pins
are extra in both for back-light LED connections). Pin description is shown in the table below.

Pin No. Name Description

Pin no. 1 VSS Power supply (GND)

Pin no. 2 VCC Power supply (+5V)

Pin no. 3 VEE Contrast adjust

0 = Instruction input
Pin no. 4 RS
1 = Data input

0 = Write to LCD module


Pin no. 5 R/W
1 = Read from LCD module

Pin no. 6 EN Enable signal


43
Pin no. 7 D0 Data bus line 0 (LSB)

Pin no. 8 D1 Data bus line 1

Pin no. 9 D2 Data bus line 2

Pin no. 10 D3 Data bus line 3

Pin no. 11 D4 Data bus line 4

Pin no. 12 D5 Data bus line 5

Pin no. 13 D6 Data bus line 6

Pin no. 14 D7 Data bus line 7 (MSB)

DDRAM - Display Data RAM

Display data RAM (DDRAM) stores display data represented in 8-bit character codes.
Its extended capacity is 80 X 8 bits, or 80 characters. The area in display data RAM
(DDRAM) that is not used for display can be used as general data RAM. So whatever you
send on the DDRAM is actually displayed on the LCD. For LCDs like 1x16, only 16
characters are visible, so whatever you write after 16 chars is written in DDRAM but is not
visible to the user.

CGROM - Character Generator ROM

Now you might be thinking that when you send an ASCII value to DDRAM, how the
character is displayed on LCD? So the answer is CGROM. The character generator ROM
generates 5 x 8 dot or 5 x 10 dot character patterns from 8-bit character codes (see Figure 5
and Figure 6 for more details). It can generate 208 5 x 8 dot character patterns and 32 5 x 10
dot character patterns. User defined character patterns are also available by mask-programmed
ROM.

As you can see in both the code maps, the character code from 0x00 to 0x07 is occupied by
the CGRAM characters or the user defined characters. If user wants to display the fourth
custom character then the code to display it is 0x03 i.e. when user sends 0x03 code to the
LCD DDRAM then the fourth user created character or pattern will be displayed on the LCD.

CGRAM - Character Generator RAM


44
As clear from the name, CGRAM area is used to create custom characters in LCD. In
the character generator RAM, the user can rewrite character patterns by program. For 5 x 8
dots, eight character patterns can be written, and for 5 x 10 dots, four character patterns can be
written.

BF - Busy Flag

Busy Flag is a status indicator flag for LCD. When we send a command or data to the
LCD for processing, this flag is set (i.e. BF =1) and as soon as the instruction is executed
successfully this flag is cleared (BF = 0). This is helpful in producing and exact amount of
delay for the LCD processing.

To read Busy Flag, the condition RS = 0 and R/W = 1 must be met and The MSB of the LCD
data bus (D7) act as busy flag. When BF = 1 means LCD is busy and will not accept next
command or data and BF = 0 means LCD is ready for the next command or data to process.

Instruction Register (IR) and Data Register (DR)

There are two 8-bit registers in HD44780 controller Instruction and Data register.
Instruction register corresponds to the register where you send commands to LCD e.g. LCD
shift command, LCD clear, LCD address etc. and Data register is used for storing data which
is to be displayed on LCD. When send the enable signal of the LCD is asserted, the data on
the pins is latched in to the data register and data is then moved automatically to the DDRAM
and hence is displayed on the LCD.

Data Register is not only used for sending data to DDRAM but also for CGRAM, the
address where you want to send the data, is decided by the instruction you send to LCD.

4-bit programming of LCD

In 4-bit mode the data is sent in nibbles, first we send the higher nibble and then the lower
nibble. To enable the 4-bit mode of LCD, we need to follow special sequence of initialization
that tells the LCD controller that user has selected 4-bit mode of operation. We call this
special sequence as resetting the LCD. Following is the reset sequence of LCD.

 Wait for about 20mS

45
 Send the first init value (0x30)
 Wait for about 10mS
 Send second init value (0x30)
 Wait for about 1mS
 Send third init value (0x30)
 Wait for 1mS
 Select bus width (0x30 - for 8-bit and 0x20 for 4-bit)
 Wait for 1mS

The busy flag will only be valid after the above reset sequence. Usually we do not use busy
flag in 4-bit mode as we have to write code for reading two nibbles from the LCD. Instead we
simply put a certain amount of delay usually 300 to 600uS. This delay might vary depending
on the LCD you are using, as you might have a different crystal frequency on which LCD
controller is running. So it actually depends on the LCD module you are using.

In 4-bit mode, we only need 6 pins to interface an LCD. D4-D7 are the data pins connection
and Enable and Register select are for LCD control pins. We are not using Read/Write (RW)
Pin of the LCD, as we are only writing on the LCD so we have made it grounded
permanently. If you want to use it, then you may connect it on your controller but that will
only increase another pin and does not make any big difference. Potentiometer RV1 is used to
control the LCD contrast. The unwanted data pins of LCD i.e. D0-D3 are connected to
ground.

Sending data/command in 4-bit Mode

We will now look into the common steps to send data/command to LCD when
working in 4-bit mode. In 4-bit mode data is sent nibble by nibble, first we send higher nibble
and then lower nibble. This means in both command and data sending function we need to
separate the higher 4-bits and lower 4-bits.

The common steps are:

 Mask lower 4-bits


 Send to the LCD port
 Send enable signal
 Mask higher 4-bits

46
 Send to LCD port
 Send enable signal

3.6 MAX-232:

3.6.1 RS232:

RS232 (serial port).

RS-232 (Recommended Standard - 232) is a telecommunications standard for


binary serial communications between devices. It supplies the roadmap for the way
devices speak to each other using serial ports. The devices are commonly referred to
as a DTE (data terminal equipment) and DCE (data communications equipment); for
example, a computer and modem, respectively.

RS232 is the most known serial port used in transmitting the data in
communication and interface. Even though serial port is harder to program than
the parallel port, this is the most effective method in which the data transmission
requires less wires that yields to the less cost. The RS232 is the communication line
which enables the data transmission by only using three wire links. The three links
provides ‘transmit’, ‘receive’ and common ground...

 The ‘transmit’ and ‘receive’ line on this connecter send and receive data
between the computers. As the name indicates, the data is transmitted
serially. The two pins are TXD & RXD. There are other lines on this port as
RTS, CTS, DSR, DTR, and RTS, RI. The ‘1’ and ‘0’ are the data which defines
a voltage level of 3V to 25V and -3V to -25V respectively.

he electrical characteristics of the serial port as per the EIA (Electronics Industry
Association) RS232C Standard specifies a maximum baud rate of 20,000bps, which
is slow compared to today’s standard speed. For this reason, we have chosen the
new RS-232D Standard, which was recently released.

     The RS-232D has existed in two types. i.e., D-TYPE 25 pin connector and D-
TYPE 9 pin connector, which are male connectors on the back of the PC. You need a

47
female connector on your communication from Host to Guest computer. The pin
outs of both D-9 & D-25 are show below

D-Type-9 D-Type-25 Pin outs Function


pin no. pin no.

3 2 RD Receive Data (Serial data input)

2 3 TD Transmit Data (Serial data output)

7 4 RTS Request to send (acknowledge to modem


that UART is ready to exchange data
8 5 CTS Clear to send (i.e.; modem is ready to
exchange data)
6 6 DSR Data ready state (UART establishes a link)

5 7 SG Signal ground

1 8 DCD Data Carrier detect (This line is active


when modem detects a carrier
4 20 DTR Data Terminal Ready.

9 22 RI Ring Indicator (Becomes active when


modem detects ringing signal from PSTN

Rs232

48
When communicating with various micro processors one needs to convert the
RS232 levels down to lower levels, typically 3.3 or 5.0 Volts. Here is a cheap and
simple way to do that. Serial RS-232 (V.24) communication works with voltages
-15V to +15V for  high and low. On the other hand, TTL  logic operates between 0V
and +5V . Modern low power consumption logic operates in the range of 0V and
+3.3V or even lower.

RS-232 TTL Logic

-15V …  -3V +2V … +5V High

+3V … +15V 0V … +0.8V  Low

Thus the RS-232 signal levels are far too high TTL electronics, and the negative
RS-232 voltage for high can’t be handled at all by computer logic. To receive serial
data from an RS-232 interface the voltage has to be reduced.  Also the low and high
voltage level has to be inverted. This level converter uses a Max232 and five
capacitors. The max232 is quite cheap (less than 5 dollars) or if youre lucky you
can get a free sample from Maxim. The MAX232 from Maxim was the first IC which
in one package contains the necessary drivers and receivers to adapt the RS-232
signal voltage levels to TTL logic. It became popular, because it just needs one

voltage (+5V or +3.3V) and generates the necessary RS-232 voltage levels.

MAX 232 PIN DIAGRAM

49
Figure 3.12: Max232 pin diagram

Table 3.9: MAX232 to RS232 DB9 Connection as a DCE

50
Figure 3.13: Max232 circuit board

3.6.2 RS232 interfaced to Max 232:


J2
C 1
U 3 1uf
9 5
16

8 4 13 12 P 3 .0 R XD
7 3 T1O U T 8 R 1 IN R 1O U T 9
VC C

6 2 R 2 IN R 2O U T
1 10 14 T1O U T
T XD P 3 .1 11 T 2 IN T1O U T 7
C 4 T 1 IN T2O U T
5V 1
3 C 1+
C0 . 51 u f 4 C 1-
5 C 2+
C 6 C 2-
0 .1 u f 2
0 .1 u f V+
G N D

6
V-
C 7
M A X3232
15

0 .1 u f

Figure 3.14: RS 232 interfaced to Max 232

Rs232 is 9 pin db connector, only three pins of this are used i.e. 2, 3, 5 the transmit pin
of RS232 is connected to Rx pin of microcontroller
51
3.6.3 Max232 interfaced to microcontroller:

Figure 3.15: Max 232 interfaced to microcontroller

MAX232 is connected to the microcontroller as shown in the figure 3.25 above 11, 12
pin are connected to the 10 and 11 pin ie transmit and receive pin of microcontroller.

3.7 TEMPERATURE SENSOR - THE LM35:

The LM35 series are precision integrated-circuit temperature sensors, whose output
voltage is linearly proportional to the Celsius (Centigrade) temperature. The LM35 thus has an
advantage over linear temperature sensors calibrated in ° Kelvin, as the user is not required to
subtract a large constant voltage from its output to obtain convenient Centigrade scaling. The
LM35 does not require any external calibration or trimming to provide typical accuracies of
±¼°C at room temperature and ±¾°C over a full -55 to +150°C temperature range. Low cost
is assured by trimming and calibration at the wafer level. The LM35's low output impedance,
linear output, and precise inherent calibration make interfacing to readout or control circuitry
especially easy. It can be used with single power supplies, or with plus and minus supplies. As
it draws only 60 µA from its supply, it has very low self-heating, less than 0.1°C in still air.

52
The LM35 is rated to operate over a -55° to +150°C temperature range, while the LM35C is
rated for a -40° to +110°C range (-10° with improved accuracy). 

Figure 3.16: LM 35

An analog temperature sensor is pretty easy to explain, its a chip that tells you what the
ambient temperature is! These sensors use a solid-state technique to determine the
temperature. That is to say, they don’t use mercury (like old thermometers), bimetallic strips
(like in some home thermometers or stoves), nor do they use thermistors (temperature
sensitive resistors). Instead, they use the fact as temperature increases, the voltage across a
diode increases at a known rate. (Technically, this is actually the voltage drop between the
base and emitter - the Vbe - of a transistor. By precisely amplifying the voltage change, it is
easy to generate an analog signal that is directly proportional to temperature. There have been
some improvements on the technique but, essentially that is how temperature is measured.
Because these sensors have no moving parts, they are precise, never wear out, don't need
calibration, work under many environmental conditions, and are consistent between sensors
and readings. Moreover they are very inexpensive and quite easy to use

3.7.1 Features:

 Calibrated directly in ° Celsius (Centigrade).

 Linear + 10.0 mV/°C scale factor.

 0.5°C accuracy guaranteable (at+25°C).

 Rated for full -55° to +150°C range.

 Suitable for remote applications.

53
 Low cost due to wafer-level trimming.

 Operates from 4 to 30 volts.

 Less than 60 µA current drain.

 Low self-heating, 0.08°C in still air.

 Nonlinearity only ±¼°C typical.

 Low impedance output, 0.1 Ohm for 1 mA load.

3.7.2 Why Use LM35s To Measure Temperature?

 You can measure temperature more accurately than a using a thermistor.

 The sensor circuitry is sealed and not subject to oxidation, etc.

 The LM35 generates a higher output voltage than thermocouples and may not require
that the output voltage be amplifi

CHAPTER 4

SOFTWARE DESCRIPTION

4.1 KEIL SOFTWARE:

4.1.1 Introduction to Micro vision Keil:

Keil is a cross compiler. So first we have to understand the concept of compilers and
cross compilers. After then we shall learn how to work with keil.

4.1.2 Concept of compiler:

Compilers are programs used to convert a High Level Language to object code.
Desktop compilers produce an output object code for the underlying microprocessor, but not
for other microprocessors. I.E the programs written in one of the HLL like ‘C’ will compile
54
the code to run on the system for a particular processor like x86 (underlying microprocessor in
the computer). For example compilers for Dos platform is different from the Compilers for
UNIX platform.

So if one wants to define a compiler then compiler is a program that translates source
code into object code. The compiler derives its name from the way it works, looking at the
entire piece of source code and collecting and reorganizing the instruction. See there is a bit
little difference between compiler and an interpreter. Interpreter just interprets whole program
at a time while compiler analyzes and execute each line of source code in succession, without
looking at the entire program.

The advantage of interpreters is that they can execute a program immediately.


Secondly programs produced by compilers run much faster than the same programs executed
by an interpreter. However compilers require some time before an executable program
emerges. Now as compilers translate source code into object code, which is unique for each
type of computer, many compilers are available for the same language.

4.1.3 Concept of cross compiler:

A cross compiler is similar to the compilers but we write a program for the target
processor (like AT 89S52 and its derivatives) on the host processors (like computer of x86).It
means being in one environment you are writing a code for another environment is called
cross development. And the compiler used for cross development is called cross compiler.

So the definition of cross compiler is a compiler that runs on one computer but
produces object code for a different type of computer. Cross compilers are used to generate
software that can run on computers with a new architecture or on special-purpose devices that
cannot host their own compilers. Cross compilers are very popular for embedded
development, where the target probably couldn't run a compiler. Typically an embedded
platform has restricted RAM, no hard disk, and limited I/O capability. Code can be edited and
compiled on a fast host machine (such as a PC or Unix workstation) and the resulting
executable code can then be downloaded to the target to be tested. Cross compilers are
beneficial whenever the host machine has more resources (memory, disk, I/O etc) than the

55
target. Keil C Compiler is one such compiler that supports a huge number of host and target
combinations. It supports as a target to 8 bit microcontrollers like Atmel and Motorola etc. 

4.1.4 Why do we need cross compiler?

There are several advantages of using cross compiler. Some of them are described as follows:

 By using this compilers not only can development of complex embedded systems be
completed in a fraction of the time, but reliability is improved, and maintenance is
easy.

 Knowledge of the processor instruction set is not required.

 A rudimentary knowledge of the AT 89S52’s memory architecture is desirable but not


necessary.

 Register allocation and addressing mode details are managed by the compiler.

 The ability to combine variable selection with specific operations improves program
readability.

 Keywords and operational functions that more nearly resemble the human thought
process can be used.

 Program development and debugging times are dramatically reduced when compared
to assembly language programming.

 The library files that are supplied provide many standard routines (such as formatted
output, data conversions, and floating-point arithmetic) that may be incorporated into
your application.

 Existing routine can be reused in new programs by utilizing the modular programming
techniques available with C.

 The C language is very portable and very popular. C compilers are available for almost
all target systems. Existing software investments can be quickly and easily converted
from or adapted to other processors or environments.

56
 Now after going through the concept of compiler and cross compilers lets we start with
Keil C cross compiler.

4.1.5 Keil C cross compiler:

Keil is a German based Software development company. It provides several development


tools like

 IDE (Integrated Development environment).

 Project Manager.

 Simulator.

 Debugger.

 C Cross Compiler, Cross Assembler, Locator/Linker.

Keil Software provides you with software development tools for the AT 89S52
microcontrollers. With these tools, you can generate embedded applications for the multitude
of ARM derivatives.

Keil provides following tools for AT 89S52 development:

1. AT 89S52 Optimizing C Cross Compiler,

2. Macro Assembler,

3. AT 89S52 Utilities (linker, object file converter, library manager),

4. Source-Level Debugger/Simulator,

5. µVision for Windows Integrated Development Environment.

The keil AT 89S52 tool kit includes three main tools, assembler, compiler and linker.

 An assembler is used to assemble your AT 89S52 assembly program.

 A compiler is used to compile your C source code into an object file.

 A linker is used to create an absolute object module suitable for your in-circuit
emulator. 

57
4.2 AT 89S52 Project development cycle:

These are the steps to develop AT 89S52 project using keil:

 Create source files in C or assembly.

 Compile or assemble source files.

 Correct errors in source files.

 Link object files from compiler and assembler.

 Test linked application.

4.3 Dumping steps:

The steps involved in dumping the program edited to microcontroller are shown
below:

1. Initially before connecting the program dumper to the microcontroller kit the window is
appeared.

2. Select Tools option and click on Check Communication for establishing a connection.

3. After connecting the dumper properly to the microcontroller kit the window is
appeared.

4. Again by selecting the Tools option and clicking on Check Communication the
microcontroller gets recognized by the dumper.

5. Import the program which is ‘.hex’ file from the saved location by selecting File option
and clicking on ‘Import Hex’.

6. After clicking on ‘Import Hex’ option we need to browse the location of our program
and click the ‘prog.hex’ and click on ‘open’ for dumping the program into the
microcontroller.

4.4 SOURCE CODE

58
#include<reg52.h>
#include<intrins.h>
#include<string.h>
#define LCD P0

sbit DCLK = P1^2;


sbit SDAT = P1^1;
sbit CS   = P1^0;

sbit sen1 = P2^0;


sbit sen2 = P2^1;
sbit sen3 = P2^2;
sbit sen4 = P2^3;

bit flag = 0;
bit r_flag = 0;
bit sucess = 0;
bit t_flag=0;
bit receive=0;

unsigned int tempnum;

void init_lcd(void);
void cmd_lcd(unsigned char);
void data_lcd(unsigned char);
void display_lcd(unsigned char *);
void integer_lcd(int);
void float_lcd(float);
void adc_convert (void);
unsigned char byte_read(void);
void delay_ms(unsigned int);

void serial_send(unsigned char);


void SEND_STR(unsigned char *);
void send_data(void);
unsigned char byte0,byte1;
unsigned int num;
float val,fah;

void serial_int(void)interrupt 4
{
if(RI)
{
receive=1;
RI = 0;
tempnum=SBUF;
}

else
{
59
t_flag=1;
TI=0;
}
}

void main()
{

 init_lcd();
 sen1=sen2=sen3=sen4=0;
  SCON  = 0x50;   
    TMOD  = 0x20;    
    TH1   = -3;    
    TR1   = 1;     
IE=0x95; 
 display_lcd("Zigbee Based");
 cmd_lcd(0xC0);
 display_lcd("Health Monitoring");
 delay_ms(100); 
 cmd_lcd(0x01);
 
 
 
  
  SEND_STR("Deveice Connected!\r\n");
  SEND_STR("Patient ID 001a\r\n");
  while(1)
  {
   SEND_STR("Temprature  ");
   cmd_lcd(0x80);
   adc_convert();
   float_lcd(val);
   display_lcd("C");
   SEND_STR("    ");
   cmd_lcd(0x89);
   float_lcd(fah);
   display_lcd("F");
   SEND_STR("F\r\n");
   delay_ms(100);
   if(sen1==1)
   {  
cmd_lcd(0xC0);
    display_lcd("Impedance :     ");
SEND_STR("Impedance :\r\n");
   }
   if(sen2==1)
   {
   cmd_lcd(0xC0);
    display_lcd("Impedance :::   ");
60
SEND_STR("Impedance :::\r\n");
   }
   if(sen3==1)
   {
   cmd_lcd(0xC0);
    display_lcd("Impedance :::::");
SEND_STR("Impedance :::::\r\n");
   }
   display_lcd("               ");
  }
  

void init_lcd(void)
{
  cmd_lcd(0x28);
  cmd_lcd(0x28);
  cmd_lcd(0x28);
  cmd_lcd(0x0C);
  cmd_lcd(0x06);
  cmd_lcd(0x01);
}

void cmd_lcd(unsigned char var)


{
  LCD = ((var & 0xF0) | 0x04);
  LCD = 0;
  LCD = ((var << 4) );
  LCD = 0;
  delay_ms(2);
}

void data_lcd(unsigned char var)


{
  LCD = ((var & 0xF0) | 0x05);
  LCD = 0;
  LCD = ((var << 4) );
  LCD = 0;
  delay_ms(2);

void display_lcd(char *str)


{
  while(*str)
  data_lcd(*str++);
}

void delay_ms(unsigned int cnt)


{
61
  int i;
  while(cnt--)
  for(i=0;i<500;i++);
}

void SEND_STR(unsigned char *s)


{
while(*s)
serial_send(*s++);
}   

void serial_send(unsigned char buf)


{
 t_flag= 0;
  SBUF = buf;
 
}

void adc_convert (void)  



    DCLK=1;
    CS=1;                  //low to high to start conversion
    CS=0;
    byte1=byte_read(); //msb result from adc
byte0=byte_read(); //lsb result from adc
 
    CS=1; 
    num=(byte1&0x1f); //
    num=((num<<8)|byte0)>>1;
    val=((num*5.55)/4096)*10;
val=(1/val)*1000;
    fah=(9/5)*val+32;
}
  
unsigned char byte_read (void)  
{
 unsigned char i,c=0,mask=0x80;
  for (i=0;i<8;i++)
   {
    DCLK=0;
     if (SDAT==1)
      c|=mask;
    DCLK=1;
    mask>>=1;                                          
   }
  return c;
}

void integer_lcd(int n)
{
62
unsigned char c[6];
unsigned int i=0;
  if(n<0)
  {
    data_lcd('-');
serial_send('-');
    n=-n;
  }
  if(n==0)
  {
    data_lcd('0');
serial_send('0');
   }
  while(n>0)
  {
    c[i++]=(n%10)+48;
    n/=10;
  }
  while(i-->=1)
   {
    data_lcd(c[i]);
serial_send(c[i]);
   }
}

void float_lcd(float f)
{
int n;
float temp;

temp=f-n;
if(temp>=0.00&&temp<=0.09)
{
data_lcd('0');
serial_send('0');
}
f=temp*100;
n=f;
integer_lcd(n);
}

63
CONCLUSION

The project “ZIGBEE DEVICE ACCESS CONTROL AND RELIABLE


DATA TRANSMISSION IN ZIGBEE BASED HEALTH MONITORING SYSTEM”.
has been successfully designed and tested. It has been developed by integrating features of all
the hardware components used. Presence of every module has been reasoned out and placed
carefully thus contributing to the best working of the unit.
Secondly, using highly advanced IC’s and with the help of growing technology the
project has been successfully implemented.

64
REFERENCES:
1.The 8051 Micro controller and Embedded Systems
-Muhammad Ali Mazidi
-Janice Gillispie Mazidi
2.The 8051 Micro controller Architecture, Programming & Applications
-Kenneth J.Ayala
3.Fundamentals Of Micro processors and Micro computers
-B.Ram
4.Micro processor Architecture, Programming & Applications
-Ramesh S.Gaonkar
5.Electronic Components
-D.V.Prasad
6. 8051 System Developer’s Guide

-Andrew N.SLOSS

-Domenic SYMES

-Chris WRIGHT

References on the Web:

7. www.national.com
8. www.nxp.com
9. www.8052.com
10. www.microsoftsearch.com
11. www.geocities.com
12. www.keil.com

65

You might also like