You are on page 1of 71

1.

OVERVIEW
1.1 INTRODUCTION ZigBee focuses on defining a general purpose in expensive self-organizing mesh network that can be used for industrial control, embedded sensing, medical data collection, building automation and home automation. Our project mainly deals with home automation, which is linking of appliances, monitoring and controlling them through an intelligent network. This project demonstrates home automation applications by making use of the wireless ZigBee protocol. The XBee OEM RF Modules were engineered to operate within the ZigBee protocol and provide reliable delivery of data between remote devices. 1.2 BLOCK DIAGRAM

ZigBee device can play a role as a master or a slave. Master tries to connect itself to other devices and slave is waiting to be connected from other devices. A ZigBee connection can always be made from pair of master and slave devices. XBee and XBee-Pro are the RF Modules which are used as ZigBee devices in the transmitter and receiver sections. The microcontroller used in this project is Philips 89C51 which belongs to the 8051 family. It takes input from the external sources and roots them to the appropriate devices as programmed in it. The LCD used here is PCD8544 which is a low power CMOS controller/device. It is used to display the name of the appliance which is being currently controlled. Each and every key in the keypad is designed for a particular function. A device can be controlled by pressing the corresponding key. Power Supply Unit is used to provide a constant 5Volts, 1.5A supply to different ICs. This is a standard circuit using external 12V DC adopter and fixed 3-pin voltage regulator.

2. ZIGBEE COMMUNICATIONS
2.1 INTRODUCTION For the last few years, we've witnessed a great expansion of remote control devices. Five years ago, infrared remotes for the television were the only such devices in our homes. Now we quickly run out of fingers as we count the devices and appliances we can control remotely in our house. This number will only increase as more devices are controlled or monitored from a distance. To interact with all these remotely controlled devices, a new and emerging wireless modality, ZigBee was developed. ZigBee style networks began to be designed in 1998 when many engineers realized that both Wi-Fi and Bluetooth were going to be unsuitable for many applications. It is a published specification designed to use small and low power digital radios based on the IEEE 802.15.4 standard for wireless personal area networks (WPANs).

With its unique emphasis on reliability, low cost, long battery life and easy deployment, ZigBee is paving the way for intelligent sensors to provide greater control of lighting, heating, cooling, water and filtration, appliance-use and security systems from anywhere in and around the home. These additional controls play an instrumental role in dramatically improving energy efficiency as the world grapples with increasing power demands that exceed supply, as well as concerns around greenhouse gas emissions.

2.2 WHAT DOES ZIGBEE DO? ZigBee is designed for wireless controls and sensors. It could be built into just about anything you have around your home or office, including lights, switches, doors and appliances. These devices can then interact without wires, and you can control them all from a remote control or even your mobile phone. It allows wireless two-way communications between lights and switches, thermostats and furnaces, hotel-room airconditioners and the front desk, and central command posts. It travels across greater distances and handles many sensors that can be linked to perform different tasks. Figure below gives a great example of how ZigBee can be applied.

ZigBee works well because it aims low. Controls and sensors don't need to send and receive much data. ZigBee has been designed to transmit slowly. It has a data rate of 250kbps (kilobits per second), pitiful compared with Wi-Fi, which is hitting throughput of 20Mbps or more. But because ZigBee transmits slowly, it doesn't need much power, so batteries will last up to 10 years. Because ZigBee consumes very little power, a sensor and transmitter that reports whether a door is open or closed, for example, can run for up to five years on a single double-A battery. Also, operators are much happier about adding ZigBee to their phones than faster technologies such as Wi-Fi; therefore, the phone will be able to act as a remote control for all the ZigBee devices it encounters. 2.3 ZIGBEE PROTOCOL

The ZigBee protocol was engineered by the ZigBee Alliance, a non-profit consortium of leading semiconductor manufacturers, technology providers, OEMs and end-users worldwide. The ZigBee protocol carries all the benefits of the 802.15.4 protocol with added networking functionality. The 802.15.4 specification was developed at the Institute of Electrical and Electronics Engineers (IEEE). The specification is a packet-based radio protocol that meets the needs of low-cost, battery-operated devices. The protocol allows devices to intercommunicate and be powered by batteries that last years instead of hours. 5

ZigBee can be implemented in mesh networks larger than is possible with Bluetooth. ZigBee compliant wireless devices are expected to transmit 10-75 meters, depending on the RF environment and the power output consumption required for a given application, and will operate in the unlicensed RF worldwide (2.4GHz global, 915MHz Americas or 868 MHz Europe). The data rate is 250kbps at 2.4GHz, 40kbps at 915MHz and 20kbps at 868MHz. IEEE and ZigBee Alliance have been working closely to specify the entire protocol stack. IEEE 802.15.4 focuses on the specification of the lower two layers of the protocol (physical and data link layer). On the other hand, ZigBee Alliance aims to provide the upper layers of the protocol stack (from network to the application layer) for interoperable data networking, security services and a range of wireless home and building control solutions, provide interoperability compliance testing, marketing of the standard, advanced engineering for the evolution of the standard.

2.3.1 ZigBee Protocol Features: Low duty cycle - provides long battery life Low latency Support for multiple network topologies: static, dynamic, star and mesh Direct Sequence Spread Spectrum (DSSS) Up to 65,000 nodes on a network 128-bit AES (Advanced Encryption Standard) - provides secure connections between devices Collision avoidance Link quality indication Clear channel assessment 6

Retries and acknowledgements Support for guaranteed time slots and packet freshness.

