Sie sind auf Seite 1von 72

SECURITY MANAGEMENT SYSTEM FOR OILFIELD BASED ON ZIGBEE

Project Report submitted in partial fulfillment of the requirements for the award of the degree of Bachelor of Technology in

ELECTRONICS & INSTRUMENTATION ENGINEERING


by SOWMYA KRISHNA AKASH RANJAN S.V.D. MALLESHWAR G. SIDDARDHA

Under the esteemed guidance of SRI L. SRINIVAS RAO M.Tech, ICS


Assistant Professor

DEPARTMENT OF ELECTRONICS & INSTRUMENTATION ENGINEERING GITAM INSTITUTE OF TECHNOLOGY GITAM UNIVERSITY VISAKHAPATNAM-530045 ANDHRA PRADESH

SECURITY MANAGEMENT SYSTEM FOR OILFIELD BASED ON ZIGBEE


Project Report submitted in partial fulfillment of the requirements for the award of the degree of Bachelor of Technology in

ELECTRONICS & INSTRUMENTATION ENGINEERING


by SOWMYA KRISHNA AKASH RANJAN S.V.D. MALLESHWAR G. SIDDARDHA

Under the esteemed guidance of SRI L. SRINIVAS RAO M.Tech, ICS


Assistant Professor

DEPARTMENT OF ELECTRONICS & INSTRUMENTATION ENGINEERING GITAM INSTITUTE OF TECHNOLOGY GITAM UNIVERSITY VISAKHAPATNAM-530045 ANDHRA PRADESH

DEPARTMENT OF ELECTRONICS & INSTRUMENTATION ENGINEERING GITAM INSTITUTE OF TECHNOLOGY GITAM UNIVERISTY VISAKHAPATNAM-530045

CERTIFICATE
This is to certify that project work entitled SECURITY MANAGEMENT SYSTEM FOR OILFIELD BASED ON ZIGBEE has been carried out by the following students under my guidance in the partial fulfillment of the requirements for the award of degree of Bachelor of Technology in Electronics & Instrumentation Engineering submitted to the Department of Electronics & Instrumentation Engineering, GITAM INSTITUTE of TECHNOLOGY, GITAM UNIVERSITY, Visakhapatnam, during the year 2011-2012.

Name SOWMYA KRISHNA AKASH RANJAN S.V.D. MALLESHWAR G. SIDDARDHA

Registration No. 1210608138 1210608102 1210608102 1210608102

(Dr. D Elizabeth Rani)

(L. Srinivas Rao)

Signature of Head of Department

Signature of Guide

ACKNOWLEDGEMENT

We express our profound sense of gratitude to our guide Sri L Srinivas Rao, Assistant Professor, Dept. of Electronics & Instrumentation Engineering, GITAM University for the brilliant and gracious and unstinted cooperation through out our work. He spared his valuable time and spared project report with keen interest. This project report would not have been shaped to this form without his encouragement and cooperation.

We also express our thanks to Dr. D. Elizabeth Rani, Head of the Department of Electronics & Instrumentation engineering for the encouragement and support given to us.

We are thankful to other staff members of the college for their encouragement and valuable suggestions during the project work.

Sowmya Krishna Akash Ranjan S.V.D. Malleshwar G. Siddardha

Abstract

With rapid development of national economic construction, there is a great demand and dependent on petroleum in various industries. The international price of petroleum has been kept at a high level in recent years, so production efficiency on domestic oilfield is urgently needed to be improved, new requirements for oilfield information construction is raised, construction of information and digitalization become development direction for oilfield. The first level consists of some remote controllers and a launcher, which include wireless fire alarm and burglar alarm; and some water sprinkling mechanism. The second level consists of a wireless receiver and a wireless alarm controller in the system. The core of a wireless receiver and some launchers adopt advanced embedded technology. The wireless communication system which we are going to use is zigbee. ZigBee is a low-cost, low-power, wireless mesh network standard. The low cost allows the technology to be widely deployed in wireless control and monitoring applications. Low power-usage allows longer life with smaller batteries. Mesh networking provides high reliability and more extensive range.

CONTENTS
1. 2.

Introduction
Embedded System 2.1 Embedded System 2.2 Real Time System 2.3 Categories of Embedded System 2.4 Gartner Corporation Categories 2.5 Applications of Embedded System 2.6 Microcontrollers 2.6.1 Introduction 2.6.2 Microcontroller vs Microprocessor 2.6.3 Advantages of Microcontroller 2.6.4 Types of 8051 Microcontroller 2.6.5 Features 2.7 Microcontroller 8051 2.7.1 Introduction 2.7.2 Description 2.7.3 Features 2.7.4 Microcontroller Architecture 2.7.5 Features of 89C51 2.7.6 Pin Description 2.7.7 Input-Output Ports 2.7.8 Memory in Microcontroller 2.7.9 Using Timers to Measure Time

3.

ZigBee Wireless Communication 3.1 Introduction 3.2 ZigBee Characteristics 3.3 Frame Structure

4.

Hardware Design 4.1 Block Diagram 4.1.1 Transmitter Side 4.1.2 Receiver Side

4.2 Power supply 4.3 Serial Communication 4.4 Synchronous And Synchronous Communication 4.5 Drivers for Serial Communication 4.5.1 RS 232 4.5.2 MAX 232 4.6 Drivers for Relay 4.7 Zigbee module: Tarang 4.8 Buzzer 4.9 LCD Display 5. Software 5.1 Keil Software 5.2 Getting Started and Creating Application 5.2.1 Evaluation Kits and Development Kits. 5.2.2 Types of users 5.3 Vision IDE 5.3.1 About the Environment 5.3.2 Menu, Commands, Toolbars and Shortcuts 5.3.4 Vision Features 5.4 Advantages 5.5 Using Keil 5.6 Programming the Chip 5.6.1 Intelligent Universal Programmer 6. Source Code 6.1 Transmitter Side 6.2 Receiver Side 7. Conclusion

1. INTRODUCTION

With rapid development of national economic construction, there is a great demand and dependent on petroleum in various industries. The international price of petroleum has been kept at a high level in recent years, so production efficiency on domestic oilfield is urgently needed to be improved, new requirements for oilfield information construction is raised, construction of information and digitalization become development direction for oilfield. The Distribution State of working environment in oilfield is very special, the site of oilwell is distributed dispersedly, but distribution area is widely, oil exhauster continuous working for 24h, regional of Perambulation for the site of oil-well is very vast, meanwhile, as for the problem of petroleum' being stolen, transmission line' being stolen, transformer' being stolen, which has been one of the important management works. With Consideration of the objective condition restriction of geographical environment, the implementation of safe management for oilfield is very difficult. We overcome these difficulties, which comes from geographical environment. the cost is not only high if the fiber cable would be lay between working station in the several tens of square kilometers, but also need to put into a lot of human and material resources with line maintenance and guard against theft. It is a perfect scheme that remote wireless monitoring and control system is established. This system can improve the level of oilfields security; enhance the security checking management of digitization and information. The method could solve problems with highly efficient and rapid, also could reduce the loss of country with effective. So it has the important significance and social and economic benefits for the dependability and controllability of remote communication.

2. EMBEDDED SYSTEM

2.1 Embedded System:


An embedded system is a device that is used to control, monitor or assist the operation of machinery equipment or plant and is an integral part of the system. In many cases their being embedded may be such that their presence is far from obvious to a 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. All embedded systems include computers or microprocessors. Some of these computers are however very simple systems as compared with a personal computer. 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 applications software on such processors is sometimes referred to as firmware. The simplest embedded systems are capable of performing only single function or a set of functions to meet a single predetermined purpose depending on the program. The ability to have programs means that the same embedded system can be used for a variety of different purposes. The simplest device consists of a single microprocessor, 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 that may start or stop the operation of a machine by operating a relay.

