You are on page 1of 113

INDUSTRAIL AUTOMATION USING PC

INDEX
CONTENTS
1. Abbreviations 2. Abstract 3. Block Diagram 4. Block Diagram Description 5. Overview of technologies 5.1. Embedded systems 5.2. ZIGBEE technology 6. Hardware components 6.1. Micro controller 6.2. Power supply 6.3. Reset 6.4. Crystal oscillator 6.5. Lcd 6.6. Serial communication 6.7. ZIGBEE technology 7. Project schematic 8. Software tools 8.1. Keil 8.2. Proteus 8.3. Flash magic

9. Project code 10. Conclusion 11. Future scope 12. References

CHAPTER 1 ABBREVIATIONS
SYMBOL ACC B PSW SP DPTR DPL DPH P0 P1 P2 P3 IP IE TMOD TCON T2CON T2MOD TH0 TL0 TH1 TL1 TH2 TL2 SCON SBUF PCON NAME Accumulator B register Program status word Stack pointer Data pointer 2 bytes Low byte High byte Port0 Port1 Port2 Port3 Interrupt priority control Interrupt enable control Timer/counter mode control Timer/counter control Timer/counter 2 control Timer/counter mode2 control Timer/counter 0high byte Timer/counter 0 low byte Timer/counter 1 high byte Timer/counter 1 low byte Timer/counter 2 high byte Timer/counter 2 low byte Serial control Serial data buffer Power control

CHAPTER 2
ABSTRACT

Every system is automated in order to face new challenges in the present day situation. Automated systems have less manual operations, so that the flexibility, reliabilities are high and accurate. Hence every field prefers automated control systems. Especially in the field of electronics automated systems are doing better performance. The main aim of this project is to control various electrical appliances by means of PC using PCs hyper terminal window. The person sitting in front of the PC can continuously check the loads being operated in the rooms and can switch off them wherever not required just by sitting in front of his PC. The controlling of loads is done by Relay. In order to control the electrical appliances through PC, data transfer must be ensured between PC and 8051 system. Serial data communication uses a single data line which makes it not only cheaper but also enables two computers located in two different cities to communicate over the telephone. There are special IC chips made by many manufacturers for serial data communication. These chips are usually referred to as USART(Universal synchronous-asynchronous receiver-transmitter) and UART(Universal asynchronous receiver-transmitter). 8051 chip has an in-built UART i.e., it has an integrated serial port which enables one to read and write values to the serial port very easily. The rate of data transfer in serial data communication is stated in bps (bits per second) or baud rate. To allow data transfer between PC and 8051 system without any error, the baud rate of the 8051 system should match the baud rate of the PCs COM port. Thus the operation mode and baud rate of the serial port is to be configured. Once configured, read or write operations can be performed accordingly.

CHAPTER 3
3. BLOCK-DIAGRAM TRANSMITTER SECTION

POWER SUPPLY

M I C R O C O N T R O L L E R

Lcd 16x2

ZIGBEE TRANSCEIVER

Personal computer Crystal oscillator

Relay driver

Relay

Devices

M I C R O

RECEVIER SECTION
POWER SUPPLY

C O N T R O L L E R

Lcd 16x2

ZIGBEE TRANSCEIVER

Relay driver

Relay

Crystal oscillator

Devices

CHAPTER 4

4. Block Diagram Explanation DESCRIPTION:


Every system is automated in order to face new challenges in the present day situation. Automated systems have less manual operations, so that the flexibility, reliabilities are high and accurate. Hence every field prefers automated control systems. Especially in the field of electronics automated systems are doing better performance. In this project there are three sections, first section is the IR remote section in which switches are connected, next is the IR receiver section in which the signals sent by the IR TX is received, displayed on LCD and using Zigbee technology it will be transmitted to Receiver section there Zigbee will received the signals according to that signals devices will be operated.

ZIGBEE:
Now a day's every system is automated in order to face new challenges. In the present days Automated systems have less manual operations, flexibility, reliability and accurate. Due to this demand every field prefers automated control systems. Especially in the field of electronics automated systems are giving good performance. And this is realized by making use of Zigbee technology for communication. Zigbee is new wireless technology guided by IEEE 802.15.4 Personal Area Network standard. It is primarily designed for the wide ranging controlling applications and to replace the existing nonstandard technologies. It currently operates in 868MHz band at a data rate of 20Kbps in Europe, 914MHz band at 40kbps in USA, and the 2.4GHz ISM bands Worldwide at a maximum data-rate of 250kbps.

CHAPTER 5 5.1. Introduction To Embedded Systems