2.4 HOW ZIGBEE WORKS? ZigBee basically uses digital radios to allow devices to communicate with one another. A typical ZigBee network consists of several types of devices. A network coordinator is a device that sets up the network, is aware of all the nodes within its network, and manages both the information about each node as well as the information that is being transmitted/received within the network. Every ZigBee network must contain a network coordinator. Other Full Function Devices (FFD's) may be found in the network, and these devices support all of the 802.15.4 functions. They can serve as network coordinators, network routers, or as devices that interact with the physical world. The final device found in these networks is the Reduced Function Device (RFD), which usually only serve as devices that interact with the physical world. An example of a ZigBee network is shown below in Figure.

The figure above introduces the concept of the ZigBee network topology. Several topologies are supported by ZigBee, including star, mesh, and cluster tree. Star and mesh 7

networking are both shown in the figure above. As can be seen, star topology is most useful when several end devices are located close together so that they can communicate with a single router node. That node can then be a part of a larger mesh network that ultimately communicates with the network coordinator. Mesh networking allows for redundancy in node links, so that if one node goes down, devices can find an alternative path to communicate with one another. 2.5 ZIGBEE Vs BLUETOOTH ZigBee is broadly categorized as a low rate WPAN, and its closest technology is Bluetooth. A good bit of energy has been spent in analyzing whether ZigBee and Bluetooth are complementary or competing technologies, but after a quick look at the two, it can be seen that they fall a lot farther down the complementary side of the spectrum. They are two different technologies with very different areas of application and different means of designing for those applications. While ZigBee is focused on control and automation, Bluetooth is focused on connectivity between laptops, PDAs, and the like, as well as more general cable replacement. ZigBee uses low data rate, low power consumption, and works with small packet devices; Bluetooth uses a higher data rate, higher power consumption, and works with large packet devices. ZigBee networks can support a larger number of devices and a longer range between devices than Bluetooth. Because of these differences, the technologies are not only geared toward different applications, they don't have the capability to extend out to other applications. As an example, for its applications, Bluetooth must rely on fairly frequent battery recharging, while the whole goal of ZigBee is for a user to be able to put a couple of batteries in the devices and forget about them for months to years. In timing critical applications, ZigBee is designed to respond quickly, while Bluetooth takes much longer and could be detrimental to the application. Thus, a user could easily use both technologies as a wireless solution in a PAN to suit all types of applications within that network. 2.6 ZIGBEE APPLICATIONS

ZigBee Home Automation is the global standard for the control of appliances, lighting, environment, energy management, safety, and security. It supports a diverse ecosystem of service providers, original device manufacturers (ODM), and original equipment manufacturers (OEM) with a standards-based wireless solution for home and small office automation. ZigBee Smart Energy offers utilities and energy service providers secure, easyto-use wireless home area networks (HAN) for managing energy. Smart Energy gives these groups and their customers the power to directly communicate with thermostats and other smart appliances. ZigBee Health Care provides a global standard for interoperable wireless devices enabling secure and reliable monitoring and management of non-critical, low-acuity healthcare services targeted at chronic disease. It promotes aging independence, overall health, wellness and fitness by providing more information about one's state of health. Designed for use in homes, fitness centers, retirement communities, nursing homes and a variety of medical care facilities. ZigBee Telecommunication Services: Innovative mobile devices for innovative lifestyles are in development and will be available soon. ZigBee Industrial Automation extends existing manufacturing and process control systems reliability. 2.7 XBee/XBee-PRO RF MODULES The XBee and XBee-PRO OEM RF Modules were engineered to meet IEEE 802.15.4 standards and support the unique needs of low-cost, low-power wireless sensor networks. The modules require minimal power and provide reliable delivery of data between devices. The modules operate within the ISM 2.4 GHz frequency band and are pin-for-pin compatible with each other.

2.7.1 Key Features


Long Range Data Integrity: XBee Indoor/Urban: up to 100 (30 m) Outdoor line-of-sight: up to 300 (100 m) Transmit Power: 1 mW (0 dBm) Receiver Sensitivity: -92 dBm

XBee-PRO Indoor/Urban: up to 300 (100 m) Outdoor line-of-sight: up to 1 mile (1500 m) Transmit Power: 100 mW (20 dBm) EIRP Receiver Sensitivity: -100 dBm

RF Data Rate 250,000 bps

10

Advanced Networking & Security: Retries and Acknowledgements DSSS (Direct Sequence Spread Spectrum) Each direct sequence channels has over 65,000 unique network addresses available Source/Destination Addressing Unicast & Broadcast Communications Point-to-point, point-to-multipoint and peer-to-peer topologies supported Coordinator/End Device operations

Low Power: XBee TX Current: 45 mA (@3.3 V) RX Current: 50 mA (@3.3 V) Power-down Current: < 10 A

XBee-Pro TX Current: 215 mA (@3.3 V) RX Current: 55 mA (@3.3 V) Power-down Current: < 10 A

ADC and I/O line support: Analog-to-digital conversion Digital I/OI/O Line Passing

Easy-to-Use: 11

No configuration necessary for out-of box RF communications Free X-CTU Software (Testing and configuration software) AT and API Command Modes for configuring module parameters Extensive command set Small form factor

2.7.2 Mechanical Drawings The figure below shows mechanical drawings of the XBee/XBee PRO OEM RF Modules. The XBee and XBeePRO RF Modules are pinforpin compatible.

2.7.3 XBee/XBee-PRO 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 12

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

3.MICROCONTROLLERS
3.1 INTRODUCTION A microcontroller is an integrated chip that is often part of an embedded system. The microcontroller includes a CPU, RAM, ROM, I/O ports, and timers like a standard computer but they are designed to execute only a specific task to control a single system and are much smaller and simplified so that they can include all the functions required on a single chip.

13

E XTERNAL INTRRUPTS

INTERRUPT CONT ROL

ON-CHIP ROM FOR PROGRAM CODE

ON-CHIP RAM

TIMER0 TIMER1

COUNTER INPUTS

CPU

OSC

BUS CONT ROL

4 I/O PORT S

SERIAL PORT

P0

P1

P2 P3

TXD

RXD

ADDRESS/DATA

Block Diagram of Microcontroller 3.2 DESCRIPTION OF PHILIPS 89C51 MICROCONTROLLER Phillips 89C51 contains a non-volatile FLASH program memory that is parallel programmable. Phillips 89C51, 8-bit Micro controller from MHS-51 Intel family, with 4K bytes of flash and 128 bytes of internal RAM had been used. It has a 40-pin configuration and other components of interfaced to its ports. The Micro controller takes input from the external sources and routes them to the appropriate devices as programmed in it.

14

3.2.1 Features 89C51 Central Processing Unit On-chip FLASH Program Memory Speedup to 33 MHz RAM expandable externally up to 64 Kbytes Four interrupt priority levels and Six interrupt sources Fully static operation Four 8-bit input output ports Full-duplex enhanced UART Framing error detection Automatic address recognition Three 16-bit timers/counters T0, T1and additional T2 Power control modes Clock can be stopped and resumed Idle mode Power down mode Asynchronous port reset

3.2.2 Central Processing Unit The CPU processes instructions for arithmetic and logical operations, bit manipulations, and data transfer operations, input and output operations, program flow control, program sequencing and supervising the system operations.

15

3.2.3 Arithmetic Logic Unit The ALU performs arithmetic and logic functions on 8-bit variables. The ALU can perform addition, subtraction, multiplication and division and the logic unit can perform logical operations. An important and unique feature of the microcontroller architecture is that the ALU can also manipulate 1 bit as well as 8-bit data types. Individual bits may be set, cleared, complemented, moved, tested and used in logic computation. 3.2.4 Accumulator It is returned as register A or Acc. It is an 8-bit Register. Accumulator holds a source of operand and stores the result of the arithmetic operations such as addition, subtraction, multiplication and division. destination register for logical operations. The accumulator can be the source or The accumulator has several exclusive

functions such as rotate, parity computation; testing for 0, sign acceptor etc. and so on. 3.2.5 Program Counter The program counter points to the address of the next instruction to be executed. As the CPU fetches the opcode from the program ROM, the program counter is implemented to point to the next instruction. The microcontroller can access program addresses 0000 to FFFFH, a total of 64K bytes of code.

16

3.3 PIN DIAGRAM

Pin Diagram of Philips 89C51 Microcontroller

17

3.3.1 PIN DESCRIPTIONS

18: Port 1: Each of these pins can be used as either input or output according to your needs. Also, pins 1 and 2 (P1.0 and P1.1) have special functions associated with Timer.

9: Reset Signal: High logical state on this input halts the MCU and clears all the registers. Bringing this pin back to logical state zero starts the program a new as if the power had just been turned on. In another words, positive voltage impulse on this pin resets the MCU. Depending on the device's purpose and environs, this pin is usually connected to the push-button, reset-upon-start circuit or a brown out reset circuit.

10-17: Port 3: As with Port 1, each of these pins can be used as universal input or output. However, each pin of Port 3 has an alternative function: Pin 10: RXD - serial input for asynchronous communication or serial output for synchronous communication. Pin 11: TXD - serial output for asynchronous communication or clock output for synchronous communication Pin 12: INT0 - input for interrupt 0 Pin 13: INT1 - input for interrupt 1 Pin 14: T0 - clock input of counter 0 Pin 15: T1 - clock input of counter 1 Pin 16: WR - signal for writing to external (add-on) RAM memory 18

Pin 17: RD - signal for reading from external RAM memory.

18-19: X2 and X1: Input and output of internal oscillator. Quartz crystal controlling the frequency commonly connects to these pins. Capacitances within the oscillator mechanism are not critical and are normally about 30pF. Instead of a quartz crystal, miniature ceramic resonators can be used for dictating the pace. In that case, manufacturers recommend using somewhat higher capacitances.

20: GND:Ground 21- 28: Port 2: If external memory is not present, pins of Port 2 act as universal input/output. If external memory is present, this is the location of the higher address byte, i.e. addresses A8 A15. In cases when not all the 8 bits are used for addressing the memory (i.e. memory is smaller than 64kB), the rest of the unused bits are not available as input/output.

29: PSEN: MCU activates this bit (brings to low state) upon each reading of byte (instruction) from program memory. If external ROM is used for storing the program, PSEN is directly connected to its control pins.

31: EA: Bringing this pin to the logical state zero (mass) designates the ports P2 and P3 for transferring addresses regardless of the presence of the internal memory. This means that even if there is a program loaded in the MCU it will not be executed, but the one from the external ROM will be used instead. Conversely, bringing the pin to the high logical state causes the controller to use both memories, first the internal, and then the external (if present).

32-39: Port 0: Similar to Port 2, pins of Port 0 can be used as universal input/output, if external memory is not used. If external memory is used, P0 behaves as address output (A0 A7) when ALE pin is at high logical level, or as data output (Data Bus) when ALE pin is at low logical level.

40: VCC: Power +5V. 19

3.4 MEMORY ARCHITECTURE During the runtime, micro controller uses two different types of memory: one for holding the program being executed (ROM memory), and the other for temporary storage of data and auxiliary variables (RAM memory). Depending on the particular model from 8051 family, this is usually few kilobytes of ROM and 128/256 bytes of RAM. This amount is built-in and is sufficient for common tasks performed "independently" by the MCU. However, 8051 can address up to 64KB of external memory. These can be separate memory blocks, (separate RAM chip and ROM chip) totaling 128KB of memory on MCU, which is a real programming goody. 3.4.1 ROM memory First models from 8051 families lacked the internal program memory, but it could be added externally in a form of a separate chip. New models have built-in ROM, although there are substantial variations. With some models internal memory cannot be programmed directly by the user. Instead, the user needs to precede the program to the manufacturer, so that the MCU can be programmed (masked) appropriately in the process of fabrication. Many manufacturers deliver controllers that can be programmed directly by the user. These come in a ceramic case with an opening (Erasable Programmable Read Only Memory, EPROM version) or in a plastic case without an opening (Electrically Erasable Programmable Read Only Memory, EEPROM version). Flash ROM is also another popular method of storing a program. Flash memory features: FLASH EPROM internal program memory with chip erases. Up to 64K byte external program memory if the internal program memory is disabled. Programmable security bits. 20

10,000 minimum erase/program cycles for each byte&10 year minimum data retention. 3.4.2 RAM memory

Banks and Registers of RAM RAM is used for storing temporary data and auxiliary results generated during the runtime. Apart from that, RAM comprises a number of registers: hardware counters and timers, I/O ports, buffer for serial connection, etc. With older versions, RAM spanned 256 locations, while new models feature additional 128 registers. First 256 memory locations form the basis of RAM (addresses 0 Fifth) of every 8051 MCU. Locations that are available to the user span addresses from 0 to 7Fh, i.e. first 128 registers, and this part of RAM is split into several blocks. 21

First block comprises 4 "banks" of 8 registers each, marked as R0 - R7. To address these, the parent bank has to be selected.

Second memory block (range 20h 2Fh) is bit-addressable, meaning that every belonging bit has its own address (0 to 7Fh). Since the block comprises 16 of these registers, there is a total of 128 addressable bits. (Bit 0 of byte 20h has bit address 0, while bit 7 of byte 2Fh has bit address 7Fh).

Third is the group of available registers at addresses 2Fh 7Fh (total of 80 locations) without special features or a preset purpose.

3.4.3 Memory Expanding In case the built-in amount of memory (either RAM or ROM) is not sufficient for our needs, there is always an option of adding two external 64KB memory chips. When added, they are addressed and accessed via I/O ports P2 and P3. 8051 MCU has two separate read signals, RD# (P3.7) and PSEN#. The first one is active when reading byte from the external data memory (RAM), and the second one is active when reading byte from the external program memory (ROM). Both signals are active on low logical level. An expansion using separate chips for RAM and ROM is known as Harvard architecture. Memory can be also mapped as a single block, functioning as both data memory and program memory simultaneously (only one memory chip is used). This approach is known as Von Neumann architecture. To be able to read the same block using RD# or PSEN#, these two signals were combined via logical AND. Using the Hardware architecture effectively doubles MCU memory, but that's not the only advantage offered by the method. Keeping the program code separated from the data makes the controller more reliable. 3.5 SFR (Special Function Registers) 22

SFR registers can be seen as a sort of control panel for managing and monitoring the micro controller. Every register and each of the belonging bits has its name, specified address in RAM and strictly defined role (e.g. controlling the timer, interrupt, serial connection, etc). Although there are 128 available memory slots for allocating SFR registers, the basic core shared by 8051 MCU has 22 registers. The rest has been left open intentionally to allow future upgrades while retaining the compatibility with earlier models. ADDR. (HEX.) 80 81 82 83 87 88 89 8A 8B 8C 8D 90 98 99 A0 A8 B0 B8 D0 E0 F0 MARK P0 SP DPTR DPL DPH PCON TCON TMOD TL0 TL1 TH0 TH1 P1 SCON SBUF P2 IE P3 IP PSW ACC(A) B FULL NAME PORT 0 STACK POINTER DATA POINTER DATA LOW POINTER DATA HIGH POINTER POWER CONTROL TIMER/COUNTER CONTROL TIMER/COUNTER MODE CONTROL TIMER/COUNTER0 LOW BYTE TIMER/COUNTER1 LOW BYTE TIMER/COUNTER0 HIGH BYTE TIMER/COUNTER1 HIGH BYTE PORT 1 SERIAL PORT CONTROL SERIAL DATA PORT PORT 2 INTERRUPT ENABLE PORT 3 INTERRUPT PRIORITY CONTROL PROGRAM STATUS WORD ACCUMULATOR B REGISTER

3.5.1 PSW (program status word) Register: The program status word (PSW) register is on 8-bit register. It is also referred to as the flag register. 7 6 5 4 23 3 2 1 0

CY

AC

------

RS1

RS0

OV

------

CY - Carry-flag. AC -Auxiliary carry-flag. ---- - Available to the user for general-purpose. RS1- register bank selector bit 1. RS0- register bank selector bit 0. OV- overflow flag. ---- - User definable bit. P- Parity flag. Set/cleared by hardware each instruction cycle to indicate an odd/even. 3.5.2 SCON (Serial Control) Register: The Serial Control SFR is used to configure the behavior of the 8051's on-board serial port. This SFR controls the baud rate of the serial port, whether the serial port is activated to receive data, and also contains flags that are set when a byte is successfully sent or received.

REN-set or cleared by software to enable or disable reception. TB 8-not widely used. RB 8-not widely used. TI-transmits interrupt flag. Set by hardware at the beginning of the stop bit in mode 1. It must be cleared by software. RI-received interrupts flag. Set by hardware halfway through the stop bit time in mode 1. It must be cleared by software. SM0 0 SM1 0 Serial mode 0 Synchronous mode 24

0 1 1

1 0 1

8-bit data, 1 start bit, 1 stop bit, variable baud rate 9- bit data, 1 start bit, 1 stop bit, fixed baud rate 9- bit data, 1 start bit, 1 stop bit, variable baud rate

3.5.3 PCON (Power Control) Register: The Power Control SFR is used to control the 8051's power control modes. Certain operation modes of the 8051 allow the 8051 to go into a type of "sleep" mode which requires much less power. These modes of operation are controlled through PCON. 3.5.4 SBUF (Serial Control): The Serial Buffer SFR is used to send and receive data via the on-board serial port. Any value written to SBUF will be sent out the serial port's TXD pin. Likewise, any value which the 8051 receives via the serial port's RXD pin will be delivered to the user program via SBUF. In other words, SBUF serves as the output port when written to and as an input port when read from.

3.6 TIMERS Both Timer0 and Timer1 are 16-bits wide. 8051 has an 8-bit architecture, each 16-bit timer is accessed as two separate registers of Lower byte and Higher byte.The "timer or "counter "function is selected by control bits C/T in the special function register TMOD. These two timer/counters have for operating modes, which are selected by bit-pairs (M1/M0) in TMOD. timers/counters. Mode 3 is different. 25 Modes 0, 1, and 2 are the same for both

3.6.1 TMOD (Timer Mode) Registers The Timer Mode SFR is used to configure the mode of operation of each of the two timers.

GATE

C/T

M1

M0

GATE

C/T

M1

M0

----------------- TIMER 1 ----------------------GATE :

--------------------TIMER 0 ----------------

When set, start and stop of timer by hardware When reset, start and stop of timer by software

C/T

Cleared for timer operation Set for counter operation

Modes of TMOD Register

M1 0 0

M0 0 1

MODE 0 1

OPERATING MODE 13-bit timer mode 16-bit timer mode

26

1 1

0 1

2 3

8-bit auto reload mode Split timer mode

3.6.2 TCON (Timer Control) Register: The Timer Control SFR is used to configure and modify the way in which the 8051's two timers operate. This SFR controls whether each of the two timers is running or stopped and contains a flag to indicate that each timer has overflowed.

TF1

TR1

TF0

TR0

IE1

IT1

IE0

IT0

TF: timer overflows flag. Set by hardware when the timer/counter overflows. It is cleared by hardware, as the processor vectors to the interrupt service routine. TR: timer run control bit. Set or cleared by software to turn timer or counter on/off. IE: set by CPU when the external interrupt edge (H-to-L transition) is detected. It is cleared by CPU when the interrupt is processed. IT: set/cleared by software to specify falling edge/low-level triggered external interrupt. 3.7 INTERRUPTS A single microcontroller can serve several devices. In the interrupt method, whenever any device needs its service, the device notifies the microcontroller by sending it an interrupt signal. Upon receiving an interrupt signal, the microcontroller interrupts whatever it is doing and serves the device. The program associated with the interrupt is called the interrupt service routine (ISR). The advantageous of interrupts is that the microcontroller can serve many devices based on the priority assigned to it. 27

Six Interrupts in 89C51 1. Reset. 2. Two interrupts are set aside for the timers. 3. Two interrupts are set aside for hardware external hardware interrupts. 4. Serial Communications has a single interrupt (receive and transfer). The Interrupt Enable SFR is used to enable and disable specific interrupts. The low 7 bits of the SFR are used to enable/disable the specific interrupts, where as the highest bit is used to enable or disable ALL interrupts. 3.8 SERIAL COMMUNICATION Serial communication is the process of sending data one bit at one time, sequentially, over a communication channel or computer bus. One of the 8051s many powerful features is its integrated UART, otherwise known as a serial port. The fact that the 8051 has an integrated serial port means that you may very easily read and write values to the serial port.

1 0 01 0 1 11001010 Sender Receiver

There are two basic types of serial communications, synchronous and asynchronous. With Synchronous communications, the two devices initially synchronize themselves to each other, and then continually send characters to stay in sync. 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 28

be identified by start and stop bits. The start bit indicate when the data byte is about to begin and the stop bit signals when it ends. 3.8.1 RS232 To allow compatibility among the data communication equipment made by various manufacturers; an interfacing standard called RS232, was set by the electronics industries association (EIA) in 1960. RS 232 is the standard defined for the connection of "Data Terminal Equipment" (DTE) to "Data Communications Equipment" (DCE). DTE (Data Terminal Equipment) is a generic term for an item which forms part of the "information processing" portions of a system. Examples are: computer, printer, and terminal. DCE (Data Communications Equipment) is a device, which provides an interface between a DTE and a communications link. 3.9 ADDRESSING MODES An "addressing mode" refers to how you are addressing a given memory location. Immediate Addressing Immediate addressing is so-named because the value to be stored in memory immediately follows the operation code in memory. For example, the instruction: MOV A,#20h This instruction uses Immediate Addressing because the Accumulator will be loaded with the value that immediately follows; in this case 20 (hexadecimal).

Direct Addressing Direct addressing is so-named because the value to be stored in memory is obtained by directly retrieving it from another memory location. MOV A,30h

29

This instruction will read the data out of Internal RAM address 30 (hexadecimal) and store it in the Accumulator. Indirect Addressing Indirect addressing is a very powerful addressing mode which in many cases provides an exceptional level of flexibility. Indirect addressing appears as follows: MOV A,@R0 This instruction causes the 8051 to analyze the value of the R0 register. The 8051 will then load the accumulator with the value from Internal RAM which is found at the address indicated by R0. Register Addressing It involves the use of Registers to hold the data to be manipulated. The source and destination Registers must match in size. We can move the data between Accumulator and register, but movement of data between registers is not allowed. MOV A, R0 This instruction will copy the contents of R0 into A

4. LIQUID CRYSTAL DISPLAY


4.1 INTRODUCTION

30

The PCD8544 is a low power CMOS LCD controller/driver, designed to drive a graphic display of 48 rows and 84 columns. All necessary functions for the display are provided in a single chip, including on-chip generation of LCD supply and bias voltages, resulting in a minimum of external components and low power consumption. The PCD8544 interfaces to micro controllers through a serial bus interface. The PCD8544 is manufactured in n-well CMOS technology.

4.2 FEATURES
Single chip LCD controller/driver 48 row, 84 column outputs Display data RAM 48 84 bits On-chip: Generation of LCD supply voltage (external supply also possible) Generation of intermediate LCD bias voltages Oscillator requires no external components (external clock also possible).

External RES (reset) input pin Serial interface maximum 4.0 M bits/s CMOS compatible inputs Logic supply voltage range VDD to VSS: 2.7 to 3.3 V Display supply voltage range VLCD to VSS 6.0 to 8.5 V with LCD voltage internally generated (voltage generator enabled) 6.0 to 9.0 V with LCD voltage externally supplied (voltage generator switchedoff). Low power consumption, suitable for battery operated systems Temperature compensation of VLCD Temperature range: -25 to +70 C

31

4.3 BLOCK DIAGRAM

4.4 FUNCTIONAL DESCRIPTION OF GRAPHICAL LCD Oscillator The on-chip oscillator provides the clock signal for the display system. No external components are required and the OSC input must be connected to VDD. An external clock signal, if used, is connected to this input. Address Counter (AC) The address counter assigns addresses to the display data RAM for writing. The X-address X6 to X0 and the Y-address Y2 to Y0 are set separately. After a write operation, V flag. the address counter is automatically incremented by 1, according to the

Display Data RAM (DDRAM)

32

The DDRAM is a 48 84 bit static RAM which stores the display data. The RAM is divided into six banks of 84 bytes (6 8 84 bits). During RAM access, data is transferred to the RAM through the serial interface. There is a direct correspondence between the X-address and the column output number. Timing generator The timing generator produces the various signals required to drive the internal circuits. Internal chip operation is not affected by operations on the data buses. Display address counter The display is generated by continuously shifting rows of RAM data to the dot matrix LCD through the column outputs. The display status (all dots on/off and normal/inverse video) is set by bits E and D by the display control command. LCD row and column drivers The PCD8544 contains 48 row and 84 column drivers, which connect the appropriate LCD bias voltages in sequence to the display in accordance with the data to be displayed. Unused outputs should be left unconnected. 4.5 LCD PIN DESCRIPTION

SYMBOL
R0 to R47 C0 to C83 VSS1,VSS2 VDD1,VDD2 VLCD1,VLCD2 T1 T2 T3 T4

DESCRIPTION
LCD ROW DRIVER OUTPUTS LCD COLUMN DRIVER OUTPUTS GROUND SUPPLY VOLTAGE LCD SUPPLY VOLTAGE TEST 1 INPUT TEST2 OUTPUT TEST3 INPUT/OUTPUT TEST4 INPUT

33

SDIN SCLK D/C SCE OSC RES DUMMY1,2,3,4

SERIAL DATA INPUT SERIAL CLOCK INPUT DATA/COMMAND CHIP ENABLE OSCILLATOR EXTERNAL RESET INPUT NOT CONNECTED

4.6 DESCRIPTION OF INSTRUCTION SET 4.6.1 Initialization Immediately following power-on, the contents of all internal registers and of the RAM are undefined. A RES pulse must be applied. Attention should be paid to the possibility that the device may be damaged if not properly reset. All internal registers are by applying an external RES pulse (external low) at pad 31, within the specified time. However, the RAM contents are still undefined. The state after reset is described in section below The RES input must be 0.3VDD when VDD reaches VDDmin (or higher) within a maximum time of 100ms after VDD goes HIGH . 4.6.2 Reset Function After reset, the LCD driver has the following state: Power-down mode (bit PD=1) Horizontal addressing (bit V=0) normal instruction set (bit H=0) Display blank (bit E=D=0) Address counter X5 to X0 = 0; Y2 to Y0 = 0 Temperature control mode (TC1 TC0 = 0) Bias system (BS2 to BS1 = 0) VLCD is equal to 0, the HV generator is switched off (Vop6 to Vop0) After power-on, the RAM contents are undefined.

34

5. BRIEF DESCRIPTION OF SOFTWARE MODULES


5.1 INTRODUCTION Programming Language Software used System requirements There are minimum hardware and software requirements that must be satisfied to ensure that the compiler and utilities function properly. For our Windows-based tools, we must have the following: PC with Pentium, Pentium-II or compatible processor, Windows 95, Windows-98, Windows NT 4.0, or higher 16 MB RAM minimum, 20 MB free disk space. : : C Language KEIL Vision2 IDE, Flash Magic

5.2 EVALUTION OF KEIL SOFTWARE The KEIL Vision2 IDE combines project management, a rich-featured editor with Interactive error correction, option setup, makes facility, and on-line help. We use Vision2 to create our source files and organize them into a project that defines our target application. Vision2 automatically compiles, assembles, and links our embedded application and provides a single focal point for our development efforts. 1. 2. 3. 4. 5. Start the Vision Program After the program has started: Select File, New from the program menu. Type your assembly file. Select File, Save from the program menu The first time you save the program a dialog box will popup and allow you to name your file and file type.

35

ORG 0H MOV A, #55H AGAIN: MOV P1, A MOV P2, A ACALL DELAY CPL A SJMP AGAIN DELAY: MOV R3, #200 OUTER: MOV R2, #0255 INNER: DJNZ R2, INNER DJNZ R3, OUTER RET END

6. 7. 8. 9.

Save program with filename: Toggle.a51 Change the file type: Assembler (*.a51) Select Project, New Project from the program menu Give project name: Toggle.prj

10. Click on the Add button 11. A dialog-box appears, allowing you to add files to the project 12. Change the file type to Assembly. 13. Select your assembly file. 14. Click on the Add button then close the Add dialog box. 15. Click on Save in your Project dialog box. 16. Select Project, Make: Build Project from the program menu 17. This creates the HEX file you need for the 8051 5.2.1 Using The Keil Dscope Debugger 1. Select Run, dScope debugger from the program menu The debug program will start a new session 2. Select File, load CPU driver from the program menu Choose the 8051.dll from the drop down list box; you can also select this directly. 3. Select File, load object file from the program menu. Change the file type to HEX Select your hex file, e.g. Toggle. Hex Click OK 36

4. You should now see the source code of the file typed in earlier 5. Select Peripherals, I/O Ports from the program menu. Select Port 0, Port 1, Port 2 and Port 3 This will bring up 4 boxes that display the status of the ports on the microcontroller. 6. Click on go to see the real time update of the I/O ports. 7. Click on stop when you are finished. 5.3 FLASH MAGIC: The Flash Magic is feature rich in windows based tool for downloading of code into flash micro controller .It utilizes feature of microcontrollers called ISP, which allow the transfer of data serially between a PC and the device. Flash Magic can erase device, program, read data and read and set various configuration information. rather than providing the basic feature of ISP, Flash Magic adds additional features and intelligence, allowing complex operation to be performed .For example ,erasing can be any collection pages,blocks.the hex file to be programmed or the entire device. Additional advanced feature of Flash Magic include the automatic programming,checksum,entering ISP mode via serial command, execution of just time module allowing endless flexibility in the data programmed ,control over RS232 signal to place devices into ISP mode and control over the timing of such signal Flash magic supports all current 8-bit (8051), 16 bit and 32 bit flash microcontrollers

37

Power Supply Design

38

POWER SUPPLY: The input to the circuit is applied from the regulated power supply. The a.c. input i.e., 230V from the mains supply is step down by the transformer to 12V and is fed to a rectifier. The output obtained from the rectifier is a pulsating d.c voltage. So in order to get a pure d.c voltage, the output voltage from the rectifier is fed to a filter to remove any a.c components present even after rectification. Now, this voltage is given to a voltage regulator to obtain a pure constant dc voltage.

230V AC 50Hz

D.C Output

Step down transformer

Bridge Rectifier

Filter

Regulator

Fig: Power supply

39

Transformer: Usually, DC voltages are required to operate various electronic equipment and these voltages are 5V, 9V or 12V. But these voltages cannot be obtained directly. Thus the a.c input available at the mains supply i.e., 230V is to be brought down to the required voltage level. This is done by a transformer. Thus, a step down transformer is employed to decrease the voltage to a required level.

Rectifier: The output from the transformer is fed to the rectifier. It converts A.C. into pulsating D.C. The rectifier may be a half wave or a full wave rectifier. In this project, a bridge rectifier is used because of its merits like good stability and full wave rectification.

40

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.

41

42

Filter: Capacitive filter is used in this project. It removes the ripples from the output of rectifier and smoothens the D.C. Output received from this filter is constant until the mains voltage and load is maintained constant. However, if either of the two is varied, D.C. voltage received at this point changes. Therefore a regulator is applied at the output stage. Voltage regulator: As the name itself implies, it regulates the input applied to it. A voltage regulator is an electrical regulator designed to automatically maintain a constant voltage level. In this

project, power supply of 5V and 12V are required. In order to obtain these voltage levels, 7805 and 7812 voltage regulators are to be used. The first number 78 represents positive supply and the numbers 05, 12 represent the required output voltage levels. The L78xx series of three-terminal positive regulators is available in TO-220, TO-220FP, TO-3, D2PAK and DPAK packages and several fixed output voltages, making it useful in a wide range of applications. These regulators provide local on-card regulation, associated eliminating single can the point

distribution

problems

with

regulation. Each type employs internal current limiting,

43

thermal shut-down and safe area protection, making it essentially indestructible. If adequate heat sinking is provided, they can deliver over 1 A output current. Although designed primarily as fixed voltage regulators, these devices can be used with external components to obtain adjustable voltage and currents.

44

9. Liquid Crystal Display [LCD]


We examine an intelligent LCD display of two lines, 16 characters per line that is interfaced to the 8051.The protocol (handshaking) for the display is as shown. The display contains two internal byte-wide registers, one for commands (instructions) (RS=0) and the second for characters (data) to be displayed (RS=1).It also contains a user-programmed RAM area (the character RAM) that can be programmed to generate any desired character that can be formed using a dot matrix. To distinguish between these two data areas, the hex command byte 80 will be used to signify that the display RAM address 00h will be chosen Port1 is used to furnish the command or data type, and ports 3.2 to 3.4 furnish register select and read/write levels. The display takes varying amounts of time to accomplish the functions as listed. LCD bit 7 is monitored for logic high (busy) to ensure the display is overwritten. A slightly more complicated LCD display (4 lines*40 characters) is currently being used in medical diagnostic systems to run a very similar program. Liquid Crystal Display

Figure: 10.1 Liquid Crystal Display

45

Pins Description
1 Ground 3 Contrast Voltage 7 - 14 Data I/O Pins 9 K(cathode) back light power supply GND 2 Vcc 4"R/S"_Instruction(0)/data(1) Select 8 A(anode) back light power supply 5V

5 "R/W" Read(1)/Write(0) LCD Registers 6 "E" Clock

Gnd

+5v

Vdd

15

16

16x2 Liquid Crystal Display

10

11

12

13 14

RS R/W En

Figure: 10.2 Showing LCD Pins

D0 D1 D2 0D 6 0

D3 D4

D5 D6 D7

46

11.RELAY
Introduction:A relay is an electrical switch that opens and closes under control of another electrical circuit. In the original form, the switch is operated by an electromagnet to open or close one or many sets of contacts. It was invented by Joseph Henry in 1835. Because a relay is able to control an output circuit of higher power than the input circuit, it can be considered, in a broad sense, to be a form of an electrical amplifier. Operation:When a current flows through the coil, the resulting magnetic field attracts an armature that is mechanically linked to a moving contact. The movement either makes or breaks a connection with a fixed contact. When the current to the coil is switched off, the armature is returned by a force approximately half as strong as the magnetic force to its relaxed position. Usually this is a spring, but gravity is also used commonly in industrial motor starters. Most relays are manufactured to operate quickly. In a low voltage application, this is to reduce noise. In a high voltage or high current application, this is to reduce arcing. If the coil is energized with DC, a diode is frequently installed across the coil, to dissipate the energy from the collapsing magnetic field at deactivation, which would otherwise generate a spike of voltage and might cause damage to circuit components. If the coil is designed to be energized with AC, a small copper ring can be crimped to the end of the solenoid. This "shading ring" creates a small out-of-phase current, which increases the minimum pull on the armature during the AC cycle. By analogy with the functions of the original electromagnetic device, a solid-state relay is made with a thyristor or other solid-state switching device. To achieve electrical isolation, a light-emitting diode (LED) is used with a photo transistor.

47

Types of relay:-

Figure: 11.1: latching relay 1) Latching relay:A latching relay has two relaxed states (bistable). These are also called 'keep' relays. When the current is switched off, the relay remains in its last state. This is achieved with a solenoid operating a ratchet and cam mechanism, or by having two opposing coils with an over-center spring or permanent magnet to hold the armature and contacts in position while the coil is relaxed, or with a remnant core. In the ratchet and cam example, the first pulse to the coil turns the relay on and the second pulse turns it off. In the two coil example, a pulse to one coil turns the relay on and a pulse to the opposite coil turns the relay off. This type of relay has the advantage that it consumes power only for an instant, while it is being switched, and it retains its last setting across a power outage.