2.2 Real Time System:


A real time system is one in which the correctness of the computations not only depends upon the logical correctness of the computation but also upon the time at which the results are produced. If the timing constraints of the system are not met, system failure is said to have occurred. Real time in Operating System is the ability of the operating system to provide a required level of service in a bounded response time.

What makes a good RTOS?


Multi-threaded and pre-emptive scheduling Thread priority has to exist because no deadline driven OS exists Must support predictable thread synchronization mechanisms

A system of priority inheritance must exist And it should be: Scalable Configurable Small footprint CPU support Device drivers

2.3 Categories of Embedded System:


Individual microprocessors: These may be found in small devices such as temperature sensors, smoke and gas detectors, circuit breakers, etc. Small assemblies of microprocessors with no timing function are found in flow controllers, signal amplifiers, position sensors and Valve actuators. Subassemblies with a timing function are devices such as switchgear, controllers (e.g. for traffic), telephone exchanges, lifts, data acquisition and monitoring systems, diagnostic and real time control system may fall into this category. Computer systems used in manufacturing or process control are cases where the computer is connected to plant or machinery in order to control it. In such systems the computer is used for overall control and monitoring, rather than for direct control of individual devices within it, which almost certainly involves other kinds of embedded systems.

2.4 Gartner Corporation Categories:


Gartner Corporation Divides embedded systems into three categories Micro controllers: These are found in domestic and consumer products. These cannot be programmed and rarely have a real-time clock. Gartner estimates that the chance of one of these systems failing is 1 in 100,000. Microprocessor: Microprocessors are more complex and sophisticated. They may cause problems if used in conjunction with a program that is connected to a real-time clock. It is

estimated that 7% of these will have transient Year 2000 problems; 2% may have Persistent problems. Large-scale systems: Computer with a hard disc drive is connected to equipment that may incorporate Microprocessors. The failure rate for these systems is estimated at 35%.

2.5 Application of Embedded System:


Embedded controllers may be found in many different kinds of systems and are used for many different applications
Manufacturing and process control: Water and sewage systems Power stations Power grid systems Simulators Construction industry: Surveying and location equipment Construction plant Transport: Aero planes Trains Buses Marine craft Automobiles Fuel services Air Traffic Control Systems Traffic lights Car parking and other meters Buildings and premises: Lifts, elevators, escalators Security systems Security cameras Safes and vaults Door locks Communications: Telephone exchange Cable systems Telephone switches

Satellites Mobile telephones Banking, finance and commercial: Automated teller systems Credit card systems Medical and life support: Heart defibrillators Pacemaker monitors X-ray equipment Testing, monitoring and diagnostic systems: Energy metering Environmental-monitoring equipment

This system is designed around a soft microcontroller AT89C51. This system basically consists of a) Power Supply b) Max 232 c) ULN 2003 d) Oscillatory Circuit e) Stepper Motors - For generating the required power to the circuit setup - For serial communication - For Interfacing with the stepper motors - For providing the delay - For open the door

2.6 Microcontrollers:
2.6.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 because they are designed to execute only a single specific task to control a single system, they are much smaller and simplified so that they can include all the functions required on a single chip. A microcontroller differs from a microprocessor, which is a general-purpose chip that is used to create a multi-function computer or device and requires multiple chips to handle various tasks. A microcontroller is meant to be more self-contained and independent, and functions as a tiny, dedicated computer. The great advantage of microcontrollers, as opposed to using larger microprocessors, is that the parts-count and design costs of the item being controlled can be kept to a minimum. They are typically designed using CMOS (complementary metal oxide semiconductor) technology, an efficient fabrication technique that uses less power and is more immune to power spikes than other techniques.

There are also multiple architectures used, but the predominant architecture is CISC (Complex Instruction Set Computer), which allows the microcontroller to contain multiple control instructions that can be executed with a single macro instruction. Some use a RISC (Reduced Instruction Set Computer), architecture, which implements fewer instructions, but delivers greater simplicity and lower power consumption.

2.6.2 Microcontroller vs Microprocessor:


A microcontroller is meant to be more self-contained and independent, and functions as a tiny, dedicated computer than microprocessor. The microcontroller may function as a computer with addition of external digital parts; the microprocessor must have many additional parts to be operational. Most microprocessors have many operational codes (opcodes) for moving data from external memory to the CPU; microcontrollers may have one or two. Microcontrollers are designed by using CMOS (complementary metal oxide semiconductor) technology, an efficient fabrication technique that uses less power and is more immune to power spikes than other techniques.

2.6.3 Advantages of Microcontroller:


Their powerful, cleverly chosen electronics is able to control a variety of processes and devices (industrial automatics, voltage, temperature, engines, etc) independently or by means of I/O instruments such as switches, buttons, sensors, LCD screens, relays etc.

2.6.4 Types of 8051 Microcontrollers:


The 8051 has the widest range of variants of any embedded controller on the market. The smallest device is the Atmel 89c1051, a 20 Pin FLASH variant with 2 timers, UART, 20mA. The fastest parts are from Dallas, with performance close to 10 MIPS! The most powerful chip is the Infineon Technologies 80C517A, with 32 Bit ALU, 2 UARTS, 2K RAM, PLCC84 package, 8 x 16 Bit PWMs, and other features.

Among the MAJOR manufacturers are:


AMD Atmel Signal Dallas Intel ISSI Enhanced 8051 parts (no longer producing 80x51 parts) FLASH and semi-custom parts Fastest 8051 with Flash with 12-bit 1LSB A/D. 20MHz internal clock Fast variant. Also battery backed 8051 through 80C51 GB / 80C51S1. They invented the 8051 IS80C51/31 runs up to 40MHz

Matra OKI Philips Infineon SMC SSI

80C154, low voltage static variants 80C154, mask parts 87C748 through 89C588, mostly old legacy 8051 parts from Signetics 80C501 through 80C517A, and a wide variety of CAN devices. COM20051 with ARCNET token bus network engine 80x52, 2 x HDLC variant for MODEM use

2.6.5 Features:
Compatible with MCS-51 Products 4K Bytes of In-System Reprogrammable Flash Memory Endurance: 1,000 Write/Erase Cycles Fully Static Operation: 0 Hz to 24 MHz Three-level Program Memory Lock 128 x 8-bit Internal RAM 32 Programmable I/O Lines Two 16-bit Timer/Counters Six Interrupt Sources Programmable Serial Channel

2.7 Microcontroller 89C51:


2.7.1 Introduction:
The secure microcontroller family is a line of 8051-compatile device that use nonvolatile (NV) RAM rather than ROM for program storage. NV RAM allows the design of a soft microcontroller that provides many unique features for embedded system designers. The enhanced security features employed by the secure microcontroller family protect the userapplication software against piracy and tempering. These devices offer varying degrees of security, ranging from simple access prevention to a full encryption of program and date memory of the device. Attempts to gain access to protected information result in the self-destruction of all data. The secure microcontroller family is the heart of a wide range of critical applications such as electronic banking, commercial transactions, and pay-TV access control, or any application that requires the protection of proprietary software and algorithms. The secure microcontroller family is divided between chips and modules. The chips are monolithic microprocessors that connect to a standard SRAM and lithium battery in a preassembled, pretested module. Depending on the special configuration, modules are available in either encapsulated DIP or SIMM module format.

