santu main project

download santu main project

of 65

Transcript of santu main project

  • 8/7/2019 santu main project

    1/66

    1

    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 thetemperature 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 .

  • 8/7/2019 santu main project

    2/66

    2

    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

  • 8/7/2019 santu main project

    3/66

    3

    1.3 Project overview:

    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 asthey 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.

  • 8/7/2019 santu main project

    4/66

    4

    CHAPTER 2

    EMBEDDED SYSTEMS

    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 mountedinside 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 PD A) are among the myriad possible hosts of an embedded system. Embedded systems

  • 8/7/2019 santu main project

    5/66

    5

    that are programmable are provided with a programming interface, and embedded systems

    programming is a specialized occupation.

    2.2 Need for embedded systems:

    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 FPG A 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 R AM, 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 R AM, ROM, I/O ports, and timers externally to make them functional.

    Although the addition of external R AM, 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 R AM, 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

    R AM, ROM, I/O ports, and a timer all on a single chip. In other words, the processor, the

    R AM, ROM, I/O ports and the timer are all embedded together on one chip; therefore, the

  • 8/7/2019 santu main project

    6/66

  • 8/7/2019 santu main project

    7/66

    7

    CHAPTER 3

    HARDWARE DESCRIPTION

    3.1 Working explanation:

    Mainly the block diagram consists of following parts :

    y Power supply circuit

    y AT 89S52 controller

    y ZigBee module(transceiver )

    y Max-232

    y Lcd

    y Temperature sensor

    Generally we get 230v of power supply but we need only 3.3v to generate the microcontroller 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 pinP0.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 U ART0 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

  • 8/7/2019 santu main project

    8/66

    8

    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 patients condition in the hospital. Where it

    impossible for the doctor to check each and every patient at every minute this project be used

    efficiently where more no peoples 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

    patients body temperature increases at a certain point immediately that information will be

    transmitted to the Receiving section which presents in the Doctors 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

  • 8/7/2019 santu main project

    9/66

    9

    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

    amount of R AM, ROM, I/O ports and a timer embedded all on a single chip. The fixed

    amount of on-chip ROM, R AM 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 Atmels

    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 R AM, 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 R AM, timer/counters, serial port, and interrupt system to continue

    functioning. The Power-down mode saves the R AM contents but freezes the oscillator,

    disabling all other chip functions until the next interrupt or hardware reset.

    3.2.3 F eatures of AT89S5 2 architecture:

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

    --Endurance : 1000 Write/Erase Cycles

    y 4.0V to 5.5V Operating Range

  • 8/7/2019 santu main project

    10/66

    10

    y Fully Static Operation : 0 Hz to 33 MHz

    y Three-level Program Memory Lock

    y 256 x 8-bit Internal R AM

    y 32 Programmable I/O Lines

    y Three 16-bit Timer/Counters

    y Eight Interrupt Sources

    y Full Duplex U ART Serial Channel

    y Low-power Idle and Power-down Modes

    y Interrupt Recovery from Power-down Mode

    y Watchdog Timer

    y Dual Data Pointer

    y 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 users program fused inside the device. The

    memory portion was mapped at the lower end of the Program Memory area. But, after

    getting devices, customers couldnt change anything in their program code, which

    was already made available inside during device fabrication.

  • 8/7/2019 santu main project

    11/66

    11

    3.2.4 Pin Configuration:

    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

  • 8/7/2019 santu main project

    12/66

    1 2

    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

    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 asimple 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. Port1 also receives the low-order address bytes during Flash programming and verification.

    Table 3.1: Port1 pins of microcontroller

  • 8/7/2019 santu main project

    13/66

    1 3

    Port 2:

    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.

  • 8/7/2019 santu main project

    14/66

    1 4

    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.

  • 8/7/2019 santu main project

    15/66

    1 5

    :

    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 E A is held high the CPU executes out of internal Program Memory (unless the

    Program Counter exceeds 0FFFH in the AT 89S52 ). Holding E A low forces the CPU to

    execute out of external memory regardless of the Program Counter value. In the 80C31, E A

    must be externally wired low. In the EPROM devices, this pin also receives the programmingsupply 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 89S52s 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 memor y 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.

  • 8/7/2019 santu main project

    16/66

    1 6

    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 ports two data lines and two timing

    control strobe lines are designed to use P3 port lines. When you dont use thesespecial 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 E A pin is connected to GND, all program fetches are directed to external

    memory. On the AT89S52, if E A 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 R AM. 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 R AM 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 0 A0H (which is P2 ).

    MOV 0 A0H, #data

  • 8/7/2019 santu main project

    17/66

    1 7

    Instructions that use indirect addressing access the upper 128 bytes of R AM. For

    example, the following indirect addressing instruction, where R0 contains 0 A0H, accesses the

    data byte at address 0 A0H, rather than P2 (whose address is 0 A0H).

    MOV @R0, #data

    Note that stack operations are examples of indirect addressing, so the upper 128 bytes

    of data R AM 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 8bit 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.

  • 8/7/2019 santu main project

    18/66

  • 8/7/2019 santu main project

    19/66

  • 8/7/2019 santu main project

    20/66

  • 8/7/2019 santu main project

    21/66

    2 1

    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 instructionsalways 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 users 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.

  • 8/7/2019 santu main project

    22/66

    22

    Program Status Word (PSW ) keeps the current status of the ALU in different

    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 R A M. But normally SP is initialized to 07 H after a device reset and grows upfrom 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 t wo 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 0 A6H). 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

  • 8/7/2019 santu main project

    23/66

    23

    01EH and 0E1H to WDTRST. WDTRST is a write-only register. The WDT counter 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 U A RT; 9 bit

    U A RT; inter processor Communications link or as shift register I/O expander.

    For the standard serial communication facility, AT 89S52 can be programmed

    for U ART 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 CM OS shift registers.

  • 8/7/2019 santu main project

    24/66

    24

    3.2.10 Interrupts:

    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, E A, 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 whichthe 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

  • 8/7/2019 santu main project

    25/66

    25

    Table 3.4: Interrupt Enable (IE) register Functions.

    3.2.11 Oscillator Characteristics:XT AL1 and XT AL2 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, XT AL2 should be

    left unconnected while XT AL1 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.

  • 8/7/2019 santu main project

    26/66

    26

    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 R AM 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 R AM 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 invokesPower-down is the last instruction executed. The on-chip R AM 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 R AM. The reset should not be activated

  • 8/7/2019 santu main project

    27/66

    27

    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 R AM 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 amicrocontroller 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

  • 8/7/2019 santu main project

    28/66

    28

    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.

    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

    criterias. Currently, of leading 8bit 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 D ALL AS-

    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

    y 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.

    y Low voltage, low power DC power supply units are commonly integrated with the

    devices they supply, such as computers and household electronics.y Batteries.

    y Chemical f uel cells and other forms of energy storage systems.

    y Solar power.

    y Generators or alternators.

  • 8/7/2019 santu main project

    29/66

    29

    3.3.2 Block Diagram:

    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

    y 230v AC mains

    y Transformer

    y Bridge rectifier(diodes )

    y Capacitor

    y Voltage regulator(IC 7805 )

    y Resistor

    y LED(light emitting diode )

  • 8/7/2019 santu main project

    30/66

    3 0

    3.3.3 T i

    The process of transform ing energy from one dev ice to ano ther is ca lled

    transforma tion. For transform ing energy we use transformers.

    T

    A transformer is a dev ice that transfers e lectr ical energy from one c ircu it to ano ther

    through induc tively coup led conduc tors w ithou t chang ing its frequency. A vary ing curren t in

    the f irst or pr imary w inding crea tes a vary ing magne tic f lux in the transformer's core, and thus

    a vary ing magne tic f ield through the secondary w inding. Th is vary ing magne tic

    f ield induces a vary ing e lectromo tive force (E MF) or "voltage " in the secondary w inding. Th is

    effec t is ca lled mu tual induc tion.

    If a load is connec ted to the secondary, an e lectr ic curren t will f low in the secondary

    winding and e lectr ical energy w ill be transferred from the pr imary c ircu it through the

    transformer to the load. Th is f ield is made up from lines of force and has the same shape as a

    bar magne t.

    If ano ther co il is p laced ad jacen t to the f irst coil then, as the f ield moves ou t or in, the

    mov ing lines of force w ill "cut" the turns of the second co il. As it does this, a vo ltage is

    induced in the second co il. W ith the 50 Hz A C mains supp ly, this w ill happen 50 times a

    second. Th is is ca lled M TUAL INDU CTION and forms the bas is of the transformer.

    The inpu t coil is ca lled the P R IMAR WINDING ; the ou tput coil is the

    SECONDA R WINDING.

    i 3.6: Step-Down T nsformer

  • 8/7/2019 santu main project

    31/66

    3 1

    The vo ltage induced in the secondary is de term ined by the TU R NS R ATIO.

    For examp le, if the secondary has ha lf the pr imary turns ; the secondary w ill have ha lf the pr imary vo ltage.

    Ano ther examp le is if the pr imary has 5000 turns and the secondary has 500 turns,

    then the turns ra tio is 10 :1.

    If the pr imary vo ltage is 240 vo lts then the secondary vo ltage w ill be x 10 sma ller = 24

    volts. Assum ing a perfec t transformer, the power prov ided by the pr imary mus t equa l the

    power taken by a load on the secondary. If a 24-wa tt lamp is connec ted across a 24 vo lt

    secondary, then the pr imary mus t supp ly 24 wa tts.

    To a id magne tic coup ling be tween pr imary and secondary, the co ils are wound on a

    metal COR E. S ince the pr imary wou ld induce power, ca lled EDDY CURR ENTS, into this

    core, the core is LA MINATED. Th is means that it is made up from me tal shee ts insu lated

    from each o ther. Transformers to work a t higher frequenc ies have an iron dus t core or no core

    at all.

    Note that the transformer on ly works on A C, wh ich has a cons tantly chang ing curren t

    and mov ing f ield. D C has a s teady curren t and therefore a s teady f ield and there wou ld be no

    induc tion.

    Some transformers have an e lectros tatic screen be tween pr imary and secondary. Th is

    is to preven t some types of interference be ing fed from the equ ipmen t down into the ma ins

    supp ly, or in the o ther d irec tion. Transformers are some times used for I MPEDAN CE

    MAT CHING.

    Step Up transformer:

    In case of s tep up transformer, pr imary w indings are every less compared to secondary

    winding. Because of hav ing more turns secondary w inding accep ts more energy, and it

    releases more vo ltage a t the ou tput side.

  • 8/7/2019 santu main project

    32/66

    32

    Step down transformer:

    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 ascomponents 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 R L and hence the load current flows through R L.

  • 8/7/2019 santu main project

    33/66

    33

    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

    resistance R L and hence the current flows through R L 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 F iltration:

    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

  • 8/7/2019 santu main project

    34/66

    34

    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.

    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.

  • 8/7/2019 santu main project

    35/66

    35

    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

    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

    (WP AN), 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, WP ANLow 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 IrD A address high data rate applications such as voice, video and L AN

    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

  • 8/7/2019 santu main project

    36/66

    36

    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 firsttime, 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. Consideringthe 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

  • 8/7/2019 santu main project

    37/66

    37

    of two means : con tinuous ne twork connec tion and s low bu t sure ba ttery dra in, or

    intermittent connec tion and even s lower ba ttery dra in.

    y Maximum da ta ra tes a llowed for each of these frequency bands are f ixed as 250 kbps

    @2.4 GHz, 40 kbps @ 915 MHz, and 20 kbps @868 MHz

    y High throughpu t and low latency for low du ty-cyc le app lications (

  • 8/7/2019 santu main project

    38/66

    38

    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, calledGTS (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

    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

  • 8/7/2019 santu main project

    39/66

    39

    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 theever-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'.

    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 nodeinformation and message routing between nodes.

    Figure 3.12: ZigBee Network Model

  • 8/7/2019 santu main project

    40/66

    4 0

    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 IEEEstandard defines a quartet frame structure and a super-frame structure used optionally only by

    the coordinator.

    The four frame structures are

    y Beacon frame for transmission of beacons

    y Data frame for all data transfers

    y Acknowledgement frame for successful frame receipt confirmations

    y 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 wordedfollower phrase when there is Blue tooth. A comparative study of the two can be found in

    ZigBee : 'Wireless Control That Simply Works.

  • 8/7/2019 santu main project

    41/66

    4 1

    The bandwidth of Blue tooth is 1 Mbps; Zigbees is one-fourth of this value. The

    strength of Blue tooth lies in its ability to allow interoperability and replacement of cables,

    Zigbees, of course, is low costs and long battery life.

    In terms of protocol stack size, Zigbees 32 KB is about one-third of the stack sizenecessary 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

    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 PD A and other device (mobile phone / printer etc ) and cordless audio

    applications.

    The IEEE 802.15.4based 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 concernabout 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

  • 8/7/2019 santu main project

    42/66

    42

    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.

    A white paper published by a European manufacturing group (associated with the

    development of a competing standard, Z-Wave ) claims that wireless technologies such asZigBee, 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 L AN 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.

  • 8/7/2019 santu main project

    43/66

    43

    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 thatby 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:

    y low cost allows the technology to be widely deployed in wireless control and

    monitoring applications.y low power-usage allows longer life with smaller batteries,.

    y mesh networking provides high reliability and larger range.

    3.5 LCD INTER F ACING

    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 LCDs 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.

  • 8/7/2019 santu main project

    44/66

    44

    Pin No. Name Description

    Pin no. 1 VSS Power supply (GND )

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

    Pin no. 3 VEE Contrast adjust

    Pin no. 4 RS 0 = Instruction input

    1 = Data input

    Pin no. 5 R/W 0 = Write to LCD module

    1 = Read from LCD module

    Pin no. 6 EN Enable signal

    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 R AM (DDR AM) 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 R AM

    (DDR AM) that is not used for display can be used as general data R AM. So whatever you

  • 8/7/2019 santu main project

    45/66

    45

    send on the DDR AM 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 DDR AM but is not

    visible to the user.

    CGROM - Character Generator ROM

    Now you might be thinking that when you send an ASCII value to DDR AM, 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 CGR AM 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 DDR AM then the fourth user created character or pattern will be displayed on the LCD.

    CGRAM - Character Generator RAM

    As clear from the name, CGR AM area is used to create custom characters in LCD. In

    the character generator R AM, 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 bewritten.

    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.

  • 8/7/2019 santu main project

    46/66

    46

    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 DDR AM

    and hence is displayed on the LCD.

    Data Register is not only used for sending data to DDR AM but also for CGR AM, 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

    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 wesimply 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.

  • 8/7/2019 santu main project

    47/66

    47

    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 tocontrol 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

    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.

  • 8/7/2019 santu main project

    48/66

    48

    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 linksprovides 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 todays 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

    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

    pin no.

    D-Type-25

    pin no.

    Pin outs Function

    3 2 RD Receive Data (Serial data input)

    2 3 TD Transmit Data (Serial data output)

    7 4 RTS Request to send (acknowledge to modemthat 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

  • 8/7/2019 santu main project

    49/66

    49

    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

    When communicating with various micro processors one needs to convert the

    RS232 levels down to lower levels, typically 3.3 or 5.0 V olts. 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.

  • 8/7/2019 santu main project

    50/66

    5 0

    R S-232 TTL L o ic

    -15

    -3

    +2

    + 5

    Hi h

    +3

    + 15

    0

    + 0 8

    L o

    Th th RS-232 s i n l l v ls are far t oo hi h TTL ele ctro ic , a nd th e n egat ive

    RS-232 vol tage f or hi gh ca n t b e h a ndl ed at a ll b co p ter lo gic. To rece ive ser ia l

    d ata fr o a n RS-232 in terface t h e vol tage h as t o b e re d ce d . A ls o th e lo a nd hi gh

    vol tage le ve l h as t o b e inv erte d . Thi s level conv erter uses a M x232 a nd f ive

    c citor . Th e ma x232 is qu ite c h ea p (less t h a n 5 doll ars ) o r if y oure luc k y y ou

    ca n get a free sam pl e fr om M xim Th e MA X232 fr om M xim was t h e f irst IC w hi ch

    in on e p ac k age c on ta in s t h e n ecessary d r iv ers a nd rece ivers t o a d a p t t h e RS-232

    s ign a l vol tage levels t o TT L lo gic. It b ecame pop u lar, b ecause it just n ee d s on e

    vol tage (+ 5

    or + 3 .3

    ) a nd ge n erates t h e n ecessary RS-232 vol tage levels.

    MAX 232 PIN DI AGRAM

    igure 3.12: M ax232 p in d iagram

  • 8/7/2019 santu main project

    51/66

    5 1

    Table 3.9: MAX232 to RS232 DB9 Connection as a DCE

    Figure 3.13: Max232 circuit board

  • 8/7/2019 santu main project

    52/66

  • 8/7/2019 santu main project

    53/66

    53

    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 +150C 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.1C in still air.

    The LM35 is rated to operate over a -55 to +150C temperature range, while the LM35C is

    rated for a -40 to +110C 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 dont 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

  • 8/7/2019 santu main project

    54/66

    54

    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 needcalibration, 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 F eatures:

    y Calibrated directly in Celsius (Centigrade ).

    y Linear + 10.0 mV/C scale factor.

    y 0.5C accuracy guaranteable (at+25C ).

    y Rated for full -55 to +150C range.

    y Suitable for remote applications.

    y Low cost due to wafer-level trimming.

    y Operates from 4 to 30 volts.

    y Less than 60 A current drain.

    y Low self-heating, 0.08C in still air.

    y Nonlinearity only C typical.

    y Low impedance output, 0.1 Ohm for 1 m A load.

    3.7.2 Why Use LM35s To Measure Temperature?

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

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

    y The LM35 generates a higher output voltage than thermocouples and may not require

    that the output voltage be amplifi

  • 8/7/2019 santu main project

    55/66

    55

    CHAPTER 4

    SO F TWARE DESCRIPTION

    4.1 KEIL SO F TWARE:

    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

    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.

  • 8/7/2019 santu main project

    56/66

    56

    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 R AM, 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

    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 :

    y 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.

    y Knowledge of the processor instruction set is not required.

    y A rudimentary knowledge of the AT 89S52s memory architecture is desirable but not

    necessary.

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

    y The ability to combine variable selection with specific operations improves program

    readability.

  • 8/7/2019 santu main project

    57/66

  • 8/7/2019 santu main project

    58/66

    58

    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.

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

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

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

    emulator.

    4.2 AT 89S52 Project development cycle:

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

    y Create source files in C or assembly.

    y Compile or assemble source files.

    y Correct errors in source files.

    y Link object files from compiler and assembler.

    y 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.

  • 8/7/2019 santu main project

    59/66

    59

    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 themicrocontroller 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

    #include#include#include#define LCD P0

    sbit DCLK = P1^2;

    sbit SD AT = 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 * );

  • 8/7/2019 santu main project

    60/66

  • 8/7/2019 santu main project

    61/66

    6 1

    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" );SE