48

Fig: 9.2 Showing Mechanical Operation of Relay

9.3 The Latching Relay Circuit


If a relay is connected as shown in figure 3, it will become 'latched' on when the coil is energised by pressing the Trigger button. The only way to turn the relay off will then be to cut the power supply by pressing the Reset button (which must be a push-tobreak type).

Fig: 9.3 Showing The Latching Relay Circuit

49

PIR Sensor
A PIR Sensor is a Passive Infrared Sensor which controls the switching on/off of the lighting load when it detects a moving target. The built in sensor turns on/off the connected lighting load when it detects motion in the coverage area. It has different working principle during the day time and the night time. During the day, the built in photocell sensor saves electricity by deactivating the lighting load connected to the sensor. During the night the connected lighting load is turned on by adjusting the luminosity knob (LUX). An adjustable time knob lets you select how long the light stays on after activation.

Detection Pattern

50

Working
Instead of infrared or laser transmitters and receivers, PIR (Passive Infrared Radial) sensors are used in this circuit. The sensor is basically a pyroelectric device. When the device is exposed to infrared radiation, it generates an electric charge. The device is made of crystalline material. According to the change in the amount of infrared striking the element, there will be a change in the voltages generated, which is measured by an onboard amplifier. The infrared light explained here refers to the light radiating from all objects in its field of view. The reason for not having a transmitter and receiver is that the device does not emit one, but only accepts the energy emitted from objects above absolute zero in the form of radiations. Thus the temperature will be different for a human working past a sensor, and that of a wall right in front of it. Thus the word passive is used in PIR to explain that it does not emit a radiation and receive it, but instead accepts the incoming infrared radiation passively. The block diagram of the PIR based security system is given below.