In Addition to NV RAM, Dallas semiconductors offer a number of peripherals that simply reduce the cost of embedded systems. Although the specific features of each chip or module vary, all devices offer the following basic features set: 100% code-compatible with 8051 Directly addresses 64 KB program/64KB data memory. Non volatile memory control circuitry. 10-years data retention in the absence of power In-system reprogramming via serial port. 128 bytes fast access scratchpad RAM Two 16 bit general-purpose timer/counters One UART Five interrupts with two external Dedicated memory bus, preserving four 8-bit ports for general purpose I/O Power-fail reset Early warning power-fail interrupts. Watchdog timer.

ALU ACCUMULATOR REGISTERS

TIMER/COUNTER

I/O PORTS I/O PORTS INTERNAL

INTERNAL RAM STACK POINTER

INTERNAL ROM

CIRCUITS CLOCK CIRCUIT

PROGRAM COUNTER
2.1 Functional Block Diagram of Microcontroller

Most microcontrollers will also combine other devices such as: A Timer module to allow the microcontroller to perform tasks for certain time periods. A serial I/O port to allow data to flow between the microcontroller and other devices such as a PC or another microcontroller. An ADC to allow the microcontroller to accept analogue input data for processing.

Fig 2.2 Microcontroller Block Diagram.

2.7.2 Description:
The AT89C51 is a low-power, high-performance CMOS 8-bit microcomputer with 4K bytes of Flash programmable and erasable read only memory (PEROM). The device is manufactured using Atmels high-density nonvolatile memory technology and is compatible with the industry-standard 80C51 and 80C52 instruction set and pin out.

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 Flash on a monolithic chip, the Atmel AT89C51 is a powerful microcomputer, which provides a highly flexible and cost-effective solution to many embedded control applications. The AT89C51 provides the following standard features: 4K bytes of Flash, 128 bytes of RAM, 32 I/O lines, two 16-bit timer/counters, a six-vector two-level interrupt architecture, a full-duplex serial

port(UART) which operates at 11.0592 MHz, on-chip oscillator, and clock circuitry. In addition, the AT89C51 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 Powerdown mode saves the RAM contents but freezes the oscillator, disabling all other chip functions until the next hardware reset.

2.7.3 Features:
8 bit 8051-compatible microcontroller adapts to task at hand. 8 or 32 k bytes of nonvolatile RAM for program and /or data memory storage. Initial downloading software in end system via on chip serial port. Capable of modifying its own program and/or date memory in end use. Crash proof operation: Maintains all nonvolatile resources for 10 years in the absence of VCC. Power-Fail Reset. Early Warning power-Fail Interrupt. Watchdog Timer. Software security feature: Executes encrypted software to prevent unauthorized disclosure. On-chip, full-duplex serial I/O ports. Two on-chip timer/events counter 32 parallel I/O lines. Compatible with industry standard 8051 instruction set and pin out. Optional permanently powered real timer clock.

2.7.4 Microcontroller Architecture:


The secure microcontroller family is based on an 8051-compatible core with a memory interface and I/O logic build around it. In general, most architecture features are identical to standard 8051s and apply to all members of the secure microcontroller family. Differences between versions are mentioned. This section briefly documents the important features. Figure 3.1 shows a block diagram of the microcontroller core. Users interested in a more though explanation of the 8051 architecture is referred to any of the numerous texts on the subject.

Fig 2.3 Microcontroller Architecture

Bus Organization
There are four major buses in the secure microprocessor: the internal data bus, the internal address bus, the byte wide memory bus, and the expanded bus. All addresses and data that are transferred during program execution are passed on the internal address and data buses. User program and data memory is always accessed from either the byte wide program/data RAM or from external memory located on the expanded bus. The byte wide memory bus allows access memory located on the expanded bus. The byte wide memory bus allows access to program/data RAM in the sane way as an 8051 family device would access internal ROM or EPROM memory.

This bus can be used in place of the expanded bus, freeing Port2 and Port0 pins for general I/O use. CPU Registers: The CPU registers are mapped as special function registers (SFRs). They are identical in number and function to those prevents within the 8051. These registers are described briefly. Accumulator: The accumulator (A or ACC) is used as either a source and/or destination register in all arithmetic instructions. It may also be sued in most other types of instructions. Stack Pointer: The stack pointer (SP) is an 8 bit register that marks the location of the last byte of data stored in the stack. The stack itself can be located anywhere in the on-chip 128 byte scratchpad register area. The stack pointer pre-increments during a stack push and post-decrements during a stack pop. Program Status Word: The Program status word (PSW) contains status flags that are set according to the results of a previously executed instruction. In addition, the PSW contains register bank select bits. Data Pointer: The Data pointer (DPTR) is used to access data memory that can be mapped into byte wide data RAM or onto external memory devices on the expanded bus. The DPTR is accessed by the users program as either two 8 bit SFRs or as a 16-bit register with certain instructions. Programmable Timers: Two 16 bit programmable timers are included that can perform various timing and counting functions. Four registers (TH1, TL1, TH0 and TL0) access the upper and lower halves of each of the two timer/counters. A single control register (TCON) is used to select the various operating modes of the two timers. Two external I/O pins (P3.4, P3.5) can be programmed to serve as external counter inputs, one pin for each of the two timer/counters. Parallel I/O: Four SFRs provide access for the four parallel I/O port latches. These I/O ports are denoted as P0, P1, P2 and P3. 32 bits of parallel I/O is available through these I/O ports. However, up to 16 bits are sacrificed when the expanded bus mode is used to interface to

external memory and up to 6 bits can be sacrificed if any external interrupt inputs, timer counter inputs, or serial I/O functions are used. When using the byte wide bus, ports are not affected. Atmel At89c51 Pin out and Description: The smallest current device is the ATMEL 89c51, a 40 Pin FLASH variant with 2 timers, UART, 500mA. ATMEL was the first with standard FLASH, and with more program cycles than other custom FLASH. These parts compete with OTP and MASK product on price, but eliminate inventory problems and the hidden costs of OTP development. Why we go for AT89C51? The AT89C51 is a low power, high performance CMOS 8-bit microcontroller with 4Kbytes of Flash programmable and erasable read only memory (PEROM). This device is compatible with the industry standard 8051 instruction set and pin out. The on-chip Flash allows the program memory to be quickly reprogrammed using a nonvolatile memory programmer such as the PG302 (with the ADT87 adapter). By combining an industry standard 8-bit CPU with Flash on a monolithic chip, the 8951 is a powerful microcomputer which provides a highly flexible and cost effective solution to many embedded control applications.

2.7.5 Features of AT89C51:


1. It is a 8-bit microcontroller. 2. It has a flash memory of 4KB for storing the program. 3. It has RAM of 128 bytes. 4. It has 32 I/O ports. -Port 0 (pin 39 to pin 32). -Port 1 (pin 1 to pin 8). -Port 2 (pin 21 to pin 28). -Port 3 (pin 10 to pin 17). 5. It has four register banks. 6. It has two 16-bit timers. -Timer 0

-Timer 1 7. It has full duplex asynchronous serial port. 8. It can support up to 64KB of external memory with the help of PC and DPTR. 9. It has 16-bit address bus. 10. Six interrupts with two priority levels -2 general purpose interrupts (INT0, INT1). -4 preprogrammed interrupt (Timer0, Timer1, Serial interrupt, Reset interrupt). 11. Wide range of frequency of operation (0 to 24 MHz). 12. It will operate on 5V dc supply. 13. It can support maximum of 500mA of current.

In addition, the 89C51 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 hardware reset.

2.7.6 Pin Description:


18: Port 1: Each of these pins can be used as either input or output. Also, pins 1 and 2 (P1.0 and P1.1) have special functions associated with Timer 2. 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 anew 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. The image shows one simple circuit for safe reset upon starting the controller.