An embedded system is some combination of computer hardware and software, either fixed in capability or programmable, that is specifically designed for a particular function. A general-purpose definition of embedded systems is that they are devices used to control, monitor or assist the operation of equipment, machinery or plant. "Embedded" reflects the fact that they are an integral part of the system. In many cases their embedded may be such that their presence is far from obvious to the casual observer and even the more technically skilled might need to examine the operation of a piece of equipment for some time before being able to conclude that an embedded control system was involved in its functioning. At the other extreme a general-purpose computer may be used to control the operation of a large complex processing plant, and its presence will be obvious. All embedded systems are including computers or microprocessors. Some of these computers are however very simple systems as compared with a personal computer. The very simplest embedded systems are capable of performing only a single function or set of functions to meet a single predetermined purpose. In more complex systems an application program that enables the embedded system to be used for a particular purpose in a specific application determines the functioning of the embedded system. The ability to have programs means that the same embedded system can be used for a variety of different purposes. In some cases a microprocessor may be designed in such a way that application software for a particular purpose can be added to the basic software in a second process, after which it is not possible to make further changes. The simplest devices consist of a single microprocessor (often called a "chip), which may itself be packaged with other chips in a hybrid system or Application Specific Integrated Circuit (ASIC). Its input comes from a detector or sensor and its output goes to a switch or activator which (for example) may start or stop the operation of a machine or, by operating a valve, may control the flow of fuel to an engine.

5.1.1. Block diagram of embedded system The embedded system is the combination of both software and hardware.

Embedded System

Software

Hardware

ALP C VB Etc.,

Processor Peripherals memory

Fig1.1: Block diagram of Embedded System Software deals with the languages like ALP, C, and VB etc. Hardware deals with Processors, Peripherals, and Memory. Memory Processor : It is used to store data or address. : It is an IC which is used to perform some task Peripherals : These are the external devices connected

Processors are classified into four types like: 1. Micro Processor (p) 2. Micro controller (c) 3. Digital Signal Processor (DSP) 4. Application Specific Integrated Circuits (ASIC)

5.1.2 Micro Processor (p): It is an electronic chip which performs arithmetic and logical operations with assistance of internal memory.

ALU CU

MEMORY Fig1.2: Block Diagram of Micro Processor (p)

5.1.3 Micro Controller (c): It is a highly integrated micro processor designed for specific use in embedded systems.

Fig1.3: Block Diagram of Micro Controller (c) Memory CPU

I/O PORTS

5.1.4. Micro Controller versus Micro Processor 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. 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. 5.1.5. Micro Controller 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. Table 1-1 lists some embedded products. 5.1.6 Applications of embedded system: Manufacturing and process control Construction industry Transport Buildings and premises Domestic service Communications Office systems and mobile equipment Banking, finance and commercial Medical diagnostics, monitoring and life support Testing, monitoring and diagnostic systems

5.1.7 Industrial functions of embedded systems: A manufacturing company has provided the following list of embedded systems Multi-loop control and monitoring: - DCS, SCADA, telemetry Panel mounted devices: - Control, display, recording and operations

Safety and security: - Alarm and trip systems, fire and gas systems, buildings and facilities security Field devices: - measurement, actuation Analytical systems: - Laboratory systems; on-line/ plant systems Electrical supply :- supply, measurement, control, protection Tools :- for design, documentation, testing, maintenance

5.1.8 Electronics applications and consumer devices: As the number of powerful embedded processors in consumer devices continues to rise, the Blue Cat Linux operating system provides a highly reliable and royalty-free option for systems designers. And as the wireless appliance revolution rolls on, web-enabled navigation systems, radios, personal communication devices, phones and PDAs all benefit from the costeffective dependability, proven stability and full product life-cycle support opportunities associated with Blue Cat embedded Linux. Blue Cat has teamed up with industry leaders to make it easier to build Linux mobile phones with Java integration. For makers of low-cost consumer electronic devices who wish to integrate the LynxOS real-time operating system into their products, we offer special MSRP-based pricing to reduce royalty fees to a negligible portion of the device's MSRP. 5.1.9 Military and aerospace software applications From in-orbit embedded systems to jumbo jets to vital battlefield networks, designers of mission-critical aerospace and defense systems requiring real-time performance, scalability, and high-availability facilities consistently turn to the LynxOS RTOS and the LynxOS-178 RTOS for software certification to DO-178B. Rich in system resources and networking services, Lynx OS provides an off-the-shelf software platform with hard real-time response backed by powerful distributed

computing (CORBA), high reliability, software certification, and long-term support options. The LynxOS-178 RTOS for software certification, based on the RTCA DO-178B standard, assists developers in gaining certification for their mission- and safety-critical systems. Real-time systems programmers get a boost with Lynux Works' DO-178B RTOS training courses. LynxOS-178 is the first DO-178B and EUROCAE/ED-12B certifiable, POSIXcompatible RTOS solution.

6. Hardware Description
6.1 Micro Controller 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 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. The Intel 8051 is Harvard architecture, single chip microcontroller (C) which was developed by Intel in 1980 for use in embedded systems. It was popular in the 1980s and early 1990s, but today it has largely been superseded by a vast range of enhanced devices with 8051-compatible processor cores that are manufactured by more than 20 independent manufacturers including Atmel, Infineon Technologies and Maxim Integrated Products. 8051 is an 8-bit processor, meaning that the CPU can work on only 8 bits of data at a time. Data larger than 8 bits has to be broken into 8-bit pieces to be processed by the CPU. 8051 is available in different memory types such as UV-EPROM, Flash and NVRAM.

Features
Compatible with MCS-51 Products 4K Bytes of In-System Programmable (ISP) Flash Memory 4.0V to 5.5V Operating Range 128 x 8-bit Internal RAM 32 Programmable I/O Lines Two 16-bit Timer/Counters

Six Interrupt Sources Full Duplex UART Serial Channel Low-power Idle and Power-down Modes 6.1.1 Description The AT89S51 is a low-power, high-performance CMOS 8-bit microcontroller with 4K bytes of in-system programmable Flash memory. The device is manufactured using Atmels high-density nonvolatile memory technology and is compatible with the industry- standard 8051 instruction set and pinout. The on-chip Flash allows the program memory to be reprogrammed in-system or by a conventional nonvolatile memory programmer. By combining a versatile 8-bit CPU with in-system programmable Flash on a monolithic chip, the Atmel AT89S51 is a powerful microcontroller which provides a highly-flexible and cost-effective solution to many embedded control applications. 6.1.2 The AT89S51 provides the following standard features: 4K bytes of Flash, 128 bytes of RAM, 32 I/O lines, Watchdog timer, two data pointers, two 16-bit timer/counters, a five vector two-level interrupt architecture, a full duplex serial port, on-chip oscillator, and clock circuitry. In addition, the AT89S51 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 external interrupt or hardware reset.

6.1.3 Pin diagram

6.1.4 Block Diagram

6.1.5 Pin Description VCC Supply voltage. GND Ground. Port 0 Port 0 is an 8-bit open drain bidirectional I/O port. As an output port, each pin can sink eight TTL inputs. When 1s are written to port 0 pins, the pins can be used as highimpedance inputs. 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 pull-ups 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 pull-ups. Port 1 also receives the low-order address bytes during Flash programming and verification.

Port 2 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 pull-ups 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 use 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 use 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 is an 8-bit bidirectional I/O port with internal pull-ups. The Port 3 output buffers can sink/source four TTL inputs. When 1s are written to Port 3 pins, they are pulled high by the internal pull-ups and can be used as inputs. As inputs, Port 3 pins that are externally being pulled low will source current (IIL) because of the pull-ups. Port 3 receives some control signals for Flash programming and verification. Port 3 also serves the functions of various special features of the AT89S51, as shown in the following table.

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 98 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. ALE/PROG 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 (PROG) 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.

PSEN Program Store Enable (PSEN) is the read strobe to external program memory. When the AT89S51 is executing code from external program memory, PSEN is activated twice each machine cycle, except that two PSEN activations are skipped during each access to external data memory. EA/VPP External Access Enable. EA must be strapped to GND in order to enable the device to fetch code from external program memory locations starting at 0000H up to FFFFH. Note, however, that if lock bit 1 is programmed, EA will be internally latched on reset. EA should be strapped to VCC for internal program executions. This pin also receives the 12-volt programming enable voltage (VPP) during Flash programming. XTAL1 Input to the inverting oscillator amplifier and input to the internal clock operating circuit. XTAL2 Output from the inverting oscillator amplifier 6.1.6 Special Function Registers A map of the on-chip memory area called the Special Function Register (SFR) space is shown in Table 1. Note that not all of the addresses are occupied, and unoccupied addresses may not be implemented on the chip. Read accesses to these addresses will in general return random data, and write accesses will have an indeterminate effect.

User software should not write 1s to these unlisted locations, since they may be used in future products to invoke new features. In that case, the reset or inactive values of the new bits will always be 0. Interrupt Registers: The individual interrupt enable bits are in the IE register. Two priorities can be set for each of the five interrupt sources in the IP register.

Dual Data Pointer Registers: To facilitate accessing both internal and external data memory, two banks of 16-bit Data Pointer Registers are provided: DP0 at SFR address locations 82H- 83H and DP1 at 84H-85H. Bit DPS = 0 in SFR AUXR1 selects DP0 and DPS = 1 selects DP1. The user should always initialize the DPS bit to the appropriate value before accessing the respective Data Pointer Register. Power off Flag: The Power Off Flag (POF) is located at bit 4 (PCON.4) in the PCON SFR. POF is set to 1 during power up. It can be set and rest under software control and is not affected by reset.

Memory Organization

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. 6.1.7 Program Memory If the EA pin is connected to GND, all program fetches are directed to external memory. On the AT89S51, if EA is connected to VCC, program fetches to addresses 0000H through FFFH are directed to internal memory and fetches to addresses 1000H through FFFFH are directed to external memory.

6.1.8 Data Memory The AT89S51 implements 128 bytes of on-chip RAM. The 128 bytes are accessible via direct and indirect addressing modes. Stack operations are examples of indirect addressing, so the 128 bytes of data RAM are available as stack space. 6.1.9 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 14-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 DTRST 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 14-bit counter overflows when it reaches 16383 (3FFFH), 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 16383 machine cycles. To reset the WDT the user must write 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 98xTOSC, 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. 6.1.10 WDT During Power-down and Idle In Power-down mode the oscillator stops, which means the WDT also stops. While in Powerdown mode, the user does not need to service the WDT. There are two methods of

exiting Power-down mode: by a hardware reset or via a level-activated external interrupt, which is enabled prior to entering Power-down mode. When Power-down is exited with hardware reset, servicing the WDT should occur as it normally does whenever the AT89S51 is reset. Exiting Power-down with an interrupt is significantly different. The interrupt is held low long enough for the oscillator to stabilize. When the interrupt is brought high, the interrupt is serviced. To prevent the WDT from resetting the device while the interrupt pin is held low, the WDT is not started until the interrupt is pulled high. It is suggested that the WDT be reset during the interrupt service for the interrupt used to exit Power-down mode. To ensure that the WDT does not overflow within a few states of exiting Power-down, it is best to reset the WDT just before entering Powerdown mode. Before going into the IDLE mode, the WDIDLE bit in SFR AUXR is used to determine whether the WDT continues to count if enabled. The WDT keeps counting during IDLE (WDIDLE bit =0) as the default state. To prevent the WDT from resetting the AT89S51 while in IDLE mode, the user should always set up a timer that will periodically exit IDLE, service the WDT, and reenter IDLE mode.With WDIDLE bit enabled, the WDT will stop to count in IDLE mode and resumes the count upon exit from IDLE. 6.1.11 UART The UART in the AT89S51 operates the same way as the UART in the AT89C51. 6.1.12 Timer 0 and 1 Timer 0 and Timer 1 in the AT89S51 operate the same way as Timer 0 and Timer 1 in the AT89C51. 6.1.13 Interrupts The AT89S51 has a total of five interrupt vectors: two external interrupts (INT0 and INT1), two timer interrupts (Timers 0 and 1), and the serial port interrupt. These interrupts are all shown in Figure 1. 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 4 shows that bit position IE.6 is

unimplemented. In the AT89S51, 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. 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.

6.1.14 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, as shown in Figure 2. 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, as shown in Figure 3. 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.

6.1.15 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 function 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. 6.1.16 Power-down Mode In the Power-down mode, the oscillator is stopped, and the instruction that invokes Powerdown 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 Powerdown mode can be initiated either by a hardware reset or by activation of an enabled

After Reset signal is high, SCK should be low for at least 64 system clocks before it goes high to clock in the enable data bytes. No pulsing of Reset signal is necessary. SCK should be no faster than 1/16 of the system clock at XTAL1. For Page Read/Write, the data always starts from byte 0 to 255. After the command byte and upper address byte are latched, each byte thereafter is treated as data until all 256 bytes are shifted in/out. Then the next instruction will be ready to be decoded.

*NOTICE: Stresses beyond those listed under Absolute Maximum Ratings may cause permanent damage to the device. This is a stress rating only and functional operation of

the device at these or any other conditions beyond those indicated in the operational sections of this specification is not implied. Exposure to absolute maximum rating conditions for extended periods may affect device reliability.

6.2 Power supply


The power supplies are designed to convert high voltage AC mains electricity to a suitable low voltage supply for electronics circuits and other devices. A power supply can by broken down into a series of blocks, each of which performs a particular function. A d.c power supply which maintains the output voltage constant irrespective of a.c mains fluctuations or load variations is known as Regulated D.C Power Supply For example a 5V regulated power supply system as shown below:

6.2.1 Transformer A transformer is an electrical device which is used to convert electrical power from one Electrical circuit to another without change in frequency. Transformers convert AC electricity from one voltage to another with little loss of power. Transformers work only with AC and this is one of the reasons why mains electricity is AC. Step-up transformers increase in output voltage, step-down

transformers decrease in output voltage. Most power supplies use a step-down transformer to reduce the dangerously high mains voltage to a safer low voltage. The input coil is called the primary and the output coil is called the secondary. There is no electrical connection between the two coils; instead they are linked by an alternating magnetic field created in the soft-iron core of the transformer. The two lines in the middle of the circuit symbol represent the core. is stepped up. Transformers waste very little power so the power out is (almost) equal to the power in. Note that as voltage is stepped down current The ratio of the number of turns on each coil, called the turns ratio, determines the ratio of the voltages. A step-down transformer has a large number of turns on its primary (input) coil which is connected to the high voltage mains supply, and a small number of turns on its secondary (output) coil to give a low output voltage.

An Electrical Transformer Turns ratio = Vp/ VS = Np/NS Power Out= Power In VS X IS=VP X IP Vp = primary (input) voltage Np = number of turns on primary coil Ip = primary (input) current 6.2.2 RECTIFIER: A circuit which is used to convert a.c to dc is known as RECTIFIER. The process of conversion a.c to d.c is called rectification

TYPES OF RECTIFIERS: Half wave Rectifier Full wave rectifier 1. Centre tap full wave rectifier. 2. Bridge type full bridge rectifier. 6.2.3 Comparison of rectifier circuits: Type of Rectifier Parameter Number of diodes 1 PIV of diodes Vm D.C output voltage Vdc,at no-load Ripple factor Ripple Frequency Rectification Efficiency Transformer Utilization Factor(TUF) RMS voltage Vrms 1.21 f 0.406 0.287 Vm/2 0.482 2f 0.812 0.693 Vm/2 0.482 2f 0.812 0.812 Vm/2 Vm/ 0.318Vm 2Vm 2Vm/ 0.636Vm Vm 2Vm/ 0.636Vm 2 4 Half wave Full wave Bridge

6.2.4 Full-wave Rectifier:

From the above comparison we came to know that full wave bridge rectifier as more advantages than the other two rectifiers. So, in our project we are using full wave bridge rectifier circuit. Bridge Rectifier:

The Bridge rectifier is a circuit, 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 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.

6.2.5 Filter A Filter is a device which removes the a.c component of rectifier output but allows the d.c component to reach the load Capacitor Filter We have seen that the ripple content in the rectified output of half wave rectifier is 121% or that of full-wave or bridge rectifier or bridge rectifier is 48% such high percentages of ripples is not acceptable for most of the applications. Ripples can be removed by one of the following methods of filtering. (a) A capacitor, in parallel to the load, provides an easier by pass for the ripples voltage though it due to low impedance. At ripple frequency and leave the d.c.to appears the load. (b) An inductor, in series with the load, prevents the passage of the ripple current (due to high impedance at ripple frequency) while allowing the d.c (due to low resistance to d.c)

(c) Various combinations of capacitor and inductor, such as L-section filter

section

filter, multiple section filter etc. which make use of both the properties mentioned in (a) and (b) above. Two cases of capacitor filter, one applied on half wave rectifier and another with full wave rectifier.

Filtering is performed by a large value electrolytic capacitor connected across the DC supply to act as a reservoir, supplying current to the output when the varying DC voltage from the rectifier is falling. The capacitor charges quickly near the peak of the varying DC, and then discharges as it supplies current to the output. Filtering significantly increases the average DC voltage to almost the peak value (1.4 RMS value).

To calculate the value of capacitor(C), C = *3*f*r*Rl Where, f = supply frequency, r = ripple factor, Rl = load resistance Note: In our circuit we are using 1000F Hence large value of capacitor is placed to reduce ripples and to improve the DC component. 6.2.6 Regulator: Voltage regulator ICs is available with fixed (typically 5, 12 and 15V) or variable output voltages. The maximum current they can pass also rates them. Negative voltage regulators are available, mainly for use in dual supplies. Most regulators include some automatic protection from excessive current ('overload protection') and overheating ('thermal protection'). Many of the fixed voltage regulator ICs has 3 leads and look like power transistors, such as the 7805 +5V 1A regulator shown on the right. The LM7805 is simple to use. You simply connect the positive lead of your unregulated DC power supply (anything from 9VDC to 24VDC) to the Input pin, connect the negative lead to the Common pin and then when you turn on the power, you get a 5 volt supply from the output pin.

78XX: The Bay Linear LM78XX is integrated linear positive regulator with three terminals. The LM78XX offer several fixed output voltages making them useful in wide range of applications. When used as a zener diode/resistor combination replacement, the LM78XX usually results in an effective output impedance improvement of two orders of magnitude, lower quiescent current. The LM78XX is available in the TO-252, TO-220 & TO-263packages, Features: Output Current of 1.5A Output Voltage Tolerance of 5% Internal thermal overload protection Internal Short-Circuit Limited No External Component Output Voltage 5.0V, 6V, 8V, 9V, 10V, 12V, 15V, 18V, 24V Offer in plastic TO-252, TO-220 & TO-263 Direct Replacement for LM78XX

6.3 RESET
In electronics and technology, a reset button is a button that can reset a device. On video game consoles, the reset button restarts the game, losing the player's unsaved progress. On personal computers, the reset button clears the memory and reboots the machine forcibly. Reset buttons are found on circuit breakers to reset the circuit. This button can cause data corruption so this button often doesn't exist on many machines. Usually, in computers and other electronic devices, it is present as a small button, possibly recessed into the case or only accessible by a pin or similar thin object, to prevent it being pressed accidentally. The reset button could be an actual button or concept. The reset button would typically kick off a soft boot, instructing the computer to go through the process of shutting down, which would clear memory and reset devices to their initialized state. Contrary to the 'Power Button', which would simply remove power immediately.

Pressing the reset button would be preferable to the power button, which could potentially leave a device in the middle of some operation and subject to defect. In most commodity hardware, the consumer would expect the device to be resilient enough to 'reset' when power was restored.

Depending on the architecture, the reset button might have different effects. On PCs, usually it is connected to the motherboard, and when pressed it sends a reset signal to all peripherals. Many newer computers have no separate button for resetting the computer, it is integrated with the power button. On most newer operating systems, the user can customize what happens when they press the power button. For example they may set it to 'Do nothing', 'restart', 'shutdown', or 'stand by'. This is only for pressing the button once; on most computers the power button can remove power immediately if held down for a few seconds. When OS hangs reset button is no longer "integrated with the power button".

6.4 CRYSTAL OSCILATOR


A crystal oscillator is an electronic oscillator circuit that uses the mechanical resonance of track of time (as a vibrating crystal of piezoelectric wristwatches), and to to material to a create an electrical signal with a very precise frequency. This frequency is commonly used to keep in quartz circuits, provide stable clock for radio signal for digital integrated stabilize frequencies

transmitters and receivers. The most common type of piezoelectric resonator used is the quartz crystal, so oscillator circuits incorporating them became known as crystal oscillators,[] but other piezoelectric materials including polycrystalline ceramics are used in similar circuits. Quartz crystals are manufactured for frequencies from a few tens of kilohertz to tens of megahertz. More than two billion crystals are manufactured annually. Most are used for consumer devices such as wristwatches, clocks, radios, computers, and cell phones. Quartz crystals are also found inside test and measurement equipment, such as counters, signal generators, and oscilloscopes.

6.5 LCD
6.5.1 LIQUID CRYSTAL DISPLAY: LCD stands for Liquid Crystal Display. LCD is finding wide spread use replacing LEDs (seven segment LEDs or other multi segment LEDs) because of the following reasons: 1. The declining prices of LCDs. 2. The ability to display numbers, characters and graphics. This is in contrast to LEDs, which are limited to numbers and a few characters. 3. Incorporation of a refreshing controller into the LCD, thereby relieving the CPU of the task of refreshing the LCD. In contrast, the LED must be refreshed by the CPU to keep displaying the data. 4. Ease of programming for characters and graphics. These components are specialized for being used with the microcontrollers, which means that they cannot be activated by standard IC circuits. They are used for writing different messages on a miniature LCD.

A model described here is for its low price and great possibilities most frequently used in practice. It is based on the HD44780 microcontroller ( Hitachi) and can display messages in two lines with 16 characters each. It displays all the alphabets, Greek letters, punctuation marks, mathematical symbols etc. In addition, it is possible to display symbols that user makes up on its own. Automatic shifting message on display (shift left and right), appearance of the pointer, backlight etc. are considered as useful characteristics. 6.5.2 Pins Functions There are pins along one side of the small printed board used for connection to the microcontroller. There are total of 14 pins marked with numbers (16 in case the background light is built in). Their function is described in the table below: Function Ground Power supply Contrast Pin Number 1 2 3 4 Name Vss Vdd Vee RS Logic State Description

Control of operating

R/W

6 Data / commands 7 8 9 10 11 12

E D0 D1 D2 D3 D4 D5

0V +5V 0 Vdd D0 D7 are interpreted as 0 commands 1 D0 D7 are interpreted as data Write data (from controller to 0 LCD) 1 Read data (from LCD to controller) 0 Access to LCD disabled 1 Normal operating From 1 to Data/commands are transferred to 0 LCD 0/1 Bit 0 LSB 0/1 Bit 1 0/1 Bit 2 0/1 Bit 3 0/1 Bit 4 0/1 Bit 5

13 14

D6 D7

0/1 0/1

Bit 6 Bit 7 MSB

6.5.3 LCD screen: LCD screen consists of two lines with 16 characters each. Each character consists of 5x7 dot matrix. Contrast on display depends on the power supply voltage and whether messages are displayed in one or two lines. For that reason, variable voltage 0-Vdd is applied on pin marked as Vee. Trimmer potentiometer is usually used for that purpose. Some versions of displays have built in backlight (blue or green diodes). When used during operating, a resistor for current limitation should be used (like with any LE diode).

6.5.4 LCD Basic Commands All data transferred to LCD through outputs D0-D7 will be interpreted as commands or as data, which depends on logic state on pin RS:

RS = 1 - Bits D0 - D7 are addresses of characters that should be displayed. Built in processor addresses built in map of characters and displays corresponding symbols. Displaying position is determined by DDRAM address. This address is either previously defined or the address of previously transferred character is automatically incremented. RS = 0 - Bits D0 - D7 are commands which determine display mode. List of commands which LCD recognizes are given in the table below: Command Clear display Cursor home Entry mode set Display on/off control Cursor/Display Shift Function set Set CGRAM address Set DDRAM address Read BUSY flag (BF) Write to CGRAM or DDRAM Read from CGRAM or DDRAM I/D 1 = Increment (by 1) 0 = Decrement (by 1) S 1 = Display shift on 0 = Display shift off D 1 = Display on 0 = Display off U 1 = Cursor on 0 = Cursor off RS RW D7 D6 D5 D4 D3 D2 D1 D0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 I/ 0 0 0 1 D 0 0 1 D U 0 1 D/C R/L x 1 DL N F x CGRAM address DDRAM address DDRAM address 0 0 0 0 0 0 1 x S B x x Execution Time 1.64mS 1.64mS 40uS 40uS 40uS 40uS 40uS 40uS 40uS 40uS

0 0 0 0 0 0 0 0 0 1 1 BF

0 D7 D6 D5 D4 D3 D2 D1 D0 1 D7 D6 D5 D4 D3 D2 D1 D0 R/L 1 = Shift right 0 = Shift left DL 1 = 8-bit interface 0 = 4-bit interface N 1 = Display in two lines 0 = Display in one line

F 1 = Character format 5x10 dots 0 = Character format 5x7 dots

B 1 = Cursor blink on 0 = Cursor blink off

D/C 1 = Display shift 0 = Cursor shift

6.5.5 LCD Connection Depending on how many lines are used for connection to the microcontroller, there are 8bit and 4-bit LCD modes. The appropriate mode is determined at the beginning of the process in a phase called initialization. In the first case, the data are transferred through outputs D0-D7 as it has been already explained. In case of 4-bit LED mode, for the sake of saving valuable I/O pins of the microcontroller, there are only 4 higher bits (D4-D7) used for communication, while other may be left unconnected. Consequently, each data is sent to LCD in two steps: four higher bits are sent first (that normally would be sent through lines D4-D7), four lower bits are sent afterwards. With the help of initialization, LCD will correctly connect and interpret each data received. Besides, with regards to the fact that data are rarely read from LCD (data mainly are transferred from microcontroller to LCD) one more I/O pin may be saved by simple connecting R/W pin to the Ground. Such saving has its price. Even though message displaying will be normally performed, it will not be possible to read from busy flag since it is not possible to read from display. 6.5.6 LCD Initialization Once the power supply is turned on, LCD is automatically cleared. This process lasts for approximately 15mS. After that, display is ready to operate. The mode of operating is set by default. This means that: 1. Display is cleared 2. Mode DL = 1 Communication through 8-bit interface N = 0 Messages are displayed in one line F = 0 Character font 5 x 8 dots

3. Display/Cursor on/off D = 0 Display off U = 0 Cursor off B = 0 Cursor blink off 4. Character entry ID = 1 Addresses on display are automatically incremented by 1 S = 0 Display shift off Automatic reset is mainly performed without any problems. Mainly but not always! If for any reason power supply voltage does not reach full value in the course of 10mS, display will start perform completely unpredictably. If voltage supply unit can not meet this condition or if it is needed to provide completely safe operating, the process of initialization by which a new reset enabling display to operate normally must be applied. Algorithm according to the initialization is being performed depends on whether connection to the microcontroller is through 4- or 8-bit interface. All left over to be done after that is to give basic commands and of course- to display messages. 6.5.7 Contrast control: To have a clear view of the characters on the LCD, contrast should be adjusted. To adjust the contrast, the voltage should be varied. For this, a preset is used which can behave like a variable voltage device. As the voltage of this preset is varied, the contrast of the LCD can be adjusted.

Fig: Variable resistor

Potentiometer Variable resistors used as potentiometers have all three terminals connected. This arrangement is normally used to vary voltage, for example to set the switching point of a circuit with a sensor, or control the volume (loudness) in an amplifier circuit. If the terminals at the ends of the track are connected across the power supply, then the wiper terminal will provide a voltage which can be varied from zero up to the maximum of the supply.

Potentiometer Symbol

Presets These are miniature versions of the standard variable resistor. They are designed to be mounted directly onto the circuit board and adjusted only when the circuit is built. For example, to set the frequency of an alarm tone or the sensitivity of a light-sensitive circuit, a small screwdriver or similar tool is required to adjust presets. Presets are much cheaper than standard variable resistors so they are sometimes used in projects where a standard variable resistor would normally be used.

Multiturn presets are used where very precise adjustments must be made. The screw must be turned many times (10+) to move the slider from one end of the track to the other, giving very fine control.

6.6 Serial Communication:


The main requirements for serial communication are: 1. RS 232 cable 2. MAX 232 IC 6.6.1 Asynchronous and Synchronous Serial Communication Computers transfer data in two ways: parallel and serial. In parallel data transfers, often 8 or more lines are used to transfer data to a device that is only a few feet away. Although a lot of data can be transferred in a short amount of time by using many wires in parallel, the distance cannot be great. To transfer to a device located many meters away, the serial method is best suitable.

In serial communication, the data is sent one bit at a time. The 8051 has serial communication capability built into it, thereby making possible fast data transfer using only a few wires. The fact that serial communication uses a single data line instead of the 8-bit data line instead of the 8-bit data line of parallel communication not only makes it cheaper but also enables two computers located in two different cities to communicate over the telephone. Serial data communication uses two methods, asynchronous and synchronous. The synchronous method transfers a block of data at a time, while the asynchronous method transfers a single byte at a time. With synchronous communications, the two devices initially synchronize themselves to each other, and then continually send characters to stay in sync. Even when data is not really being sent, a constant flow of bits allows each device to know where the other is at any given time. That is, each character that is sent is either actual data or an idle character. Synchronous communications allows faster data transfer rates than asynchronous methods, because additional bits to mark the beginning and end of each data byte are not required. The serial ports on IBM-style PCs are asynchronous devices and therefore only support asynchronous serial communications. Asynchronous means "no synchronization", and thus does not require sending and receiving idle characters. However, the beginning and end of each byte of data must be identified by start and stop bits. The start bit indicates when the data byte is about to begin and the stop bit signals when it ends. The requirement to send these additional two bits causes asynchronous communication to be slightly slower than synchronous however it has the advantage that the processor does not have to deal with the additional idle characters. There are special IC chips made by many manufacturers for serial data communications. These chips are commonly referred to as UART(universal asynchronous receiver-

transmitter) and USART(universal synchronous-asynchronous receiver-transmitter). The 8051 has a built-in UART. In the asynchronous method, the data such as ASCII characters are packed between a start and a stop bit. The start bit is always one bit, but the stop bit can be one or two bits. The start bit is always a 0 (low) and stop bit (s) is 1 (high). This is called framing. The rate of data transfer in serial data communication is stated as bps (bits per second). Another widely used terminology for bps is baud rate. The data transfer rate of a given computer system depends on communication ports incorporated into that system. And in asynchronous serial data communication, this baud rate is generally limited to 100,000bps. The baud rate is fixed to 9600bps in order to interface with the microcontroller using a crystal of 11.0592 MHz. 6.6.2 RS232 CABLE: To allow compatibility among data communication equipment, an interfacing standard called RS232 is used. Since the standard was set long before the advent of the TTL logic family, its input and output voltage levels are not TTL compatible. For this reason, to connect any RS232 to a microcontroller system, voltage converters such as MAX232 are used to convert the TTL logic levels to the RS232 voltage levels and vice versa.

8051 connection to RS232

TXD

RXD TXD

2 3 5

Embedded Controller

RXD GND

MAX 232

Fig.7.1: Connection of Microcontroller with Serial Port Using MAX 232 6.6.3 MAX 232: Max232 IC is a specialized circuit which makes standard voltages as required by RS232 standards. This IC provides best noise rejection and very reliable against discharges and short circuits. MAX232 IC chips are commonly referred to as line drivers. To ensure data transfer between PC and microcontroller, the baud rate and voltage levels of Microcontroller and PC should be the same. The voltage levels of microcontroller are logic1 and logic 0 i.e., logic 1 is +5V and logic 0 is 0V. But for PC, RS232 voltage levels are considered and they are: logic 1 is taken as -3V to -25V and logic 0 as +3V to +25V. So, in order to equal these voltage levels, MAX232 IC is used. Thus this IC converts RS 232 voltage levels to microcontroller

vo versa.

ltage levels and vice

Interfacing max232 with microcontroller:

6.6.4 SCON (serial control) register: The SCON register is an 8-bit register used to program the start bit, stop bit and data bits of data framing.

SM0 SM1 SM2 REN TB8 RB8 TI

SCON.7 SCON.6 SCON.5 SCON.4 SCON.3 SCON.2 SCON.1

Serial port mode specifier Serial port mode specifier Used for multiprocessor communication Set/cleared by software to enable/disable reception Not widely used Not widely used Transmit interrupt flag. Set by hardware at the beginning of the stop bit in mode 1. Must be cleared by software.

RI

SCON.0

Receive interrupt flag. Set by hardware at the beginning of the stop bit in mode 1. Must be cleared by software.

SM0 0 0 1 1

SM1 0 1 0 1 Serial Mode 0 Serial Mode 1, 8-bit data, 1 stop bit, 1 start bit Serial Mode 2 Serial Mode 3

Of the four serial modes, only mode 1 is widely used. In the SCON register, when serial mode 1 is chosen, the data framing is 8 bits, 1 stop bit and 1 start bit, which makes it compatible with the COM port of IBM/ compatible PCs. And the most important is serial mode 1 allows the baud rate to be variable and is set by Timer 1 of the 8051. In serial mode 1, for each character a total of 10 bits are transferred, where the first bit is the start bit, followed by 8 bits of data and finally 1 stop bit.

6.7.5 ZIGBEE TRANSCEIVER

Pin Diagram

Fig: 6.1 Pin diagram of X-Bee Transceiver

Zigbee modules feature a UART interface, which allows any microcontroller or microprocessor to immediately use the services of the Zigbee protocol. All a Zigbee hardware designer has to do in this ase is ensure that the hosts serial port logic levels are compatible with the XBees 2.8- to 3.4-V logic levels. The logic level conversion can be performed using either a standard RS-232 IC or logic level translators such as the 74LVTH125 when the host is directly connected to the XBee UART. The below table gives the pin description of transceiver.

Table: 6.1 Pin Description of X-Bee Transceiver Pin Name Direction Description

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

Vcc DOUT DIN/CONFIG DO8 RESET PWM0/RSSI PWM1 [reserved] DDR/SLEEP_RQ/DI8 GND AD4/DIO4 CTS/DIO7 ON/SLEEP VREF Associate/AD5/DIO5 RTS/AD6/DIO6 AD3/DIO3 AD2/DIO2 AD1/DIO1 AD0/DIO0

Output Input Output Input Output Output Input Either Either Output Input Either Either Either Either Either Either

Power Supply UART Data Out UART Data In Digital Output 8 Module Reset PWM Output 0/RX Signal Strength Indicator PWM Output 1 Do not connect Pin Sleep Control Line or Digital Input 8 Ground Analog Input 4 or Digital I/O 4 Clear-to-Send Flow Control or Digital I/O 7 Module Status Indicator Voltage Reference for A/D Inputs Associated Indicator, Analog Input 5 or Digital I/O 5 Request-to-Send Flow Control, Analog Input 6 or Digital I/O 6 Analog Input 3 or Digital I/O 3 Analog Input 2 or Digital I/O 2 Analog Input 1 or Digital I/O 1 Analog Input 0 or Digital I/O 0

Design Notes: Minimum connections: VCC, GND, DOUT & DIN Minimum connections for updating firmware: VCC, GND, DIN, DOUT, RTS and DTR Signal Direction is specified with respect to the module
Module includes a 50k pull-up resistor attached to RESET

Several of the input pull-ups can be configured using the PR command

Unused pins should be left disconnected

Features
Performance: Table: 6.2 Performance characteristics

Parameters
Indoor/Urban Range Outdoor RF (LOS) Transmit Power Output RF Data Rate Serial Interface Data Rate Receiver Sensitivity

Value
30m 100m 1mW (0dBm) 250,000bps 1200-115200bps -92dBm

Power Requirements:
Table: 6.3 Power Requirement characteristics

Parameters
Supply Voltage Transmit Current Receive Current

Value
2.8 - 3.4V 45mA 50mA

General:
Table: 6.4 General characteristics

Parameters
Operating Frequency Dimensions Operating Temperature Antenna Options

Value
ISM 2.4GHz 2.468 x 2.761 -40o to 85o C Integrated Chip Antenna

Networking and Security:


Table: 6.5 Networking and Security characteristics

Parameters
Supported Network Topologies Number of Channels Addressing Options

Value
Point-to-point, Point-to-multipoint, Peer-to-peer 16 Direct Sequence Channels PAN ID, Channel and Addresses

6.3 System Data Flow Diagram

Fig: 6.2 Data Flow Diagram

The X-Bee RF Modules interface to a host device through a logic-level asynchronous Serial port. Through its serial port, the module can communicate with any logic and voltage Compatible UART; or through a level translator to any serial device. Data is presented to the X-Bee module through its DIN pin, and it must be in the asynchronous serial format, which consists of a start bit, 8 data bits, and a stop bit. Because the input data goes directly into the input of a UART within the X-Bee module, no bit inversions are necessary within the asynchronous serial data stream. All of the required timing and parity checking is automatically taken care of by the X-Bees UART. Just in case you are producing data faster than the X-Bee can process and transmit it, both X-Bee modules incorporate a clear-to-send (CTS) function to throttle the data being presented to the X-Bee modules DIN pin. You can eliminate the need for the CTS signal by sending small data packets at slower data rates. If the microcontroller wants to send data to transceiver, it will send RTS (Request to Send) signal. If the transceiver is idle it sends CTS (Clear to Send) signal. The RTS and CTS signals are active low. When microcontroller receives CTS command it will send data to the transceiver through DIN pin. The transceiver will send the data to microcontroller through DOUT pin. The communication between transceiver and the microcontroller at the transmitter and receiver is similar. The communication between transmitter and receiver is through RF communication.

6.4 Serial Data

Fig: 6.3 Serial Data Sequence For example: UART data packet 0x1F (decimal number is 31) as transmitted through the RF module. Data enters the module UART through the DI pin (pin 3) as an asynchronous serial signal. The signal should idle high when no data is being transmitted. Each data byte consists of a start bit (low), 8 data bits (least significant bit first) and a stop bit (high). The following figure illustrates the serial bit pattern of data passing through the module. The module UART performs tasks, such as timing and parity checking, that are needed for data communications. Serial communications depend on the two UARTs to be configured with compatible settings (baud rate, parity, start bits, stop bits, data bits). X-Bee RF Modules operate in Transparent Mode. When operating in this mode, the modules act as a serial line replacement - all UART data received through the DI pin is queued up for RF transmission. When RF data is received, the data is sent out the DO pin.

Serial-to-RF Packetization
Data is buffered in the DI buffer until one of the following causes the data to be packetized and transmitted: No serial characters are received for the amount of time determined by the RO (Packetization Timeout) parameter. If RO = 0, packetization begins when a character is received. The maximum number of characters that will fit in an RF packet (100) is received. The Command Mode Sequence (GT + CC + GT) is received. Any character buffered in the DI buffer before the sequence is transmitted. If the module cannot immediately transmit (for instance, if it is already receiving RF data), the serial data is stored in the DI Buffer. The data is packetized and sent at any RO timeout or when 100 bytes (maximum packet size) are received. If the DI buffer becomes full, hardware or software flow control must be implemented in order to prevent overflow (loss of data between the host and module).

6.5 Internal Data Flow

Fig: 6.4 Internal Data Flow Diagram DI (Data In) Buffer: When serial data enters the RF module through the DI pin (pin 3), the data is stored in the DI Buffer until it can be processed. Hardware Flow Control (CTS): When the DI buffer is 17 bytes away from being full; by default, the module deasserts CTS (high) to signal to the host device to stop sending data [refer to D7 (DIO7 Configuration) parameter]. CTS are re-asserted after the DI Buffer has 34 bytes of memory available. How to eliminate the need for flow control: Send messages that are smaller than the DI buffer size. Interface at a lower baud rate [BD (Interface Data Rate) parameter] than the throughput data rate. Case in which the DI Buffer may become full and possibly overflow:

If the module is receiving a continuous stream of RF data, any serial data that arrives on the DI pin is placed in the DI Buffer. The data in the DI buffer will be transmitted over-the-air when the module is no longer receiving RF data in the network. DO (Data Out) Buffer: When RF data is received, the data enters the DO buffer and is sent out the serial port to a host device. Once the DO Buffer reaches capacity, any additional incoming RF data is lost. Hardware Flow Control (RTS): If RTS is enabled for flow control (D6 (DIO6 Configuration) Parameter = 1), data will not be sent out the DO Buffer as long as RTS (pin 16) is de-asserted. Two cases in which the DO Buffer may become full and possibly overflow: If the RF data rate is set higher than the interface data rate of the module, the module will receive data from the transmitting module faster than it can send the data to the host. If the host does not allow the module to transmit data out from the DO buffer because of being held off by hardware or software flow control.

6.6

I/O Data Format


I/O data begins with a header. The first byte of the header defines the number of

samples forthcoming. A sample is comprised of input data and the inputs can contain either DIO or ADC. The last 2 bytes of the header (Channel Indicator) define which inputs are active. Each bit represents either a DIO line or ADC channel.

Fig: 6.5 Header of I/O Data Format

Sample data follows the header and the channel indicator frame is used to determine how to read the sample data. If any of the DIO lines are enabled, the first 2 bytes are the DIO data and the ADC data follows. ADC channel data is stored as an unsigned 10-bit value right-justified on a 16-bit boundary. Sample Data

Fig: 6.6 Sample Data of I/O Data Format

6.7 Networks:
The following IEEE 802.15.4 network types are supported by the Zigbee RF modules: NonBeacon NonBeacon (w/ Coordinator) The following terms will be used to explicate the network operations: Table 6.6: Terms and definitions:

Term PAN

Definition Personal Area Network - A data communication network

that includes one or more End Devices and optionally a Coordinator Coordinator. A Full-function device (FFD) that provides network synchronization by polling nodes [NonBeacon (w/ End Device Coordinator) networks only] When in the same network as a Coordinator - RF modules that rely on a Coordinator for synchronization and can be Association put into states of sleep for low-power applications. The establishment of membership between End Devices and a Coordinator. Association is only applicable in NonBeacon (w/Coordinator) networks.
6.7.1NonBeacon: By default, XBee/XBee-PRO RF Modules are configured to support NonBeacon communications. NonBeacon systems operate within a Peer-to-Peer network topology and therefore are not depen-dent upon Master/Slave relationships. This means that modules remain synchronized without use of master/server configurations and each module in the network shares both roles of master and slave. MaxStream's peer-to-peer architecture features fast synchronization times and fast cold start times. This default configuration accommodates a wide range of RF data applications. A peer-to-peer network can be established by configuring each module to operate as an End Device (CE = 0), disabling End Device Association on all modules (A1 = 0) and setting ID and CH parameters to be identical across the network.

Figure 6.7: NonBeacon Peer-to-Peer Architecture 6.7.2 NonBeacon (w/ Coordinator): A device is configured as a Coordinator by setting the CE (Coordinator Enable) parameter to 1. Coordinator power-up is governed by the A2 (Coordinator Association) parameter. In a NonBeacon (w/ Coordinator) system, the Coordinator can be configured to use direct or indi-rect transmissions. If the SP (Cyclic Sleep Period) parameter is set to 0, the Coordinator will send data immediately. Otherwise, the SP parameter determines the length of time the Coordinator will retain the data before discarding it. Generally, SP (Cyclic Sleep Period) and ST (Time before Sleep) parameters should be set to match the SP and ST settings of the End Devices. 6.7.3 Association: Association is the establishment of membership between End Devices and a Coordinator and is only applicable in NonBeacon (w/ Coordinator) networks. The establishment of membership is useful in scenarios that require a central unit (Coordinator) to relay messages to or gather data from several remote units (End Devices), assign channels or assign PAN IDs. An RF data network that consists of one Coordinator and one or more End Devices forms a PAN (Personal Area Network). Each device in a PAN has a PAN Identifier [ID (PAN ID) parameter]. PAN IDs must be unique to prevent miscommunication between PANs. The Coordinator PAN ID is set using the ID (PAN ID) and A2 (Coordinator Association) commands. An End Device can associate to a Coordinator without knowing the address, PAN ID or channel of the Coordinator. The A1 (End Device Association) parameter bit fields determine the flexibility of an End Device during association. The A1 parameter can be used for an End Device to dynamically set its destination address, PAN ID and/or channel. Coordinator / End Device Setup and Operation

To configure a module to operate as a Coordinator, set the CE (Coordinator Enable) parameter to 1. Set the CE parameter of End Devices to 0 (default). Coordinator and End Devices should con-tain matching firmware versions. NonBeacon (w/ Coordinator) Systems In a NonBeacon (w/ Coordinator) system, the Coordinator can be configured to use direct or indirect transmissions. If the SP (Cyclic Sleep Period) parameter is set to 0, the Coordinator will send data immediately. Otherwise, the SP parameter determines the length of time the Coordinator will retain the data before discarding it. Generally, SP (Cyclic Sleep Period) and ST (Time before Sleep) parameters should be set to match the SP and ST settings of the End Devices. Coordinator Power-up Coordinator power-up is governed by the A2 (Coordinator Association) command. On power-up, the Coordinator undergoes the following sequence of events: 1. Check A2 parameter- Reassign_PANID Flag: Set (bit 0 = 1) - The Coordinator issues an Active Scan. The Active Scan selects one channel and transmits a Beacon Request command to the broadcast address (0xFFFF) and broadcast PAN ID (0xFFFF). It then listens on that channel for beacons from any Coordinator operating on that channel. The listen time on each channel is determined by the SD (Scan Duration) parameter value. Once the time expires on that channel, the Active Scan selects another channel and again transmits the BeaconRequest as before. This process continues until all channels have been scanned, or until 5 PANs have been discovered. When the Active Scan is complete, the results include a list of PAN IDs and Channels that are being used by other PANs. This list is used to assign an unique PAN ID to the new Coordinator. The ID parameter will be retained if it is not found in the Active Scan results. Otherwise, the ID (PAN ID) parameter setting will be updated to a PAN ID that was not detected. Not Set (bit 0 = 0) - The Coordinator retains its ID setting. No Active Scan is performed. For example: If the PAN ID of a Coordinator is known, but the operating channel is not; the A1 command on the End Device should be set to enable the Auto_Associate and

Reassign Channel bits. Additionally, the ID parameter should be set to match the PAN ID of the associated Coordinator. 2. Check A2 parameter - Reassign Channel Flag (bit 1) Set (bit 1 = 1) - The Coordinator issues an Energy Scan. The Energy Scan selects one channel and scans for energy on that channel. The duration of the scan is specified by the SD (Scan Duration) parameter. Once the scan is completed on a channel, the Energy Scan selects the next channel and begins a new scan on that channel. This process continues until all channels have been scanned. When the Energy Scan is complete, the results include the maximal energy values detected on each channel. This list is used to determine a channel where the least energy was detected. If an Active Scan was performed (Reassign_PANID Flag set), the channels used by the detected PANs are eliminated as possible channels. Thus, the results of the Energy Scan and the Active Scan (if performed) are used to find the best channel (channel with the least energy that is not used by any detected PAN). Once the best channel has been selected, the CH (Channel) param-eter value is updated to that channel. Not Set (bit 1 = 0) - The Coordinator retains its CH setting. An Energy Scan is not performed. 3. Start Coordinator The Coordinator starts on the specified channel (CH parameter) and PAN ID (ID parameter). Note, these may be selected in steps 1 and/or 2 above. The Coordinator will only allow End Devices to associate to it if the A2 parameter Allow Association flag is set. Once the Coordinator has successfully started, the Associate LED will blink 1 time per second. (The LED is solid if the Coordinator has not started.)

4. Coordinator Modifications Once a Coordinator has started: Modifying the A2 (Reassign_Channel or Reassign_PANID bits), ID, CH or MY parameters will cause the Coordinators MAC to reset (The Coordinator RF module (including volatile RAM) is not reset). Changing the A2 AllowAssociation bit will not

reset the Coordinators MAC. In a non-beaconing system, End Devices that associated to the Coordinator prior to a MAC reset will have knowledge of the new settings on the Coordinator. Thus, if the Coordinator were to change its ID, CH or MY settings, the End Devices would no longer be able to communicate with the non-beacon Coordinator. Once a Coordinator has started, the ID, CH, MY or A2 (Reassign_Channel or Reassign_PANID bits) should not be changed. End Device Power-up End Device power-up is governed by the A1 (End Device Association) command. On power-up, the End Device undergoes the following sequence of events: 1. Check A1 parameter - AutoAssociate Bit Set (bit 2 = 1) - End Device will attempt to associate to a Coordinator. Not Set (bit 2 = 0) - End Device will not attempt to associate to a Coordinator. The End Device will operate as specified by its ID, CH and MY parameters. Association is considered complete and the Associate LED will blink quickly (5 times per second). When the AutoAssociate bit is not set, the remaining steps (2-3) do not apply. 2. Discover Coordinator (if Auto-Associate Bit Set) The End Device issues an Active Scan. The Active Scan selects one channel and transmits a BeaconRequest command to the broadcast address (0xFFFF) and broadcast PAN ID (0xFFFF). It then listens on that channel for beacons from any Coordinator operating on that channel. The listen time on each channel is determined by the SD parameter. Once the time expires on that channel, the Active Scan selects another channel and again transmits the BeaconRequest command as before. This process continues until all channels have been scanned, or until 5 PANs have been discovered. When the Active Scan is complete, the results include a list of PAN IDs and Channels that are being used by detected PANs. The End Device selects a Coordinator to associate with according to the A1 parameter Reassign_PANID and Reassign_Channel flags: Reassign_PANID Bit Set (bit 0 = 1)- End Device can associate with a PAN with any ID value.

Reassign_PANID Bit Not Set (bit 0 = 0) - End Device will only associate with a PAN whose ID setting matches the ID setting of the End Device. Reassign_Channel Bit Set (bit 1 = 1) - End Device can associate with a PAN with any CH value. Reassign_Channel Bit Not Set (bit 1 = 0) - End Device will only associate with a PAN whose CH setting matches the CH setting of the End Device. After applying these filters to the discovered Coordinators, if multiple candidate PANs exist, the End Device will select the PAN whose transmission link quality is the strongest. If no valid Coordinator is found, the End Device will either go to sleep (as dictated by its SM (Sleep Mode) parameter) or retry Association. Note - An End Device will also disqualify Coordinators if they are not allowing association (A2 - AllowAssociation bit); or, if the Coordinator is not using the same NonBeacon scheme as the End Device. (They must both be programmed with NonBeacon code.) 3. Associate to Valid Coordinator Once a valid Coordinator is found (step 2), the End Device sends an Association Request message to the Coordinator. It then waits for an Association Confirmation to be sent from the Coordinator. Once the Confirmation is received, the End Device is Associated and the Associate LED will blink rapidly (2 times per second). The LED is solid if the End Device has not associated. 4. End Device Changes once an End Device has associated Changing A1, ID or CH parameters will cause the End Device to disassociate and restart the Association procedure. If the End Device fails to associate, the AI command can give some indication of the failure. 6.8 Zigbee Addressing: Every RF data packet sent over-the-air contains a Source Address and Destination Address field in its header. The RF module conforms to the 802.15.4 specification and supports both short 16-bit addresses and long 64-bit addresses. A unique 64-bit IEEE source address is assigned at the factory and can be read with the SL (Serial Number

Low) and SH (Serial Number High) commands. Short addressing must be configured manually. A module will use its unique 64-bit address as its Source Address if its MY (16-bit Source Address) value is 0xFFFF or 0xFFFE. To send a packet to a specific module using 64-bit addressing: Set Destination Address (DL + DH) to match the Source Address (SL + SH) of the intended destination module. To send a packet to a specific module using 16-bit addressing: Set DL (Destination Address Low) parameter to equal the MY parameter and set the DH (Destination Address High) parameter to 0.
6.8.1 Unicast Mode

By default, the RF module operates in Unicast Mode. Unicast Mode is the only mode that supports retries. While in this mode, receiving modules send an ACK (acknowledgement) of RF packet reception to the transmitter. If the transmitting module does not receive the ACK, it will re-send the packet up to three times or until the ACK is received. Short 16-bit addresses. The module can be configured to use short 16-bit addresses as the Source Address by setting (MY < 0xFFFE). Setting the DH parameter (DH = 0) will configure the Destination Address to be a short 16-bit address (if DL < 0xFFFE). For two modules to communicate using short addressing, the Destination Address of the transmitter module must match the MY parameter of the receiver. The following table shows a sample network configuration that would enable Unicast Mode communications using short 16bit addresses. Table 6.7: Unicast Network Configuration (using 16-bit addressing)

Parameter MY(source address) DH(Destination High) DL(Destination Low)


Long 64-bit addresses:

RF Module 1 0x01 0 0x02

RF Module 2 0x02 0 0x01

The RF modules serial number (SL parameter concatenated to the SH parameter) can be used as a 64-bit source address when the MY (16-bit Source Address) parame-ter is disabled. When the MY parameter is disabled (set MY = 0xFFFF or

0xFFFE), the modules source address is set to the 64-bit IEEE address stored in the SH and SL parameters. When an End Device associates to a Coordinator, its MY parameter is set to 0xFFFE to enable 64- bit addressing. The 64-bit address of the module is stored as SH and SL parameters. To send a packet to a specific module, the Destination Address (DL + DH) on one module must match the Source Address (SL + SH) of the other.
6.8.2 Broadcast Mode:

Any RF module within range will accept a packet that contains a broadcast address. When configured to operate in Broadcast Mode, receiving modules do not send ACKs (Acknowledgements) and transmitting modules do not automatically re-send packets as is the case in Unicast Mode. To send a broadcast packet to all modules regardless of 16-bit or 64-bit addressing, set the destination addresses of all the modules as shown below. Sample Network Configuration (All modules in the network): DL (Destination Low Address) = 0x0000FFFF DH (Destination High Address) = 0x00000000 (default value)

6.8Modes of Operation
The Transceiver operates in five modes .They are 1. Idle Mode 2. Receive mode 3. Transmit Mode 4. Sleep Mode 5. Command Mode

Fig: 6.7 Different Modes of Operation The operation of Transceiver in each mode is explained below

1. Idle mode
When not receiving or transmitting data, the RF module is in Idle Mode. The module shifts into the other modes of operation under the following conditions: Transmit Mode (Serial data is received in the DI Buffer) Receive Mode (Valid RF data is received through the antenna) Sleep Mode (Sleep Mode condition is met) Command Mode (Command Mode Sequence is issued)

Transmit Mode
RF data packets:

When not receiving or transmitting data, the RF module is in Idle Mode. The module shifts into the each transmitted data packet contains a Source Address and Destination Address field. The Source Address matches the address of the transmitting module as specified by the MY (Source Address) parameter (if MY >= 0xFFFE), the SH (Serial Number High) parameter or the SL (Serial Number Low) parameter. The <Destination Address> field is created from the DH (Destination Address High) and DL (Destination Address Low) parameter values. The Source Address and/or Destination Address fields will either contain a 16-bit short or long 64-bit long address. There are two methods to transmit data. They are 1. Direct Transmission If the source address matches the destination address then Data is transmitted immediately to the Destination Address. A NonBeaconing Coordinator can be configured to use only Direct Transmission by setting the SP (Cyclic Sleep Period) parameter to 0. Also, a NonBeaconing Coordinator using indirect transmissions will revert to direct transmission if it knows the destination module is awake. To enable this behavior, the ST (Time before Sleep) value of the Coordinator must be set to match the ST value of the End Device. Once the End Device either transmits data to the Coordinator or polls the Coordinator for data, the Coordinator will use direct transmission for all subsequent data transmissions to that module address until ST time (or number of beacons) occurs with no activity (at which point it will revert to using indirect transmissions for that module address). No activity means no transmission or reception of messages with a specific address. Global messages will not reset the ST timer. 2. Indirect Transmission A packet is retained for a period of time and is only transmitted after the destination module (Source Address = Destination Address) requests the data. To configure Indirect Transmissions in a PAN (Personal Area Network), the SP (Cyclic Sleep Period) parameter value on the Coordinator must be set to match the longest sleep value of any End Device. The SP parameter represents time in NonBeacon systems and

beacons in Beacon-enabled systems. The sleep period value on the Coordinator determines how long (time or number of beacons) the Coordinator will retain an indirect message before discarding it. In NonBeacon networks, an End Device must poll the Coordinator once it wakes from Sleep to determine if the Coordinator has an indirect message for it. For Cyclic Sleep Modes, this is done automatically every time the module wakes (after SP time). For Pin Sleep Modes, the A1 (End Device Association) parameter value must be set to enable Coordinator polling on pin wake-up. Alternatively, an End Device can use the FP (Force Poll) command to poll the Coordinator as needed. Indirect Transmissions can only occur on a Coordinator. Thus, if all nodes in a network are End Devices, only Direct Transmissions will occur. Indirect Transmissions are useful to ensure packet delivery to a sleeping node. The Coordinator currently is able to retain up to 2 indirect messages.

CCA (Clear Channel Assessment)


Prior to transmitting a packet, a CCA (Clear Channel Assessment) is performed on the channel to determine if the channel is available for transmission. The detected energy on the channel is compared with the CA (Clear Channel Assessment) parameter value. If the detected energy exceeds the CA parameter value, the packet is not transmitted. Also, a delay is inserted before a transmission takes place. This delay is settable using the RN (Back off Exponent) parameter. If RN is set to 0, then there is no delay before the first CCA is performed. The RN parameter value is the equivalent of the minBE parameter in the 802.15.4 specification. The transmit sequence follows the 802.15.4 specification. By default, the MM (MAC Mode) parameter = 0. On a CCA failure, the module will attempt to resend the packet up to two additional times. When in Unicast packets with RR (Retries) = 0, the module will execute two CCA retires. Broadcast packets always get two CCA retires.

Acknowledgement
If the transmission is not a broadcast message, the module will expect to receive an acknowledgement from the destination node. If an acknowledgement is not received,

the packet will be resent up to 3 more times. If the acknowledgement is not received after all transmissions, an ACK failure is recorded.

Sleep Mode
Sleep Modes enable the RF module to enter states of low-power consumption when not in use. In order to enter Sleep Mode, one of the following conditions must be met (in addition to the module having a non-zero SM parameter value): Sleep_RQ (pin 9) is asserted. The module is idle (no data transmission or reception) for the amount of time defined by the ST (Time before Sleep) parameter. (ST is only active when SM = 4-5). The SM command is central to setting Sleep Mode configurations. By default, Sleep Modes are disabled (SM = 0) and the module remains in Idle/Receive Mode. When in this state, the module is constantly ready to respond to serial or RF activity.

Higher Voltages
Sleep Mode current consumption is highly sensitive to voltage. Voltages above 3.0V will cause much higher current consumption.

Command mode
To modify or read RF Module parameters, the module must first enter into Command Mode a state in which incoming characters are interpreted as commands. Two Command Mode options are supported: AT Command Mode and API Command Mode.

6.8 AT Command Mode


To Enter AT Command Mode:

Send the 3-character command sequence +++ and observe guard times before and after the command characters. AT Command Mode Sequence (for transition to Command Mode): No characters sent for one second [GT (Guard Times) parameter = 0x3E8]. Input three plus characters (+++) within one second [CC (Command Sequence Character) Parameter = 0x2B]. No characters sent for one second [GT (Guard Times) parameter = 0x3E8]. All of the parameter values in the sequence can be modified to reflect user preferences.

To Send AT Commands:

Fig: 6.8 Syntax for sending AT Commands The preceding example would change the RF module Destination Address (Low) to 0x1F. To store the new value to non-volatile (long term) memory, subsequently send the WR (Write) command. For modified parameter values to persist in the modules registry after a reset, changes must be saved to non-volatile memory using the WR (Write) Command. Otherwise, parameters are restored to previously saved values after the module is reset.

System Response
When a command is sent to the module, the module will parse and execute the command. Upon successful execution of a command, the module returns an OK

message. If execution of a command results in an error, the module returns an ERROR message.

To Exit AT Command Mode:


1. Send the ATCN (Exit Command Mode) command (followed by a carriage return). 2. If no valid AT Commands are received within the time specified by CT (Command Mode Timeout) Command, the RF module automatically returns to Idle Mode.

6.8.1 AT Commands Description:


SH (Serial Number High) Command The SH command is used to read the high 32 bits of the RF module's unique IEEE 64-bit address. The module serial number is set at the factory and is read-only. AT Command: ATSH Parameter Range: 0 - 0xFFFFFFFF [read-only] Related Commands: SL (Serial Number Low), MY (Source Address). SL (Serial Number Low) Command The SL command is used to read the low 32 bits of the RF module's unique IEEE 64-bit address. The module serial number is set at the factory and is read-only. AT Command: ATSL Parameter Range: 0 - 0xFFFFFFFF [read-only] Related Commands: SH (Serial Number High), MY (Source Address) DH (Destination Address High) Command The DH command issued to set and read the upper 32 bits of the RF module's 64bit destination address. When combined with the DL (Destination Address Low) parameter, it defines the destination address used for transmission.

A module will only communicate with other modules having the same channel (CH parameter); PAN ID (ID parameter) and destination address (DH + DL parameters). To transmit using a 16-bit address, set the DH parameter to zero and the DL parameter less than 0xFFFF. 0x000000000000FFFF (DL concatenated to DH) is the broadcast address for the PAN. AT Command: ATDH Parameter Range: 0 - 0xFFFFFFFF Default Parameter Value: 0 Related Commands: DL (Destination Address Low), CH (Channel), ID (PAN VID) DL (Destination Address Low) Command The DL command is used to set and read the lower 32 bits of the RF module's 64bit destination address. When combined with the DH (Destination Address High) parameter, it defines the destination address used for transmission. A module will only communicate with other modules having the same channel (CH parameter), PAN ID (ID parameter) and destination address (DH + DL parameters). To transmit using a 16-bit address, set the DH parameter to zero and the DL parameter less than 0xFFFF. 0x000000000000FFFF (DL concatenated to DH) is the broadcast address for the PAN. AT Command: ATDL Parameter Range: 0 - 0xFFFFFFFF Default Parameter Value: 0 Related Commands: DH (Destination Address High), CH (Channel), ID (PAN VID)

DN (Destination Node) Command The DN command is used to resolve a NI (Node Identifier) string to a physical address. The following events occur upon successful command execution:

1. DL and DH are set to the address of the module with the matching NI (Node Identifier). 2. OK is returned. 3. RF module automatically exits AT Command Mode. If there is no response from a modem within 200 msec or a parameter is not specified (left blank), the command is terminated and an ERROR message is returned. AT Command: ATDN Parameter Range: 20-character ASCII String Minimum Firmware Version Required: v1.x80 BD (Interface Data Rate) Command The BD command is used to set and read the serial interface data rate used between the RF module and host. This parameter determines the rate at which serial data is sent to the module from the host. Modified interface data rates do not take effect until the CN (Exit AT Command Mode) command is issued and the system returns the 'OK' response. When parameters 0-7 are sent to the module, the respective interface data rates are used. The RF data rate is not affected by the BD parameter. If the interface data rate is set higher than the RF data rate, a flow control configuration may need to be implemented. AT Command: ATBD Parameter Range: 0 - 7 (standard rates) 0x80-0x1C200 (non-standard rates)

Table: 6.6 Setting Different Baud Rate Parameter 0 1 Configuration (bps) 1200 2400

2 3 4 5 6 7 Default Parameter Value: 3 CE (Coordinator Enable) Command

4800 9600 19200 38400 57600 115200

The CE command is used to set and read the behavior (End Device vs. Coordinator) of the RF module. AT Command: ATCE Parameter Range: 0 1 Table: 6.7 Configuring the RF Module Parameter 0 1 Default Parameter Value: 0 Minimum Firmware Version Required: v1.x80 Configuration End device Coordinator

CH (Channel) Command The CH command is used to set/read the operating channel on which RF connections are made between RF modules. The channel is one of three addressing options available to the module. The other options are the PAN ID (ID command) and destination addresses (DL & DH commands). In order for modules to communicate with each other, the modules must share the same channel number. Different channels can be used to prevent modules in one network from listening to transmissions of another. Adjacent channel rejection is 23 dB. The module uses channel numbers of the 802.15.4 standard. Center Frequency = 2.405 + (CH - 11d) * 5 MHz (d = decimal)

AT Command: ATCH Parameter Range: 0x0B - 0x1A (XBee) 0x0C - 0x17 (XBee-PRO) Default Parameter Value: 0x0C (12 decimal) Related Commands: ID (PAN ID), DL (Destination Address Low, DH (Destination Address High) ID (Pan ID) Command The ID command is used to set and read the PAN (Personal Area Network) ID of the RF module. Only modules with matching PAN IDs can communicate with each other. Unique PAN IDs enable control of which RF packets are received by a module. Setting the ID parameter to 0xFFFF indicates a global transmission for all PANs. It does not indicate a global receives. AT Command: ATID Parameter Range: 0 - 0xFFFF Default Parameter Value: 0x3332 (13106 decimal) MY (16-bit Source Address) Command The MY command is used to set and read the 16-bit source address of the RF module. By setting MY to 0xFFFF, the reception of RF packets having a 16-bit address is disabled. The 64-bit address is the modules serial number and is always enabled. AT Command: ATMY Parameter Range: 0 - 0xFFFF Default Parameter Value: 0 Related Commands: DH (Destination Address High), DL (Destination Address Low), CH (Channel), ID (PAN ID) NI (Node Identifier) Command

The NI command is used to set and read a string for identifying a particular node. Rules: Register only accepts printable ASCII data. A string cannot start with a space. A carriage return ends command Command will automatically end when maximum bytes for the string have been entered. This string is returned as part of the ND (Node Discover) command. This identifier is also used with the DN (Destination Node) command. AT Command: ATNI Parameter Range: 20-character ASCII string Related Commands: ND (Node Discover), DN (Destination Node) Minimum Firmware Version Required: v1.x80 WR (Write) Command The WR command is used to write configurable parameters to the RF module's nonvolatile memory. Parameter values remain in the module's memory until overwritten by subsequent use of the WR Command. If changes are made without writing them to non-volatile memory, the module reverts back to previously saved parameters the next time the module is powered-on. AT Command: ATWR

VR (Firmware Version) Command The VR command is used to read which firmware version is stored in the module. XBee version numbers will have four significant digits. The reported number will show three or four numbers and is stated in hexadecimal notation. A version can be reported as "ABC" or "ABCD". Digits ABC are the main release number and D is the revision

number from the main release. "D" is not required and if it is not present, a zero is assumed for D. "B" is a variant designator. The following variants exist: "0" = Non-Beacon Enabled 802.15.4 Code "1" = Beacon Enabled 802.15.4 Code AT Command: ATVR Parameter Range: 0 - 0xFFFF [read only] AP (API Enable) Command The AP command is used to enable the RF module to operate using a frame based API instead of using the default Transparent (UART) mode. AT Command: ATAP Parameter Range: 0 2 Table: 6.8 Enabling AP Command Parameter 0 1 2 Default Parameter Value: 0 Minimum Firmware Version Required: v1.x80 EA (ACK Failures) Command The EA command is used to reset and read the count of ACK (acknowledgement) failures. This parameter value increment when the module expires its transmission retries without receiving an ACK on a packet transmission. This count saturates at its maximum value. Set the parameter to 0 to reset count. AT Command: ATEA Parameter Range: 0 - 0xFFFF Configuration Disabled (transparent operation ) API enabled API enabled(with escaped characters)

Minimum Firmware Version Required: v1.x80 EC (CCA Failures) Command The EC command is used to read and reset the count of CCA (Clear Channel Assessment) failures. These parameter value increments when the RF module does not transmit a packet due to the detection of energy that is above the CCA threshold level (set with CA command). This count saturates at its maximum value. Set the EC parameter to 0 to reset count. AT Command: ATEC Parameter Range: 0 - 0xFFFF Related Command: CA (CCA Threshold) Minimum Firmware Version Required: v1.x80 EE (AES Encryption Enable) Command The EE command is used to set/read the parameter that disables/enables 128-bit AES encryption. The XBee/XBee-PRO firmware uses the 802.15.4 Default Security protocol and uses AES encryption with a 128-bit key. AES encryption dictates that all modules in the network use the same key and the maximum RF packet size is 95 Bytes. When encryption is enabled, the module will always use its 64-bit long address as the source address for RF packets. This does not affect how the MY (Source Address), DH (Destination Address High) and DL (Destination Address Low) parameters work. AT Command: ATEE Parameter Range: 0 - 1 Default Parameter Value: 0 Related Commands: KY (Encryption Key), AP (API Enable), MM (MAC Mode) Minimum Firmware Version Required: v1.xA0 VL (Firmware Version - Verbose)

The VL command is used to read detailed version information about the RF module. The information includes: Application builds date; MAC, PHY and boot loader versions; and builds dates. AT Command: ATVL Parameter Range: 0 - 0xFF Default Parameter Value: 0x28 (40 decimal) Minimum Firmware Version Required: v1.x80 ND (Node Discover) Command The ND command is used to discover and report all modules on its current operating channel (CH parameter) and PAN ID (ID parameter). ND also accepts an NI (Node Identifier) value as a parameter. In this case, only a module matching the supplied identifier will respond. ND uses a 64-bit long address when sending and responding to an ND request. The ND command causes a module to transmit a globally addressed ND command packet. The amount of time allowed for responses is determined by the NT (Node Discover Time) parameter. AT Command: ATND Range: optional 20-character NI value Related Commands: CH (Channel), ID (Pan ID), MY (Source Address), SH (Serial Number High), SL (Serial Number Low), NI (Node Identifier), NT (Node Discover Time) Minimum Firmware Version Required: v1.x80 AC (Apply Changes) Command The AC command is used to explicitly apply changes to module parameter values. Applying changes means that the module is re-initialized based on changes made to its

parameter values. Once changes are applied, the module immediately operates according to the new parameter values. This behavior is in contrast to issuing the WR (Write) command. The WR command saves parameter values to non-volatile memory, but the module still operates according to previously saved values until the module is re-booted or the CN (Exit AT Command Mode) command is issued. AT Command: ATAC Minimum Firmware Version Required: v1.xA0 RE (Restore Defaults) Command The RE command is used to restore all configurable parameters to their factory default settings. The RE command does not write restored values to non-volatile (persistent) memory. Issue the WR (Write) command subsequent to issuing the RE command to save restored parameter values to non-volatile memory. AT Command: ATRE V (Hardware Version) Command The HV command is used to read the hardware version of the RF module. AT Command: ATHV Parameter Range: 0 - 0xFFFF [Read-only] Minimum Firmware Version Required: v1.x80 CN (Exit Command Mode) Command The CN command is used to explicitly exit the RF module from AT Command Mode. AT Command: ATCN

6.7.6 RELAY

A relay is an electrically controllable switch widely used in industrial controls, automobiles and appliances. The relay allows the isolation of two separate sections of a system with two different voltage sources i.e., a small amount of voltage/current on one side can handle a large amount of voltage/current on the other side but there is no chance that these two voltages mix up.

Inductor

Fig: Circuit symbol of a relay

. Each relay has two mechanical parts inside. The first one is the contact(s) of the relay. The contacts operates similarly to the contacts of a simple switch or pushbutton. You should consider the contacts as a pair of metals like the following diagram:

T he two terminals operates as a switch. When the contacts are 'in contact' then the current flows from Terminal 1 to Terminal 2. There are two types of contacts: the NO and the NC. NO stands for Normal Open contact, while NC stands for Normal Closed contact. The Normal Open is a contact like the one showed in the previous illustration. When the contact is still, then no current flows through it (because it is an OPEN circuit). On the other hand, a Normal Closed contact allows the current to flow when the contact is still . shows below

contacts:

Operation: When current flows through the coil, a magnetic field is created around the coil i.e., the coil is energized. This causes the armature to be attracted to the coil. The armatures contact acts like a switch and closes or opens the circuit. When the coil is not energized, a spring pulls the armature to its normal state of open or closed. There are all types of relays for all kinds of applications.

Fig: Relay Operation and use of protection diodes

Transistors and ICs must be protected from the brief high voltage 'spike' produced when the relay coil is switched off. The above diagram shows how a signal diode (eg 1N4148) is connected across the relay coil to provide this protection. The diode is connected 'backwards' so that it will normally not conduct. Conduction occurs only when the relay coil is switched off, at this moment the current tries to flow continuously through the coil and it is safely diverted through the diode. Without the diode no current could flow and the coil would produce a damaging high voltage 'spike' in its attempt to keep the current flowing. In choosing a relay, the following characteristics need to be considered: 1. The contacts can be normally open (NO) or normally closed (NC). In the NC type, the contacts are closed when the coil is not energized. In the NO type, the contacts are closed when the coil is energized. 2. There can be one or more contacts. i.e., different types like SPST (single pole single throw), SPDT (single pole double throw) and DPDT (double pole double throw) relays. 3. The voltage and current required to energize the coil. The voltage can vary from a few volts to 50 volts, while the current can be from a few milliamps to 20milliamps. The relay has a minimum voltage, below which the coil will not be energized. This minimum voltage is called the pull-in voltage. 4. The minimum DC/AC voltage and current that can be handled by the contacts. This is in the range of a few volts to hundreds of volts, while the current can be from a few amps to 40A or more, depending on the relay.

6.7.7 Pin Diagram:

6.7.8 Pin Description:

Pin No 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

Function Input for 1st channel Input for 2nd channel Input for 3rd channel Input for 4th channel Input for 5th channel Input for 6th channel Input for 7th channel Ground (0V) Common free wheeling diodes Output for 7th channel Output for 6th channel Output for 5th channel Output for 4th channel Output for 3rd channel Output for 2nd channel Output for 1st channel

Name Input 1 Input 2 Input 3 Input 4 Input 5 Input 6 Input 7 Ground Common Output 7 Output 6 Output 5 Output 4 Output 3 Output 2 Output 1

DESCRIPTION The ULN2003 is a monolithic high voltage and high current Darlington transistor arrays. It consists of seven NPN darlington pairs that features high-voltage outputs with common-cathode clamp diode for switching inductive loads. The collector-current rating of a single darlington pair is 500mA. The darlington pairs may be parrlleled for higher current capability. Applications includerelay drivers,hammer drivers, lampdrivers,display drivers(LED gas discharge),line drivers, and logic buffers.The ULN2003 has a 2.7kW series base resistor for eachdarlington pair for operation directly with TTL or 5V CMOS devices. FEATURES * 500mA rated collector current(Single output) * High-voltage outputs: 50V * Inputs compatibale with various types of logic. * Relay driver application

CHAPTER 7 Project Schematic

CHAPTER-8
8.SOFT WARE TOOLS

8.1.1 Firmware Implementation of the project design This chapter briefly explains about the firmware implementation of the project. The required software tools are discussed in section 4.2. Section 4.3 shows the flow diagram of the project design. Section 4.4 presents the firmware implementation of the project design. 8.1.2 Software Tools Required Keil v3, Proteus are the two software tools used to program microcontroller. The working of each software tool is explained below in detail.

8.1.3 Programming Microcontroller A compiler for a high level language helps to reduce production time. To program the AT89S52 microcontroller the Keil v3 is used. The programming is done strictly in the embedded C language. Keil v3 is a suite of executable, open source software development tools for the microcontrollers hosted on the Windows platform. The compilation of the C program converts it into machine language file (.hex). This is the only language the microcontroller will understand, because it contains the original program code converted into a hexadecimal format. During this step there are some warnings about eventual errors in the program. This is shown in Fig 4.1. If there are no errors and warnings then run the program, the system performs all the required tasks and behaves as expected the software developed. If not, the whole procedure will have to be repeated again. Fig 4.2 shows expected outputs for given inputs when run compiled program. One of the difficulties of programming microcontrollers is the limited amount of resources the programmer has to deal with. In personal computers resources such as RAM and processing speed are basically limitless when compared to microcontrollers. In contrast, the code on microcontrollers should be as low on resources as possible.

8.2 Keil Compiler: Keil compiler is software used where the machine language code is written and compiled. After compilation, the machine source code is converted into hex code which is to be dumped into the microcontroller for further processing. Keil compiler also supports C language code.

Fig 4.1: Compilation of source Code

8.3 Proteus: Proteus is software which accepts only hex files. Once the machine code is converted into hex code, that hex code has to be dumped into the microcontroller and this is done by the Proteus . Proteus is a programmer which itself contains a microcontroller

in it other than the one which is to be programmed. This microcontroller has a program in it written in such a way that it accepts the hex file from the Keil compiler and dumps this hex file into the microcontroller which is to be programmed. As the Proteus programmer kit requires power supply to be operated, this power supply is given from the power supply circuit designed above. It should be noted that this programmer kit contains a power supply section in the board itself but in order to switch on that power supply, a source is required. Thus this is accomplished from the power supply board with an output of 12volts.

Features

Supports major Atmel 89 series devices Auto Identify connected hardware and devices Error checking and verification in-built Lock of programs in chip supported to prevent program copying 20 and 40 pin ZIF socket on-board Auto Erase before writing and Auto Verify after writing Informative status bar and access to latest programmed file Simple and Easy to use Works on 57600 speed

Description It is simple to use and low cost, yet powerful flash microcontroller programmer for the Atmel 89 series. It will Program, Read and Verify Code Data, Write Lock Bits, Erase and Blank Check. All fuse and lock bits are programmable. This programmer has intelligent onboard firmware and connects to the serial port. It can be used with any type of computer and requires no special hardware. All that is needed is a serial communication ports which all computers have.

All devices have signature bytes that the programmer reads to automatically identify the chip. No need to select the device type, just plug it in and go! All devices also have a number of lock bits to provide various levels of software and programming protection. These lock bits are fully programmable using this programmer. Lock bits are useful to protect the program to be read back from microcontroller only allowing erase to reprogram the microcontroller. The programmer connects to a host computer using a standard RS232 serial port. All the programming 'intelligence' is built into the programmer so you do not need any special hardware to run it. Programmer comes with window based software for easy programming of the devices.

Programming Software Computer side software called 'Proload V4.1' is executed that accepts the Intel HEX format file generated from compiler to be sent to target microcontroller. It auto detects

the hardware connected to the serial port. It also auto detects the chip inserted and bytes used. Software is developed in Delphi 7 and requires no overhead of any external DLL.

Fig 4.4: Writing the programs bytes onto the microcontroller

About Keil

1. 2.

Click on the Keil u Vision Icon on Desktop The following fig will appear

3. 4.

Click on the Project menu from the title bar Then Click on New Project

5.

Save the Project by typing suitable project name with no extension in u r own folder sited in either C:\ or D:\

6. 7. 8.

Then Click on Save button above. Select the component for u r project. i.e. Atmel Click on the + Symbol beside of Atmel

9.

Select AT89C51 as shown below

10. 11.

Then Click on OK The Following fig will appear

12.

Then Click either YES or NOmostly NO

13. 14.

Now your project is ready to USE Now double click on the Target1, you would get another option Source group 1 as shown in next page.

15.

Click on the file option from menu bar and select new

16.

The next screen will be as shown in next page, and just maximize it by double clicking on its blue boarder.

17. 18.

Now start writing program in either in C or ASM For a program written in Assembly, then save it with extension . asm and for C based program save it with extension .C

19.

Now right click on Source group 1 and click on Add files to Group Source

20.

Now you will get another window, on which by default C files will appear.

21. 22. 23.

Now select as per your file extension given while saving the file Click only one time on option ADD Now Press function key F7 to compile. Any error will appear if so happen.

24. 25.

If the file contains no error, then press Control+F5 simultaneously. The new window is as follows

26.

Then Click OK

27.

Now Click on the Peripherals from menu bar, and check your required port as shown in fig below

28.

Drag the port a side and click in the program file.

29. 30.

Now keep Pressing function key F11 slowly and observe. You are running your program successfully

CHAPTER 10

10. Conclusion
Hence by this project we can design an effective INDUSTRIAL AUTOMATION USING PC that can operate industrial appliances easily and more comfortably, and this project is very useful for physically challenged persons to monitor the industrial appliances.

CHAPTER 12

12. References
The 8051 Micro controller and Embedded Systems -Muhammad Ali Mazidi - Janice Gillispie Mazidi The 8051 Micro controller Architecture, Programming & Applications -Kenneth J.Ayala Fundamentals Of Micro processors and Micro computers -B.Ram Micro processor Architecture, Programming & Applications -Ramesh S. Gaonkar Electronic Components -D.V. Prasad References on the Web: www.national.com www.atmel.com

www.microsoftsearch.com www.geocities.com