PIR Block Diagram

51

GAS sensor

52

Flame sensor

Hamamatsu R2868 is a UV TRON ultraviolet detector that makes use of the photoelectric effect of metal and the gas multiplication effect. It has a narrow spectral sensitivity of 185 to 260 nm, being completely insensitive to visible light. Unlike semiconductor detectors, it does not require optical visible-cut filters, thus making it easy to use. In spite of its small size, the R2868 has wide angular sensitivity (directivity) and can reliably and quickly detect weak ultraviolet radiations emitted from flame due to use of the metal plate cathode (eg. it can detect the flame of a cigarette lighter at a distance of more than 5 m.). The R2868 is well suited for use in flame detectors and fire alarms, and also in detection of invisible discharge phenomena such as corona discharge of high-voltage transmission lines.

53

RS 232:
In telecommunications, RS-232 (Recommended Standard 232) is a standard for serial binary data signals connecting between a DTE (Data Terminal Equipment) and a DCE (Data Circuit Terminating Equipment). It is a commonly used in computer serial ports. An RS-232 port can supply only limited power to another device. The number of output lines, the type of interface driver IC, and the state of the output lines are important considerations.

Fig. 2.8 RS 232 Connector In serial communication the terminal end (PC) is called the Data Terminal Equipment (DTE) and the modem is called the Data Communication Equipment (DCE) as shown in the diagram below.