Fig 2.4 Microcontroller Pin Diagram.

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.

Fig 2.5 Microcontroller Reset circuit

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 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 (see the image) are not critical and are normally about 30pF. New MCUs work at frequencies from 0Hz to 50MHz+.

Fig 2.6 Clock Circuit

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, then these pins serve as the location of the higher address byte, i.e. addresses A8 A15. It is important to note that 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. 30: ALE: Before each reading of the external memory, MCU sends the lower byte of the address register (addresses A0 A7) to port P0 and activates the output ALE. External register (74HCT373 or 74HCT375 circuits are common), memorizes the state of port P0 upon receiving a signal from ALE pin, and uses it as part of the address for memory chip. During the second part of the mechanical MCU cycle, signal on ALE is off, and port P0 is used as Data Bus. In this way, by adding only one cheap integrated circuit, data from port can be multiplexed and the port simultaneously used for transferring both addresses and data. 31: EA: Bringing this pin to the logical state zero 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

2.7.7 Input Output (I/O) Ports


Every MCU from 8051 family has 4 I/O ports of 8 bits each. This provides the user with 32 I/O lines for connecting MCU to the environs. Port 0 Port 0 has two fold role: if external memory is used, it contains the lower address byte (A0-A7), otherwise all bits of the port are either input or output. Another feature of this port comes to play when it has been designated as output. Port 0 lacks the "pull up" resistor (resistor with +5V on one end). Therefore, to get one (5V) on the output, external "pull up" resistor needs to be added for connecting the pin to the positive pole. Port 1 This is "true" I/O port, devoid of dual function characteristic for Port 0. Having the "pull up" resistor, Port 1 is fully compatible with TTL circuits. Port 2 When using external memory, this port contains the higher address byte (addresses A8 A15). Otherwise, it can be used as universal I/O port.

Port 3 Beside its role as universal I/O port, each pin of Port 3 has an alternate function. In order to use one of these functions, the pin in question has to be designated as input, i.e. the appropriate bit of register P3 needs to be set. From a hardware standpoint, Port 3 is similar to Port 0.

2.7.8 Memory in 8051 Microcontroller


The 8051 has three very general types of memory. The memory types are illustrated in the following figure: On-Chip Memory, External Code Memory, and External RAM.

Fig 2.7 Memory Block Diagram.

On-Chip Memory refers to any memory (Code, RAM, or other) that physically exists on the microcontroller itself. External Code Memory is code (or program) memory that resides off-chip. This is often in the form of an external EPROM. External RAM is RAM memory that resides off-chip. This is often in the form of standard static RAM or flash RAM. During the runtime, microcontroller 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). ROM memory In this MCU contain 4 kilobytes of the flash memory on the chip. It is of EEPROM. We can use 12v to program MCU. This option is cost-effective only for large series. The main purpose of ROM is to store the programs to be executed.

RAM memory
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 FFh) 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 as can be seen in the following figure.

Fig 2.8 RAM Memory.

The main purpose of RAM is to provide synchronization between ROM and CPU so as to increase the speed of microcontroller. Bit Memory The 8051, being a communications-oriented microcontroller, gives the user the ability to access a number of bit variables. These variables may be either 1 or 0. There are 128 bit variables available to the user, numbered 00h through 7Fh. Special Function Register (SFR) Memory Special Function Registers (SFRs) are areas of memory that control specific functionality of the 8051 processor. It may appear that SFR is part of Internal Memory. However, when using this method of memory access (its called direct address), any instruction that has an address of 00h through 7Fh refers to an Internal RAM memory address; any instruction with an address of 80h through FFh refers to an SFR control register. Register Banks General Purpose registers:

The 8051 uses 8 "R" registers which are used in many of its instructions. These "R" registers are numbered from 0 through 7 (R0, R1, R2, R3, R4, R5, R6, and R7). These registers are generally used to assist in manipulating values and moving data from one memory location to another. SFR Registers (Special Function Registers) SFR registers can be seen as a sort of control panel for managing and monitoring the microcontroller.

Fig 2.9 Special Function Registers.

Timers: The 8051 comes equipped with two timers, both of which may be controlled, set, read, and configured individually. The 8051 timers have three general functions:

1) Keeping time and/or calculating the amount of time between events, 2) Counting the events themselves, or 3) Generating baud rates for the serial port.

2.7.9 Using Timers To Measure Time


Obviously, one of the primary uses of timers is to measure time. When a timer is used to measure time it is also called an "interval timer" since it is measuring the time of the interval between two events. . Timer SFRs The 8051 has two timers which each function essentially the same way. One timer is TIMER0 and the other is TIMER1. The two timers share two SFRs (TMOD and TCON) which control the timers, and each timer also has two SFRs dedicated solely to itself (TH0/TL0 and TH1/TL1). An SFR has a numeric address. It is often useful to know the numeric address that corresponds to an SFR name. When you enter the name of an SFR into an assembler, it internally converts it to a number. The TMOD SFR (Timer Mode): The TMOD SFR is used to control the mode of operation of both timers. Each bit of the SFR gives the microcontroller specific information concerning how to run a timer. The high four bits (bits 4 through 7) relate to Timer 1 whereas the low four bits (bits 0 through 3) perform the exact same functions, but for timer 0. The individual bits of TMOD have the following functions: Bit Name Explanation of Function When this bit is set the timer will only run when INT1 7 GATE1 (P3.3) is high. When this bit is clear the timer will run 1 regardless of the state of INT1. Timer

When this bit is set the timer will count events on T1 6 C/T1 (P3.5). When this bit is clear the timer will be 1 incremented every machine cycle. 5 4 T1M1 T1M0 Timer mode bit (see below) Timer mode bit (see below) When this bit is set the timer will only run when INT0 3 GATE0 (P3.2) is high. When this bit is clear the timer will run 0 regardless of the state of INT0. When this bit is set the timer will count events on T0 2 C/T0 (P3.4). When this bit is clear the timer will be 0 incremented every machine cycle. 1 0 T0M1 T0M0 Timer mode bit (see below) Timer mode bit (see below) 0 0 1 1

Four bits (two for each timer) are used to specify a mode of operation. The modes of operation are: TxM1 0 0 1 TxM0 0 1 0 Timer Mode 0 1 2 Description of Mode 13-bit Timer. 16-bit Timer 8-bit auto-reload

Split timer mode

The TCON SFR There is one more SFR that controls the two timers and provides valuable information about them. The TCON SFR has the following structure: TCON (88h) SFR Bit Address

Bit Name

Explanation of Function

Timer

TF1

8Fh

Timer 1 Overflow. This bit is set by the microcontroller when Timer 1 overflows. Timer 1 Run. When this bit is set Timer 1 is turned on. When this bit is clear Timer 1 is off. Timer 0 Overflow. This bit is set by the microcontroller when Timer 0 overflows.

TR1 8Eh

TF0

8Dh

TR0 8Ch

Timer 0 Run. When this bit is set Timer 0 is turned on. When this bit is clear Timer 0 is off.

Only four bits of SFR are used for timers, the remaining four are used for interrupts.

Interfaces: The digital I/O ports are the means by which the microcontroller interfaces to the environment. Digital I/O tends to be grouped into byte wide ports (8 digital bits) that can be configured as either input bits or output bits.

Fig 2.10 Types of AT89C51 Microcontroller

3. ZIGBEE WIRELESS COMMUNICATION

3.1 Introduction:
ZigBee is an established set of specifications for wireless personal area networking (WPAN), i.e. digital radio connections between computers and related devices. WPAN Low Rate or ZigBee provides specifications for devices that have low data rates consume very low power and are thus characterized by long battery life. ZigBee makes possible completely networked homes where all devices are able to communicate and be controlled by a single unit. The ZigBee Alliance, the standards body which defines ZigBee, also publishes application profiles that allow multiple OEM vendors to create interoperable products. The current list of application profiles either published or in the works are: Home Automation ZigBee Smart Energy Telecommunication Applications Personal Home The relationship between IEEE 802.15.4 and ZigBee is similar to that between IEEE 802.11 and the Wi-Fi Alliance. For non-commercial purposes, the ZigBee specification is available free to the general public. An entry level membership in the ZigBee Alliance, called Adopter, costs US$ 3500 annually and provides access to the as-yet unpublished specifications and permission to create products for market using the specifications. ZigBee is one of the global standards of communication protocol formulated by the relevant task force under the IEEE 802.15 working group. The fourth in the series, WPAN Low Rate/ZigBee is the newest and provides specifications for devices that have low data rates, consume very low power and are thus characterized by long battery life. Other standards like Bluetooth and IrDA address high data rate applications such as voice, video and LAN communications. ZigBee devices are actively limited to a throughrate of 250Kbps, compared to Bluetooth's much larger pipeline of 1Mbps, operating on the 2.4 GHz The specified maximum range of operation for ZigBee devices is 250 feet (76m), substantially further than that used by Bluetooth capable devices, although security concerns raised over "sniping" Bluetooth devices remotely, may prove to hold true for ZigBee devices as well. Due to its low power output, ZigBee devices can sustain themselves on a small battery for many months, or even years, making them ideal for install-and-forget purposes, such as most small household systems. Predictions of ZigBee installation for the future, most based on the explosive use of ZigBee in automated household tasks in China, look to a near future when upwards of sixty ZigBee devices may be found in an average American home, all communicating with one another freely and regulating common tasks seamlessly.

The ZigBee Alliance has been set up as an association of companies working together to enable reliable, cost-effective, low-power, wirelessly networked, monitoring and control products based on an open global standard. Once a manufacturer enrolls in this Alliance for a fee, he can have access to the standard and implement it in his products in the form of ZigBee chipsets that would be built into the end devices. Philips, Motorola, Intel, HP are all members of the Alliance. The goal is to provide the consumer with ultimate flexibility, mobility, and ease of use by building wireless intelligence and capabilities into every day devices. ZigBee technology will be embedded in a wide range of products and applications across consumer, commercial, industrial and government markets worldwide. For the first time, companies will have a standards based wireless platform optimized for the unique needs of remote monitoring and control applications, including simplicity, reliability, low cost and low-power.

3.2 ZIGBEE Characteristics:


The focus of network applications under the IEEE 802.15.4 / ZigBee standard include the features of low power consumption, needed for only two major modes (Tx/Rx or Sleep), high density of nodes per network, low costs and simple implementation. These features are enabled by the following characteristics, 2.4GHz and 868/915 MHz dual PHY modes. This represents three license-free bands: 2.42.4835 GHz, 868-870 MHz and 902-928 MHz. The number of channels allotted to each frequency band is fixed at sixteen (numbered 11-26), one (numbered 0) and ten (numbered 1-10) respectively. The higher frequency band is applicable worldwide, and the lower band in the areas of North America, Europe, Australia and New Zealand. Low power consumption, with battery life ranging from months to years. Considering the number of devices with remotes in use at present, it is easy to see that more numbers of batteries need to be provisioned every so often, entailing regular (as well as timely), recurring expenditure. In the ZigBee standard, longer battery life is achievable by either of two means: continuous network connection and slow but sure battery drain, or intermittent connection and even slower battery drain. Maximum data rates allowed for each of these frequency bands are fixed as 250 kbps @2.4 GHz, 40 kbps @ 915 MHz, and 20 kbps @868 MHz. High throughput and low latency for low duty cycle applications (<0.1%) Channel access using Carrier Sense Multiple Access with Collision Avoidance (CSMA - CA)

Addressing space of up to 64 bit IEEE address devices, 65,535 networks. 50m typical range Fully reliable hand-shaked data transfer protocol. Different topologies as illustrated below: star, peer-to-peer, mesh

PAN Coordinator

Full Function Device Reduced Function Device

Star Topology

Communications Flow

Peer to Peer topology


Full function device
Figure 3.1 ZigBee topologies.

Cluster Tree Topology


Communications flow

3.3 Frame Structure:


The frame structures have been designed to keep the complexity to a minimum while at the same time making them sufficiently robust for transmission on a noisy channel. Each successive protocol layer adds to the structure with layer-specific headers and footers. The IEEE 802.15.4 MAC defines four frame structures: A beacon frame, used by a coordinator to transmit beacons. A data frame, used for all transfers of data. An acknowledgment frame, used for confirming successful frame reception. A MAC command frame, used for handling all MAC peer entity control transfers.

1
2 The data frame is illustrated below:

Figure 3.2 Data Frame of zigbee

The Physical Protocol Data Unit is the total information sent over the air. As shown in the illustration above the Physical layer adds the following overhead: Preamble Sequence Start of Frame Delimiter Frame Length 4 Octets 1 Octet 1 Octet

The MAC adds the following overhead: Frame Control 2 Octets

Data Sequence Number Address Information Frame Check Sequence

1 Octet 4 20 Octets 2 Octets

In summary the total overhead for a single packet is therefore 15 -31 octets (120 bits); depending upon the addressing scheme used (short or 64 bit addresses). Please note that these numbers do not include any security overhead.

Super Frame Structure


The LR-WPAN standard allows the optional use of a superframe structure. The format of the superframe is defined by the coordinator. The superframe is bounded by network beacons, is sent by the coordinator (See Figure 4) and is divided into 16 equally sized slots. The beacon frame is transmitted in the first slot of each superframe. If a coordinator does not wish to use a superframe structure it may turn off the beacon transmissions. The beacons are used to synchronize the attached devices, to identify the PAN, and to describe the structure of the superframes. Any device wishing to communicate during the contention access period (CAP) between two beacons shall compete with other devices using a slotted CSMA-CA mechanism. All transactions shall be completed by the time of the next network beacon.

Figure 3.3 Superframe

For low latency applications or applications requiring specific data bandwidth, the PAN coordinator may dedicate portions of the active superframe to that application. These portions are called guaranteed time slots (GTSs). The guaranteed time slots comprise the contention free period (CFP), which always appears at the end of the active superframe starting at a slot boundary immediately following the CAP, as shown in Figure 5. The PAN coordinator may allocate up to seven of these GTSs and a GTS may occupy more than one slot period. However, a sufficient portion of the CAP shall remain for contention based access of other networked devices or new devices wishing to join the network. All contention based transactions shall be complete before the CFP begins. Also each device transmitting in a GTS shall ensure that its transaction is complete before the time of the next GTS or the end of the CFP.

Figure 3.4 Frame with contention free period.

4. HARDWARE DESIGN

4.1 Block Diagram:


4.1.1 Transmitter Side:

BLOCK DIAGRAM

ULN 2003 RESET CIRCUIT

MOTOR MOTOR

BUZZER ATMEL 89C51 CONTROLLER

FIRE ALARM SENSOR


BURGLAR

OSCILLATORY CIRCUIT

M AX 23 2 circ uit

ZIGBEE

Figure 4.1 Transmitter Side Block Diagram

4.1.2 Receiver Side:

BLOCK DIAGRAM

RESET CIRCUIT
BUZZER ATMEL 89C51 CONTROLLER

LCD

OSCILLATORY CIRCUIT

M AX 23 2 circ uit

ZIGBEE

Figure 4.2 Block Diagram of Receiver

4.2 Power Supply:


Circuit Description:
Any invention of latest technology cannot be activated without the source of power. So in this fast moving world we deliberately need a proper power source which will be apt for a particular requirement. All the electronic components starting from diode to is only work with a DC supply ranging from 5V to 12V.We are utilizing for the same, the cheapest and commonly available energy source of 230V-50Hz and stepping down, rectifying, filtering and regulating the voltage. The power requirement for various components differs from one component to another. For example the microcontroller needs a 5 volts DC where as the motors circuit requires 12 volts DC. All the components are provided with their respective power requirements by the power supply circuit employing the bridge circuit , voltage regulator 7812 and 7805 as illustrated in the below circuit diagram. The bridge converts the 12volts ac to pulsating dc and the voltage regulators 7812 and 7805 are used to achieve the required 5v dc. The capacitors are used for filtering action, that is, they tend to minimize the ripples present in the voltage.

Fig. 4.2 Power supply circuit

Transformer
A bridge rectifier coupled with a step down transformer is used for our design. The voltage rating of transformer used is 0-12V and the current rating is 500mA. When AC voltage of 230V is applied across the primary winding an output AC voltage of 12V is obtained. One alteration of input causes the top of transformer to be positive and the bottom negative. The next alteration will temporarily cause the reverse.

Rectifier

In the power supply unit, rectification is normally achieved using a solid state diode. Diode has the property that will let the electron flow easily at one direction at proper biasing condition. Bridge rectifiers of 4 diodes are used to achieve full wave rectification. Two diodes will conduct during the negative cycle and the other two will conduct during the positive half cycle.

Filtering unit
Filter circuit which is usually a capacitor acts as a surge arrester always follows the rectifier unit. This capacitor is also called as a decoupling capacitor or a bypass capacitor, is used not only to short the ripple with frequency to ground but also leave the frequency of the DC to appear at the output.

Regulators
The voltage regulators play an important role in any power supply unit. The primary purpose of a regulator is to aid the rectifier and filter circuit in providing a constant DC voltage to the device. Power supplies without regulators have an inherent problem of changing DC voltage values due to variations in the load or due to fluctuations in the AC line voltage. With a regulator connected to DC output, the voltage can be maintained within a close tolerant region of the desired output. IC 7805 and 7812 regulators are used in this project for providing a DC voltage of +5V and +12V respectively.

Light Emitting Diodes (LEDs)


There are many colors of LEDs of which red LEDs are of high intensity.

4.3 Serial Communication


All IBM PC and compatible computers are typically equipped with two serial ports and one parallel port. Although these two types of ports are used for communicating with external devices, they work in different ways.

Bi- Directional Communication


The serial port on PC is a full-duplex device meaning that it can send and receive data at the same time. In order to be able to do this, it uses separate lines for transmitting and receiving data.

Some types of serial devices support only one-way communications and therefore use only two wires in the cable - the transmit line and the signal ground.

Communication by Bits
Once the start bit has been sent, the transmitter sends the actual data bits. There may either be 5, 6, 7, or 8 data bits, depending on the number selected. Both receiver and the transmitter must agree on the number of data bits, as well as the baud rate. Almost all devices transmit data using either 7 or 8 data bits.

4.4 Synchronous and Asynchronous Communication


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

9 Pin Connector on a DTE device (PC connection) Male DB9 RS232

Pin Number

Direction of signal:

1 2 3 4 5 6 7 8 9

Carrier Detect (CD) (from DCE) Incoming signal from a modem Received Data (RD) Incoming Data from a DCE Transmitted Data (TD) Outgoing Data to a DCE Data Terminal Ready (DTR) Outgoing handshaking signal Signal Ground Common reference voltage Data Set Ready (DSR) Incoming handshaking signal Request To Send (RTS) Outgoing flow control signal Clear To Send (CTS) Incoming flow control signal Ring Indicator (RI) (from DCE) Incoming signal from a modem

The TD (transmit data) wire is the one through which data from a DTE device is transmitted to a DCE device. The TD line is kept in a mark condition by the DTE device when it is idle. The RD (receive data) wire is the one on which data is received by a DTE device, and the DCE device keeps this line in a mark condition when idle .RTS stands for Request To Send. This line and the CTS line are used when "hardware flow control" is enabled in both the DTE and DCE devices. The DTE device puts this line in a mark condition to tell the remote device that it is ready and able to receive data. If the DTE device is not able to receive data (typically because its receive buffer is almost full), it will put this line in the space condition as a signal to the DCE to stop sending data. The complement of the RTS wire is CTS, which stands for Clear To Send. The DCE device puts this line in a mark condition to tell the DTE device that it is ready to receive the data. Likewise, if the DCE device is unable to receive data, it will place this line in the space condition. Together, these two lines make up what is called RTS/CTS or "hardware" flow control.

DTR stands for Data Terminal Ready. Its intended function is very similar to the RTS line. DSR (Data Set Ready) is the companion to DTR in the same way that CTS is to RTS. Some serial

devices use DTR and DSR as signals to simply confirm that a device is connected and is turned on. CD stands for Carrier Detect. Carrier Detect is used by a modem to signal that it has a made a connection with another modem, or has detected a carrier tone.

RI or Ring Indicator. A modem toggles the state of this line when an incoming call rings your phone. The Carrier Detect (CD) and the Ring Indicator (RI) lines are only available in connections to a modem.

4.5 Driver for Serial Communication


Introduction
Serial RS-232 communication works with voltages (-15V ... -3V for high) and +3V ... +15V for lo]) which are not compatible with normal computer logic voltages. On the other hand, microcontroller operates between 0V ... +5V. Therefore, to receive serial data from an RS-232 interface the voltage has to be reduced RS-232 C Logic

-----------------------------------------------15V ... -3V <-> 0V <-> low

+3V ... +15V <-> 5V <-> high

4.5.1 RS 232
RS-232 stands for Recommend Standard number 232. The full RS-232C standard specifies a 25pin "D" connector of which 22 pins are used. Most of these pins are not needed for normal PC communications, and indeed, most new PCs are equipped with male D type connectors having only 9 pins.

RS-232 Level Converters

Almost all digital devices required either TTL or CMOS logic levels. Therefore the first step to connecting a device to the RS-232 port is to transform the RS-232 levels back into 0 and 5 Volts, this is done by RS-232 Level Converters.

4.5.2 MAX 232

Fig. 4.3 Pin Diagram of MAX232

It includes a Charge Pump, which generates +10V and -10V from a single 5v supply. This I.C. also includes two receivers and two transmitters in the same package. This is handy in many cases when you only want to use the Transmit and Receive data Lines. You don't need to use two chips, one for the receive line and one for the transmit. However all this convenience comes at a price, but compared with the price of designing a new power supply it is very cheap.

Fig 4.4 Typical MAX-232 Circuit.

4.6 Drivers for Relay


We have used ULN2003 driver in our project to interface with the stepper motor required for the automatic opening of the door of the industry when authorized person enters.

Features of ULN2003:
1. 2. 3. 4. ULN2003 is a 16 bit IC It is of Darlington pair amplifier (1 to 1000) 1.2 Amps current is supported. It gives inverted output.

Reasons for Using ULN2003 DRIVER


This driver is used to avoid back EMF and protect circuit from back EMF. It also provides current amplification. General microcontroller supports current up to 500mA but some motors require 600mA. In order to achieve this we need current amplification.

I-Inverter, A-Darlington pair of amplifier


Fig 4.5 ULN2003 circuit diagram