Fig 2.9 Serial Communication with modem RS-232 signals have a direction (in or out) depending on whether they are with respect to a DTE or a DCE. In the entire pin out diagrams below the signal direction is with respect to the DTE (PC).

54

Fig. 2.10 DB9: View looking into male connector

Fig 2.11 DB9: View looking into female connector

55

Circuit diagram

56

57

PCB

6. CODE
6.1 ZIGBEE COMMUNICATION TRANSMITTER

58

#include <reg51.h> #include<intrins.h> sbit lcd_rs = P1^5; sbit lcd_rw = P1^6; sbit lcd_en = P1^7; #define lcd_data P0 sbit lcd_busy = P0^7; void lcdline1(); void lcdline2(); void lcdline3(); void lcdline4(); void lcd_clr(); void busy_check(); void lcdinit(); void displaystring(char *ptr); void lcd_cmmnd( unsigned char val); sbit sw1=P1^1; sbit sw2=P1^2; sbit sw3=P1^3; sbit sw4=P1^4; sbit led1=P2^1; sbit led2=P2^2; void loop1(); void loop2(); void loop3(); void loop4(); void delay_ms(unsigned char); void main() { lcdinit(); TMOD=0x20; SCON=0x50; TH1=0x0FD; TR1=1; P2=0x00; delay_ms(500); lcdline1(); displaystring("ZIGBEE COMUNCATION"); delay_ms(500); 59

lcdline2(); displaystring("developed by"); delay_ms(500); lcdline4(); displaystring("US"); delay_ms(500); lcd_clr(); while(1) { if (sw1==0) loop1(); if (sw2==0) loop2(); if (sw3==0) loop3(); if (sw4==0) loop4(); } } void loop1() { lcdline1(); displaystring("50W LIGHT ON "); SBUF='a'; while(TI==0); TI=0; while(1) { led1=1; if (sw2==0) loop2(); if (sw3==0) loop3(); if (sw4==0) loop4(); } } void loop2() { lcdline1(); 60

displaystring("50W LIGHT OFF "); SBUF='b'; while(TI==0); TI=0; while(1) { led1=0; if (sw1==0) loop1(); if (sw3==0) loop3(); if (sw4==0) loop4(); } } void loop3() { lcdline2(); displaystring("fan ON "); SBUF='c'; while(TI==0); TI=0; while(1) { led2=1; if (sw1==0) loop1(); if (sw2==0) loop2(); if (sw4==0) loop4(); } } void loop4() { lcdline2(); displaystring(" fan Off "); SBUF='d'; while(TI==0); TI=0; while(1) { led2=0; 61

if (sw1==0) loop1(); if (sw2==0) loop2(); if (sw3==0) loop3(); } } void lcdinit() { lcd_cmmnd(0x30); lcd_cmmnd(0x38); lcd_cmmnd(0x06); lcd_cmmnd(0x0c); lcd_cmmnd(0x01); } void lcd_cmmnd( unsigned char val) { busy_check(); lcd_data =val; lcd_rs=0; lcd_rw=0; lcd_en=1; _nop_(); lcd_en=0; } void lcd_dataout(unsigned char val) { busy_check(); lcd_data =val; lcd_rs=1; lcd_rw=0; lcd_en=1; _nop_(); lcd_en=0; } void lcdline1() { lcd_cmmnd(0x80); } 62