Description The ULN2001A,ULN2002A,ULN2003A,ULN2004A are monolithic high-voltage, high-current Darlington transmitter, each consist of seven Darlington pairs that feature high-voltage output with common-cathode clamp diodes for switching inductive load. The collector-current rating of a single Darlington pair is 500mA. The Darlington pair may be paralleled for higher current capability applications include relay drivers, hammer driver, lamp drivers, display drivers (LED & gas discharge), line driver & logic buffers. For 100-V (otherwise inter chargeable) versions, see the SN75465 through SN75469. The ULN2001A is a general-purpose array and can be used with TTL and CMOS techniques. The ULN2002A is specifically designed for use with 14 to 25v PMOS devices. Each input of this device has a Zener diode and resistor in series to control the input current to a safe limit. The ULN2003A has a 2.7kohms series based resistor for each Darlington pair for operation directly with TTL or 5v CMOS devices. The ULN2004A has a 10.5k ohms series based resistor to allow its operation directly from CMOS devices they use supply voltages of 6 to 15 volts. The required input current of the ULN2004A is below that of the ULN2003A, and the required voltage is less than that required by the ULN2002A.

Relay The relay is an electromagnetic device which energies when the supply is given. Relay circuit is used to activate the relay through microcontroller. The relay is an electromagnetic device which energies when the supply is given. Relay circuit is used to activate the relay through microcontroller. That means when the microcontroller gives high to the relay circuit the switched on and also the relay is ON. Darlington transistor is

When the microcontroller gives low to the relay circuit the Darlington transistor is switched off and also the relay is OFF. In this circuit we have to use a Darlington transistor (Tip122) for switch on the relay.

Relay Circuit

Fig 4.6 Relay circuit

4.7 ZigBee Module: Tarang


Tarang modules are designed with low to medium transmit power and for high reliability wireless networks. The modules require minimal power and provide reliable delivery of data between devices. The interfaces provided with the module help to directly fit into many industrial applications. The modules operate within the ISM 2.4-2.4835 GHz frequency band with IEEE 802.15.4 baseband.

Features
Range - Outdoor line of sight: up to 50kms with directional antenna. Transmit Power: up to 1 watt / 30 dBm nominal. Receiver Sensitivity: up to 107 dBm. AT Command Modes for configuring Module Parameters Direct sequence spread spectrum technology. Analog to digital conversion and digital I/O line support.

TarangNet Features
Acknowledgement

mode communication with retries

Each direct sequence channel has 64K unique network addresses. Source / destination addressing. Unicast and broadcast communication. Point to point, point to multi point and peer-to-peer topologies are possible.

4.8 Buzzer:
Buzzer is a transducer, which produces sound signal to the corresponding electric signal. The switching operation of the buzzer is controlled by using microcontroller. the buzzer draws more current while it is operating so by using 2N2222 fast switching transistor we directly operate the buzzer by using microcontroller. The connection of the buzzer is as shown below,

Figure 4.7 Buzzer Circuit.

When output pin of the microcontroller is high, then 2N2222 goes to saturation, then buzzer gets operated. Whenever output pin of the microcontroller is low the buzzer stops operating.

4.9 LCD Display

Figure 4.8 LCD Display

5. SOFTWARE

5.1 Keil Software:


Keil Software provides you with software development tools for the 8051 family of microprocessors. With the Keil tools, you can generate embedded applications for multitude of 8051 derivatives. Throughout this project we refer to these tools as the 8051 development tools. However, they support all derivatives and variants of the 8051microcontrollerFamily.

The Keil Software 8051 development tools listed below are the programs used to compile your C code, assemble your assembler source files, link your program together, create HEX files, and debug your target program.

Vision2 for Windows Integrated Development Environment: combines project Management, Source Code Editing, and Program Debugging in one powerful environment. C51 ANSI Optimizing C Cross Compiler: creates relocatable object modules from your C source code, A51 Macro Assembler: creates re locatable object modules from your 8051 assembler source code, BL51 Linker/Locator: combines relocatable object modules created by the compiler and assembler into the final absolute object module, LIB51 Library Manager: combines object modules into a library which may be used by the linker, OH51 Object-HEX Converter: creates Intel HEX files from absolute object modules, RTX-51 real-time operating system: simplifies the design of complex, time critical software projects.

They are designed for the professional software developer, but any level of programmer can use them to get the most out of the 8051 hardware.

5.2 Getting Started and Creating Application:


5.2.1Evaluation kits and Development kit:

Keil Software provides two types of kits in which our tools are delivered. The EK51 Evaluation Kit includes evaluation versions of our 8051 tools along with this users guide. The tools in the evaluation kit let you generate these applications up to 2 Kbytes in size. You may use this kit to evaluate for the effectiveness of our 8051 tools and to generate small target applications. The 8051 Production Kits discussed in Product Overview topic section, include the unlimited versions of our 8051 tools along with this users guide and the full manual set. The production kits also include 1 year of free technical support and product updates.

5.2.2 Types of Users:


This manual addresses three types of users: 1) Evaluation users 2) New users and 3) Experienced users.

Evaluation Users:
Evaluation users are those users who have not yet purchased the software but have requested the evaluation package to get a better feel for what the tools do and how they perform. The evaluation package includes evaluation tools that are limited to 2 Kbytes along with several sample programs that provide real-world applications created for the 8051 microcontroller family. Even if you are only an evaluation user, take the time to read this manual. It explains how to install the software, provides you with an overview of the development tools, and introduces the sample programs.

New Users:

New users are those users who are purchasing 8051 development tools for the first time. The included software provides you with the latest development tool technology, manuals, and sample programs. If you are new to the 8051 or the tools, take the time to review the sample programs described in this manual.

Experienced Users:
Experienced users are those users who have previously used the Keil 8051 development tools and is now upgrading to the latest version. The software included with a product upgrade contains the latest development tools and sample programs.

5.3 VISION2 Integrated Development Environment:


Vision2 is a standard Windows application. Vision2 is integrated software development platform that combines a robust editor, project manager, and make facility. Vision2 supports all of the Keil tools for the 8051 including the C compiler, macro assembler, linker/locator, and object-HEX converter. Vision2 helps expedite the development process of your embedded applications by providing the following:

Full-featured source code editor, Device Database for pre-configuring the development tool setting, Project manager for creating and maintaining your projects, Integrated make facility for assembling, compiling, and linking your embedded applications, Dialogs for all development tool settings, True integrated source-level Debugger with high-speed CPU and peripheral simulator. Advanced GDI interface for software debugging in the target hardware and for connection to Monitor-51. Links to development tools manuals, device datasheets & users guides. The Vision2 debugging features are only available in the PK51 and DK51 tool kits.

5.3.1 About the Environment:

The Vision2 screen provides you with a menu bar for command entry, a tool bar where you can rapidly select command buttons, and windows for source files, dialog boxes, and information displays. Vision2 lets you simultaneously open and view multiple source files.

5.3.2 Menu Commands, Toolbars And Shortcuts:

The menu bar provides you with menus for editor operations, project maintenance, development tool option settings, program debugging, window selection and manipulation, and on-line help. With the toolbar buttons you can rapidly execute operations. The commands can be reached also with configurable keyboard shortcuts. The following tables give you an overview of the Vision2 commands and the default shortcuts.

5.3.3 C51 Optimizing C CROSS COMPILER:


For 8051 microcontroller applications, the Keil C51 Cross Compiler offers a way to program in C which truly matches assembly programming in terms of code efficiency and speed. The Keil C51 is not a universal C compiler adapted for the 8051. It is a dedicated C compiler that generates extremely fast and compact code. The Keil C51 Compiler implements the ANSI standard for the C language. Use of a high-level language such as C has many advantages over assembly language programming: The Vision IDE from Keil, combines project management, make facilities, source code editing, program debugging, and complete simulation in one powerful environment. Vision helps you get programs working faster than ever while providing an easy-to-use development platform. The editor and debugger are integrated into a single application and provide a seamless embedded project development environment.