void lcdline2() { lcd_cmmnd(0xc0); } void lcdline3() { lcd_cmmnd(0x94); } void lcdline4() { lcd_cmmnd(0xd4); } void lcd_clr() { lcd_cmmnd(0x01); } void displaystring(char *ptr) { while(*ptr) { lcd_dataout(*ptr); delay_ms(2); ptr++; } } void busy_check(void) { lcd_data = 0xff; lcd_rs = 0; lcd_rw =1; while(lcd_busy==1) { lcd_en =0; _nop_(); _nop_(); lcd_en=1; 63

} } void delay_ms(unsigned char p) { unsigned int i,j; for(i=0;i<1273;i++) for(j=0;j<p;j++); }

6.2 ZIGBEE COMMUNICATION RECEIVER #include <reg51.h> #include<intrins.h> sbit lcd_rs = P1^5; sbit lcd_rw = P1^6; sbit lcd_en = P1^7; #define lcd_data P0 sbit lcd_busy = P0^7; void lcdline1(); void lcdline2(); void lcdline3(); void lcdline4(); void lcd_clr(); void delay_1msc(); void lcdinit(); void displaystring(char *ptr); void lcd_cmmnd( unsigned char val); sbit led1=P2^1; sbit led2=P2^2; void loop1(); void loop2(); void loop3(); void loop4(); unsigned char x; void main() 64