5.3.4 vision Provides Unique Features:

The Device Database which automatically sets the assembler, compiler, and linker options for the chip you select. This prevents you from wasting your time configuring the tools and helps you get started writing code faster. A robust Project manager which lets you create several different configurations of your target from a single project file. Only the Keil Vision IDE allows you to create an output file for simulating, an output file for debugging with an emulator, and an output file for programming an EPROM--all from the same Project file. An integrated make facility with automatic dependency generation. You don't have to figure out which header files and include files are used by which source files. The Keil compilers and assemblers do that automatically.

Interactive error correction. As you project compiles, errors and warnings appear in an output window. You may make corrections to the files in your project while Vision continues to compile in the background. Line numbers associated with each error or warning are automatically resynchronized when you make changes to the source.

The Keil 8051 Development Tools are designed to solve the complex problems facing embedded software developers. When starting a new project, simply select the microcontroller you use from the Device Database and the Vision IDE sets all compiler, assembler, linker, and memory options for you. Numerous example programs are included to help you get started with the most popular embedded 8051 devices. The Keil Vision Debugger accurately simulates on-chip peripherals (IC, CAN, UART, SPI, Interrupts, I/O Ports, A/D Converter, D/A Converter, and PWM Modules) of your 8051 device. Simulation helps you understand hardware configurations and avoids time wasted on setup problems. Additionally, with simulation, you can write and test applications before target hardware is available. When you are ready to begin testing your software application with target hardware, use the MON51, MON390, MONADI, or FlashMON51 Target Monitors, the ISD51 In-System Debugger, or the ULINK USB-JTAG Adapter to download and test program code on your target system.

5.4 Advantages:
Knowledge of the processor instruction set is not required, rudimentary knowledge of the memory structure of the 8051 CPU is desirable (but not Necessary). Details like register allocation and addressing of the various memory types and data types are managed by the compiler. Programs get a formal structure and can be divided into separate functions. This leads to better program structure. The ability to combine variable selection with specific operations improves program readability. Keywords and operational functions can be used that more nearly resemble the human thought process. Programming and program test time is drastically reduced which increases your efficiency. The C run-time library contains many standard routines such as: formatted output, numeric conversions and floating point arithmetic.

Existing program parts can be more easily included into new programs, because of the comfortable modular program construction techniques. The language C is a very portable language (based on the ANSI standard) that enjoys wide popular support, and can be easily obtained for most systems. This means that existing program investments can be quickly adapted to other processors as needed.

5.5 Using KEIL:

Step1: Open the keil window and go to project in the menu and create new project

Step2: Enter a file name for the project and save it in the required location.

Step3: Select the required device from the target.

Step4: Open a text file to write the required code

Step5: Save the text file in the required location with .asm extension

step6: Browse the required asm file and add the asm file to the target

Step7: Select the required file and build the target

Step8: Compile the code and check for any errors occurred or warnings encountered.

Step9: If no errors and warnings occurred then go to debug mode as shown

Step10: Open the required ports from the menu-peripherals-I/O ports.

Step11: Now run the code either in step-by-step mode or single step mode and check the Ports and other peripherals used in the code.

5.6 Programming The Chip:


The chip can be programmed using INTELLIGENT UNIVERSAL PROGRAMMER from Advantech, which connects to PCs parallel port. The LabTool-48UXP features a 48-pin universal pin driver and an expandable TTL pin driver, an on-board processor lets it handle todays (and tomorrows) complicated DIP-type silicon PLDs, microprocessors and high density memory chips. The LabTool-48XP is developed for both laboratory and mass-production applications. It supports over 7000 different devices, including PAL, GAL, CPLD, EPLD, PEEL, MAX, MACH, pLSI, microprocessors, EPROM, series EPROM, PROM and Flash memory. The LabTool-48XP performs device insertion and contact checks before it programs each device. It can detect poor pin contact and incorrect insertion, thus saving expensive chip damage due to operator error. Many EPROM and Flash memories have a built-in device and manufacturer ID. The LabTool-48XP can read this information, making it useful when working with secondhand chips and devices that have had their part number removed.

Figure 5.1 IPC

5.6.1 Intelligent Universal Programmer

Features of IUP:

High Speed USB port interface. Supports 5V, 3.3V & 1.8V Devices Less that 2 seconds per M bit Programming speed No adapter required for DIL devices up to 48-pin. 48-pin universal pin driver and current limit Device insertion / continuity check Supports Windows 95/98, Windows 2000, Windows XP & NT 3 years hardware warranty. FREE software updates via the web. Serialization for Memory and Micro's Memory buffer H / L byte swap Project file save and load function User Selectable verify VCC with one or two-pass verify voltage Automatic file format detection and conversion Pin swapping table provided for all adapters

6. SOURCE CODE.

6.1 Transmitter side:


org 23h clr p2.0 setb p2.7 call baudrate main: jnb p2.3,FIRE jb p2.4,THEFT jmp main THEFT: clr p2.7 mov a,#'1' call send call delay setb p2.7 jmp main FIRE: clr p2.7 mov a,#'2' call send setb p2.0 call delay setb p2.7 jmp main

baudrate: mov scon,#50h mov Tmod,#20h mov th1,#0fdh

setb tr1 ret send: call delay mov sbuf,a jnb TI,$ clr TI ret

delay: mov r4,#25 h: setb tr0 jnb tf0,$ clr tr0 clr tf0 djnz r4,h ret end

6.2 Receiver Side:


#include <reg52.h> /* special function register declarations */ void delay_ms(unsigned int); sbit ALARM=P2^1; #define lcd P0 void init_lcd(void); void cmd_lcd(unsigned char); void lcd_data(unsigned char); void display_lcd(unsigned char *); void main () {

ALARM=1; SCON = 0x50; /* SCON: mode 1, 8-bit UART, enable rcvr */ TMOD = 0x20; /* TMOD: timer 1, mode 2, 8-bit reload */ TH1 = -3; /* TH1: reload value for 9600 baud @ 11.0592MHz */ TR1 = 1; /* TR1: timer 1 run */ init_lcd(); delay_ms(10); display_lcd("OILFIELD SECURITY "); cmd_lcd(0xc0); display_lcd(" USING ZIGBEE"); delay_ms(50); while(1); } void serial_int(void)interrupt 4 { unsigned char k; if(RI) { k=SBUF; if(k=='1') { cmd_lcd(0x01); ALARM=0; display_lcd("WELL OPENED"); delay_ms(200); ALARM=1; } else if(k=='2') { cmd_lcd(0x01); ALARM=0; display_lcd("WARNING"); delay_ms(10); cmd_lcd(0xc0);

display_lcd("FIRE DETECTED"); delay_ms(200); ALARM=1; }

RI = 0; } }

void init_lcd(void) { cmd_lcd(0x28); cmd_lcd(0x0c); cmd_lcd(0x06); cmd_lcd(0x01); delay_ms(10); } void cmd_lcd(unsigned char c) { lcd = ((c & 0xf0) | 0x08); lcd = 0; lcd = ((c<<4)|0x08); lcd = 0; delay_ms(20); }

void lcd_data(unsigned char c) { lcd = ((c&0xf0)|0x0a); lcd = 0; lcd = ((c<<4)|0x0a); lcd = 0; delay_ms(20); } void display_lcd(unsigned char *s) { while(*s) lcd_data(*s++); }

void delay_ms(unsigned int i) { unsigned int j=0; while(i-->0) for(j=0;j<500;j++); }

7. CONCLUSION

Das könnte Ihnen auch gefallen