{ lcdinit(); TMOD=0x20; SCON=0x50; TH1=0x0FD; TR1=1; P2=0x00; while(1) { while (RI==0); x=SBUF; RI=0; if(x=='a') loop1(); if(x=='b') loop2(); if(x=='c') loop3(); if(x=='d') loop4(); } } void loop1() { led1=1; lcdline1(); displaystring("50W LIGHT ON "); while(RI==0); x=SBUF; RI=0; while(1) { if (x=='b') loop2(); if (x=='c') loop3(); if (x=='d') loop4(); } }

65

void loop2() { led1=0; lcdline1(); displaystring("50W LIGHT OFF"); while(RI==0); x=SBUF; RI=0; while(1) { if (x=='a') loop1(); if (x=='c') loop3(); if (x=='d') loop4(); } } void loop3() { led2=1; lcdline2(); displaystring("FAN ON "); while(RI==0); x=SBUF; RI=0; while(1) { if (x=='a') loop1(); if (x=='b') loop2(); if (x=='d') loop4(); } }

66

void loop4() { led2=0; lcdline2(); displaystring("FAN OFF"); while(RI==0); x=SBUF; RI=0; while(1) { if (x=='a') loop1(); if (x=='b') loop2(); if (x=='c') loop3(); } } void lcdinit() { lcd_cmmnd(0x30); lcd_cmmnd(0x38); lcd_cmmnd(0x06); lcd_cmmnd(0x0c); lcd_cmmnd(0x01); } void lcd_cmmnd( unsigned char val) { delay_1msc(); lcd_data =val; lcd_rs=0; lcd_rw=0; lcd_en=1; _nop_(); lcd_en=0; } void lcd_dataout(unsigned char val) 67

{ delay_1msc(); lcd_data =val; lcd_rs=1; lcd_rw=0; lcd_en=1; _nop_(); lcd_en=0; } void lcdline1() { lcd_cmmnd(0x80); } void lcdline2() { lcd_cmmnd(0xc0); } void lcdline3() { lcd_cmmnd(0x94); } void lcdline4() { lcd_cmmnd(0xd4); } void lcd_clr() { lcd_cmmnd(0x01); } void displaystring(char *ptr) { while(*ptr) { lcd_dataout(*ptr); 68

ptr++; } } void delay_1msc(void) { lcd_data = 0xff; lcd_rs = 0; lcd_rw =1; while(lcd_busy==1) { lcd_en =0; _nop_(); _nop_(); lcd_en=1; } }

69

8. CONCLUSION
This project has combined the characteristics of the IEEE 802.15.4 standard with the maturing ZigBee specification in defining the wireless profiles for low data rate monitoring and control applications. The capabilities of both will result in the availability of a technology tailored specifically for the low power, low cost, and low complexity applications in the industrial, residential, and home today and in the future.

If the application strictly needs to communicate in a point-to-point or point-tomultipoint fashion ZigBee will be able to handle all the communications between your devices and will be simpler to implement. Flexible management of home appliances from anywhere in the house is possible using the ZigBee remote.

70

8. REFERENCES
Homepage of ZigBee Alliance, http://www.zigbee.org/

Muhammad Ali Mazidi The 8051 Microcontroller and Embedded Systems Kenneth J.Ayala The 8051 Micro-controller Second Edition

Myke Predko Programming and customizing the 8051 www.atmel.com www.analogicgroup.com www.philips.com
P. Kinney, ZigBee Technology: Wireless Control that Simply Works, White Paper dated 2 October 2003

71

You might also like