Вы находитесь на странице: 1из 59

CHAPTER 1

INTRODUCTION

1.1 Overview of the Project

This system is developed to overcome the problem of knowing the availability of a


person in his/her busy conditions. By just watching at the display device we can save our
time and also can complete our work when the person is freely available.

To design this embedded system we are using a wireless network, Infrared sensors,
limit switch, microcontrollers, interfacing circuits like MAX232, conditioning circuits and
other components.

By this project we can display the presence or absence of a specific person and the
number of persons in his/her cabin on the LCD display placed at the receiver side using
wireless transmission. Here we are using Xbee module which uses Zigbee protocol for the
wireless transmission.

The microcontrollerAT89S52 was used in this project which has facilities of interfacing
with other devices and circuits and its programming speed is high. Its ROM size is 8 kilo
bytes and RAM size is 256 bytes. We are using two microcontrollers in this project.

1.2 Requirements of the Project

Hardware Components:

AT89S52 micro controller


LCD display
IR LED and Photo diode
Limit Switch
Xbee Module
MAX 232 IC
LM 358 IC
Power supply

Department of E.C.E, Gudlavalleru Engineering College 1


Software used:

Keil u Vision 4

1.3 Existing Model

Until now for knowing the presence of a specific person in his/her respective cabin or
workspace we used to either enquire or watch at them without their notice and which is not so
advisable in case of higher officials.

A remedy to this is the usage of a IN/OUT box which is placed outside the door of the
personnel and it must be operated by any other person as if to know whether the person is
present in the room or not. But if the box is not adjusted according to the status of the person,
it might be another problem for the people who come to meet the respected person in the
cabin.

So taking this as a problem for human kind we had started this project to find a
solution to this problem using the concepts of electronics and the usage of electronic devices.

1.3.1 Disadvantages of Existing Model

A specified person must every time change the status of the box.
If such types of devices are not used the time of the persons who comes to meet the
official gets wasted.

1.4 Proposed Model

For overcoming the disadvantages in the existing model and to find a solution to the
above problem we had started designing this system using the concepts of electronics and the
use of simple electronic devices.

In this system we use the IR sensor and the limit switch as the inputs at the transmitter
side and these are given as inputs to the microcontroller and the output is transmitted to the
receiver section using the Zigbee wireless transmission protocol and is received at the
receiver end and is displayed in the 16*2 LCD display unit.

Department of E.C.E, Gudlavalleru Engineering College 2


This system overcomes the problem of knowing the presence of the person in his/her
respective cabin without actually looking at him and just looking at the display unit placed
outside of the room.

1.4.1 Advantages of Proposed System

Work gets automated.


Reduces the waste of time.
Can be able to get the work done in short time without waiting.

1.5 Organization of the project


Chapter 1 deals with the overview of the project, requirements of the project and the
proposed model of the system.

Chapter 2 deals with explanation of block diagram and its operation.

Chapter 3 deals with brief explanation of the microcontroller and the other
components and also their interfacing with the microcontroller and the overall circuit
diagram.

Chapter 4 deals with explanation of algorithm and flowchart.

Chapter 5 deals with the result and conclusion of the project.

In this chapter the overview and requirements of the project are discussed along with
criteria to choose microcontroller. In the next chapter block diagram and its operations are
explained.

Department of E.C.E, Gudlavalleru Engineering College 3


CHAPTER 2

DESIGN AND DEVELOPMENT OF EMBEDDED SYSTEM

In the last chapter the overview and requirements of the project are discussed. This
chapter deals with the block diagram and its operation. The basic operation of the circuit can
be explained using the block diagram.

2.1 Transmitter Section

Figure 2.1 shows the transmitter block diagram of the system. The transmitter block
mainly consists of the power supply section which takes input from 230V, 50Hz AC Supply
and gives it to the 12V step-down transformer and the 12V output from the transformer is
given to the bridge rectifier to get it converted to DC voltage and then to the voltage regulator
circuit to limit the output voltage to 5V for giving the power supply to the micro controller
board.

The other main components in the transmitter section are the IR Sensors and the limit
switch which are the input devices for the micro controller. The controller is the heart of the
circuit which gives the output whether the person is present or not in the 16*2 LCD display
device in the receiver section.

Power supply

Tx

Sensor 1

Micro MAX Zigbee


Sensor 2
controller 232 Transceiver

Limit
switch

Fig. 2.1 Block Diagram of Embedded System (Transmitter)

Department of E.C.E, Gudlavalleru Engineering College 4


The data transfer from the transmitter section to receiver section is done through the
Zigbee wireless communication protocol. The MAX 232 in the transmitter section is used to
convert the TTL logic levels to the RS 232 standard for wireless transmission.

2.2 Receiver Section

Figure 2.2 shows the receiver block diagram of the system. The receiver section is a
combination of the ZIGBEE TRANSRECEIVER, MAX232, Micro controller and LCD
display with power supply section.

Power
Supply

Rx

Zigbee 16*2
Max Micro
Transceiver
232 controller LCD Display

Fig. 2.2 Block Diagram of Embedded System (Receiver)

The signals from Zigbee transceiver is transmitted to microcontroller through


MAX232, the microcontroller processing the received data then results will be displayed on
16*2 LCD display.

2.3 Working

The input to the circuit is applied from the regulated power supply. The ac 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 dc voltage. So in order to get a pure dc
voltage, the output voltage from the rectifier is fed to a filter to remove any ac components
present even after rectification. Now, this voltage is given to a voltage regulator to obtain a

Department of E.C.E, Gudlavalleru Engineering College 5


pure constant dc voltage. This power supply section is required both transmitter and Receiver
section this constant dc voltage is required to operate microcontroller.

In transmitter section IR sensors are used which emits infrared radiation. This
radiation illuminates the surface in front of LED. Surface reflects the infrared light.
Depending on the reflectivity of the surface, amount of light reflected varies. This reflected
light is made incident on reverse biased IR sensor when photons are incident on reverse
biased junction of this diode, electron-hole pairs are generated, which results in reverse
leakage current. Amount of electron-hole pairs generated depends on intensity of incident IR
radiation. More intense radiation results in more reverse leakage current. This current can be
passed through a resistor so as to get proportional voltage. Thus as intensity of incident rays
varies, voltage across resistor will vary accordingly.

This voltage can then be given to OP-AMP based comparator. Output of the
comparator can be read by the micro controller and it processes and the resulting data is
transmitted through wireless Zigbee transceiver.

Another input device in the system is the limit switch. It is connected to the
microcontroller at the port 1.2 and which gives the signal to the microcontroller when the
person is present in his / her respective chair. This gives the high enable signal to the
microcontroller when the person sits in the chair and with respective to this the output of the
system varies accordingly.

The limit switch is a device which gives the high output signal when the two
terminals get touched with each other. This is done only when the person sits in the chair and
so it is placed beneath the chair.

The both outputs from the IR sensors and the limit switch are given to the
microcontroller and it is programmed in such a way that according to these input conditions
the output is obtained and it is transferred to the receiver section by using the Zigbee
transceiver.

In between the microcontroller and the Zigbee module we had used an MAX 232 IC
which is used to convert the TTL logic levels to the RS 232 standard values and vice-versa.
This is placed as the Zigbee transceiver works with RS 232 standard and the microcontroller

Department of E.C.E, Gudlavalleru Engineering College 6


works on TTL logic levels. Upon converting the values these are transferred to the Zigbee
module to transmit them to the receiver section.

At receiver section the Zigbee transceiver receives the signal and it is transmitted to
microcontroller through MAX232 IC. It is a specialized circuit which makes standard
voltages as required by RS232 standards. This IC provides best noise rejection and very
reliable against discharges and short circuits. MAX232 IC chips are commonly referred to as
line drivers. To ensure data transfer between PC and microcontroller, the baud rate and
voltage levels of Microcontroller and PC should be the same. The voltage levels of
microcontroller are logic1 and logic 0 i.e., logic 1 is +5V and logic 0 is 0V. But for PC,
RS232 voltage levels are considered and they are: logic 1 is taken as -3V to -25V and logic 0
as +3V to +25V. So, in order to equal these voltage levels, MAX232 IC is used. Thus this IC
converts RS232 voltage levels to microcontroller voltage levels and vice versa.

The microcontroller reads the information and it is programmed such that port 3 is
taken as input port and port 2 as output port. The resultant output data is transferred to LCD
section. LCD are very commonly used , LCDs are easy to program and are proved to be a
better display unit as compared to other devices like seven segments and LED display units.

Department of E.C.E, Gudlavalleru Engineering College 7


CHAPTER 3

HARDWARE IMPLEMENTATION

In the previous chapter the block diagram and its operation are discussed. This chapter
explains about Microcontroller AT89S52 features, pin diagram, and the other components
used and their interfacings with the microcontroller are discussed.

3.1 Microprocessors vs. Microcontrollers

Microprocessors are single-chip CPUs used in microcomputers. Microcontrollers and


microprocessors are different in three main aspects hardware architecture, applications, and
instruction set features.

Hardware Architecture:

A Microprocessor is a single chip CPU while a microcontroller is a single IC contains


a CPU and much of remaining circuitry of a complete computer (e.g., RAM, ROM, serial
interface, parallel interface, timer, and interrupt handling circuit).

Applications:

Microprocessors are commonly used as a CPU in computers while microcontrollers


are found in small, minimum component designs performing control oriented activities.

Microprocessor instruction sets are processing Intensive. Their instructions operate on


nibbles, bytes, words, or even double words.

Addressing modes provide access to large arrays of data using pointers and offsets.
They have instructions to set and clear individual bits and perform bit operations. They have
instructions for input/output operations, event timing, enabling and setting priority levels for
interrupts caused by external stimuli. Processing power of a microcontroller is much less than
a microprocessor.

Department of E.C.E, Gudlavalleru Engineering College 8


3.2 Why we are using AT89S52 Microcontroller
The AT89S52 is a low-power, high-performance CMOS 8-bit microcomputer with
8K bytes of flash Programmable and Erasable Read Only Memory (PEROM). The device is
manufactured using Atmels high density non-volatile memory technology and is compatible
with the industry standard 80S51 and 80S52 instruction set and pin out. The on-chip flash
allows the program memory to be reprogrammed in-system or by a conventional non-volatile
memory programmer. By combining a versatile 8-bit CPU with flash on a monolithic chip,
the Atmel AT89S52 is a powerful microcomputer which provides a highly flexible and cost
effective solution to many embedded control applications.
The AT89S52 provides the following standard features: 8K bytes of Flash, 256 bytes
of RAM, 32 I/O lines, three 16-bit timer/counters, six-vector two-level interrupt architecture,
a full duplex serial port, on-chip oscillator, and clock circuitry. In addition, the AT89S52 is
designed with static logic for operation down to zero frequency and supports two software
selectable power saving modes. The Idle Mode stops the CPU while allowing the RAM,
timer/counters, serial port, and interrupt system to continue functioning. The Power down
Mode saves the RAM contents but freezes the oscillator, disabling all other chip functions
until the next hardware reset.

3.3 Features of AT89S52

4.0V to 5.5V Operating Range


Fully Static Operation: 0 Hz to 33 MHz
Three-level Program Memory Lock
256K Internal RAM
32 Programmable I/O Lines
3 16-bit Timer/Counters
Full Duplex UART Serial Channel
Low-power Idle and Power-down Modes
Interrupt Recovery from Power-down Mode

Department of E.C.E, Gudlavalleru Engineering College 9


3.4 Power Supply Section

The Power Supply is a primary requirement for the circuit to operate. The required
DC power supply for the base unit as well as for the recharging unit is derived from the mains
line. For this purpose centre tapped secondary of 12V-0-12V transformer is used. From this
transformer after regulating we get 5V power supply. In this +5V output is a regulated output
and it is designed using 7805 positive voltage regulator. This is a three pin voltage regulator
which can deliver current up to 800 mA. Rectification is a process of rendering an alternating
current or voltage into a uni-directional one. The component used for rectification is called
rectifier. A rectifier permits current to flow only during positive half cycles of the applied AC
voltage. Thus, pulsating DC is obtained and further to obtain smooth DC power additional
filter circuits required. The ac voltage, typically 120 Vrms, is connected to a transformer,
which steps that ac voltage down to the level for the desired dc output. A diode rectifier then
provides a full-wave rectified voltage that is initially filtered by a simple capacitor filter to
produce a dc voltage. This resulting dc voltage usually has some ripple or ac voltage
variation.

230V AC
D.C
50Hz Output

Step down Bridge Filter


transformer Rectifier
Regulator
Filter
Fig. 3.1 Block Diagram of Power Supply

Department of E.C.E, Gudlavalleru Engineering College 10


3.4.1 Circuit Diagram of power supply

Fig. 3.2 Circuit Diagram of Power Supply

A diode can be used as rectifier. These are various types of diodes. However,
semiconductor diodes are very popularly used as rectifiers. A semiconductor diode is a solid-
state device consisting of two elements is being an electron emitter or cathode, the other an
electron collector or anode. Since electrons in a semiconductor diode can flow in one
direction only-form emitter to collector-the diode provides the unilateral conduction
necessary for rectification. The rectified output is filtered for smoothening the DC, for this
purpose capacitor is used in the filter circuit. The filter capacitors are usually connected in
parallel with rectifier output and the load. The AC can pass through a capacitor but DC
cannot, the ripples are thus limited and the output becomes smoothed. When the voltage
across the capacitor plates tends to rise, it stores up energy back into voltage and current.
Thus, the fluctuation in the output voltage is reduced considerable.

3.5 IC Voltage Regulators

Voltage regulators comprise a class of widely used ICs. Regulator IC units contain the
circuitry for reference source, comparator amplifier, control device, and overload protection
all in a single IC. Although the internal construction of the IC is somewhat different from that
described for discrete voltage regulator circuits, the external operation is also in the same
manner. IC units provide regulation of either a fixed positive or negative voltage, or an
adjustable set voltage. A power supply can be built using a transformer connected to the ac
supply line to step down the ac voltage to desired amplitude, then rectifying that ac voltage,
filtering with a capacitor and finally regulating the dc voltage using an IC regulator.

Department of E.C.E, Gudlavalleru Engineering College 11


3.5.1 Three Terminal Voltage Regulators

Figure 3.3 shows the basic connection of a three-terminal voltage regulator IC to a


load. The fixed voltage regulator has an unregulated dc input voltage, Vi, applied to one input
terminal, a regulated output dc voltage, Vo, from a second terminal, with the third terminal
connected to ground The specifications also list the amount of output voltage change
resulting from a change in load current (load regulation) or in input voltage (line regulation).

3.5.2 Fixed Positive Voltage Regulators

Fig. 3.3 7805 IC Voltage Regulator

3.5.3 Features of 7805

Output current in excess of 0.5A


No external components
Internal thermal overload protection
Internal short circuit current-limiting
Output transistor safe-area compensation
Available in TO-220, TO-39, and TO-252 D-PAK packages.

3.6 IR LED

An IR LED, also known as IR transmitter, is a special purpose LED that transmits


infrared rays in the range of 760 nm wavelength. Such LEDs are usually made of gallium
arsenide or aluminium gallium arsenide. They, along with IR receivers, are commonly used
as sensors.

The appearance is same as a common LED. Since the human eye cannot see the
infrared radiations, it is not possible for a person to identify whether the IR LED is working

Department of E.C.E, Gudlavalleru Engineering College 12


or not, unlike a common LED. To overcome this problem, the camera on a cell phone can be
used. The camera can show us the IR rays being emanated from the IR LED in a circuit.

Fig. 3.4 Diagram of IR LED

3.7 Photodiode

A photodiode is a type of photo detector capable of converting light into either current
or voltage, depending upon the mode of operation. The common, traditional solar cell used to
generate electric solar power is a large area photodiode.

Photodiodes are similar to regular semiconductor diodes except that they may be
either exposed (to detect vacuum UV or X-rays) or packaged with a window or optical fiber
connection to allow light to reach the sensitive part of the device. Many diodes designed for
use specifically as a photodiode use a PIN junction rather than a p-n junction, to increase the
speed of response. A photodiode is designed to operate in reverse bias.

Fig. 3.5 Diagram of Photo Diode

Department of E.C.E, Gudlavalleru Engineering College 13


3.7.1 Principle of operation
A photodiode is a p-n junction or PIN structure. When a photon of sufficient energy
strikes the diode, it excites an electron, thereby creating a free electron (and a positively
charged electron hole). This mechanism is also known as the inner photoelectric effect. If the
absorption occurs in the junction's depletion region, or one diffusion length away from it,
these carriers are swept from the junction by the built-in field of the depletion region. Thus
holes move toward the anode, and electrons toward the cathode, and a photocurrent is
produced. This photocurrent is the sum of both the dark current (without light) and the light
current, so the dark current must be minimized to enhance the sensitivity of the device.

3.8 IR Sensor

Fig. 3.6 Symbols of IR led and Photo Diode

3.8.1 Working of IR sensor

IR sensor works on the principle of emitting IR rays and receiving the reflected ray by
a receiver (Photo Diode).
IR source (LED) is used in forward bias.
IR Receiver (Photodiode) is used in reverse bias

Department of E.C.E, Gudlavalleru Engineering College 14


Fig. 3.7 Diagram of IR Sensor Working

3.9 Resistor

A resistor is a passive two-terminal electrical component that implements electrical


resistance as a circuit element. The current through a resistor is in direct proportion to the
voltage across the resistor's terminals. Thus, the ratio of the voltage applied across a resistor's
terminals to the intensity of current through the circuit is called resistance. This relation is
represented by Ohm's law in the equation 1:

Units

The ohm (symbol: ) is the SI unit of electrical resistance, named after George
Simon Ohm. An ohm is equivalent to a volt per ampere. Since resistors are specified and
manufactured over a very large range of values, the derived units of milliohm (1 m = 10 3
), kilo ohm (1 k = 103 ), and mega ohm (1 M = 106 ) are also in common usage.

Electronic symbols and notation

The symbol used for a resistor in a circuit diagram varies from standard to standard
and country to country. Two typical symbols are as follows.

Department of E.C.E, Gudlavalleru Engineering College 15


(a) (b)

Fig. 3.8 Resistor symbols. (a) Resistor, (b) Rheostat (variable resistor)

Lead arrangements

Fig. 3.9 Resistors with Wire leads for through-hole mounting

Through-hole components typically have leads leaving the body axially. Others have
leads coming off their body radially instead of parallel to the resistor axis. Other components
may be SMT (surface mount technology) while high power resistors may have one of their
leads designed into the heat sink.

Electronic color code

The electronic color code is used to indicate the values or ratings of electronic
components, very commonly for resistors, but also for capacitors, inductors, and others. A
separate code, the 25-pair color code, is used to identify wires in some telecommunications
cables. The electronic color code was developed in the early 1920s by the Radio
Manufacturers Association (now part of Electronic Industries Alliance (EIA)), and was
published as EIA-RS-279. The current international standard is IEC 60062.

Fig. 3.10 Resistor Colour Coding

Department of E.C.E, Gudlavalleru Engineering College 16


To distinguish left from right there is a gap between the C and D bands.

Band A is first significant figure 3.10 of component value (left side)


Band B is the second significant figure 3.10
Band C is the decimal multiplier
Band D if present, indicates tolerance of value in percentage (no band means 20%)

Resistors manufactured for military use may also include a fifth band which indicates
component failure rate (reliability). Tight tolerance resistors may have three bands for
significant figures rather than two, or an additional band indicating temperature coefficient, in
units of ppm/K. Table 3.1 shows standard colour code of the resistors.

TABLE 3.1 The Standard Resistor Colour Code

Significant Temp. Coefficient


Colour Multiplier Tolerance
figures (ppm/K)
Black 0 100 250 U
Brown 1 101 1% F 100 S
Red 2 102 2% G 50 R
Orange 3 103 15 P
Yellow 4 104 (5%) 25 Q
Green 5 105 0.5% D 20 Z
Blue 6 106 0.25% C 10 Z
Violet 7 107 0.1% B 5 M
Gray 8 108 0.05% (10%) A 1 K
White 9 109
Gold 10-1 5% J
Silver 10-2 10% K

3.10 Capacitor

A capacitor (originally known as condenser) is a passive two-terminal electrical


component used to store energy in an electric field. The forms of practical capacitors vary
widely, but all contain at least two electrical conductors separated by a dielectric (insulator);
for example, one common construction consists of metal foils separated by a thin layer of

Department of E.C.E, Gudlavalleru Engineering College 17


insulating film. Capacitors are widely used as parts of electrical circuits in many common
electrical devices.

Fig. 3.11 A Typical Electrolytic Capacitor

When there is a potential difference (voltage) across the conductors, a static electric
field develops across the dielectric, causing positive charge to collect on one plate and
negative charge on the other plate. Energy is stored in the electrostatic field. An ideal
capacitor is characterized by a single constant value, capacitance, measured in farads. This is
the ratio of the electric charge on each conductor to the potential difference between them.

The capacitance is greatest when there is a narrow separation between large areas of
conductor, hence capacitor conductors are often called "plates," referring to an early means of
construction. In practice, the dielectric between the plates passes a small amount of leakage
current and also has an electric field strength limit, resulting in a breakdown voltage, while
the conductors and leads introduce an undesired inductance and resistance.

Capacitors are widely used in electronic circuits for blocking direct current while
allowing alternating current to pass, in filter networks, for smoothing the output of power
supplies, in the resonant circuits that tune radios to particular frequencies, in electric power
transmission systems for stabilizing volt A capacitor consists of two conductors separated by
a non-conductive region. The non-conductive region is called the dielectric. In simpler terms,
the dielectric is just an electrical insulator. Examples of dielectric media are glass, air, paper,
vacuum, and even a semiconductor depletion region chemically identical to the conductors. A
capacitor is assumed to be self-contained and isolated, with no net electric charge and no
influence from any external electric field. The conductors thus hold equal and opposite
charges on their facing surfaces, and the dielectric develops an electric field. In SI units, a

Department of E.C.E, Gudlavalleru Engineering College 18


capacitance of one farad means that one coulomb of charge on each conductor causes a
voltage of one volt across the device.

3.11 LIQUID CRYSTAL DISPLAY (LCD)

A Liquid Crystal Display is used to display any message on its screen which can be
programmed by a microcontroller.

3.11.1 Description

The LCD unit receives character codes (8 bits per character) from a microprocessor or
microcomputer, latches the codes to its display data RAM (80-byteDD RAM for storing 80
characters), transforms each character code into a 5X7 dot matrix character pattern, and
displays the characters on its LCD screen. The LCD unit incorporates a character generator
ROM which produces 160 different 5X7 dot-matrix character patterns.
The unit also provides a character generator RAM (64 bytes) through which the user
may define up to eight additional 5X7 dot matrix character patterns, as required by the
application. To display a character, positional data is sent via the data bus from the
microprocessor to the LCD unit, where it is written into the instruction register. A character
code is then sent and written into the Data register. The LCD unit displays the corresponding
character pattern in the specified position.
The LCD unit can either increment or decrement the display position automatically
after each character entry, so that only successive characters codes need to be entered to
display a continuous character string. The display/cursor shift instruction allows the entry of
characters in either the left-to-right or right to left direction.
Since the display data RAM (DDRAM) and the character generator RAM (CG RAM)
many be accessed by the microprocessor, unused portions of each RAM may be used as
general purpose data areas.
The LCD unit may be operated with either dual 4-bit or single 8-bit data transfers, to
accommodate interfaces with both 4-bit and 8-bit microprocessors. The low power feature of
the LCD unit will be further appreciated when combined with a CMOS microprocessor.

Department of E.C.E, Gudlavalleru Engineering College 19


3.11.2 Features
Interface with either 4-bit or 8-bit microprocessor
Display data RAM
8 bits X80 (80 characters)
Character generator ROM
160 different 7 dot-matrix character patterns
Character generator RAM
8 different 7 dot-matrix patterns X users programmed 5
Display data RAM and character generator RAM may be
Accessed by the microprocessor.
Clear Display, Cursor Home, Display ON/OFF, Cursor
ON/OFF, Blink Character, Cursor Shift, Display Shift.
Built-in reset circuit is triggered at power ON.
Built-in oscillator.

3.11.3 Block diagram of LCD


Figure 3.12 shows the block diagram of LCD which consists of LCD panel which can
support 32 characters in two lines with 16 characters in each line.

Fig. 3.12 Block Diagram of LCD

3.11.4 Pin Diagram


Figure 3.13 shows the pin diagram of LCD. It has 16 pins out of which eight are data
pins and three are control pins.

Department of E.C.E, Gudlavalleru Engineering College 20


Fig. 3.13 Pin Diagram of LCD

The description of each pin is shown in the Table 3.2 along with symbol and also
indicating whether it is used as input or output pin.

Table 3.2 Pin Description of LCD


PIN SYMBOL I/O DESCRIPTION

1 VSS -- Ground
2 VCC -- +5V power supply
3 VEE -- Power supply to control contrast
4 RS I RS=0 to select command register
RS=1 to select data register
5 R/W I R/W=0 for write
R/W=1 for read
6 EN I/O Enable
7 DB0 I/O The 8-bit data bus
8 DB1 I/O The 8-bit data bus
9 DB2 I/O The 8-bit data bus
10 DB3 I/O The 8-bit data bus
11 DB4 I/O The 8-bit data bus
12 DB5 I/O The 8-bit data bus
13 DB6 I/O The 8-bit data bus
14 DB7 I/O The 8-bit data bus

3.11.5 LCD Basic Commands

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

Department of E.C.E, Gudlavalleru Engineering College 21


RS = 1 - Bits D0 - D7 are addresses of characters that should be displayed. Built in
processor addresses built in map of characters and displays corresponding symbols.
Displaying position is determined by DDRAM address. This address is either previously
defined or the address of previously transferred character is automatically incremented.

RS = 0 - Bits D0 - D7 are commands which determine display mode. List of


commands which LCD recognizes are given in the table 3.3.

Table 3.3 LCD basic commands

3.12 Limit Switch

In electrical engineering a limit switch is a switch operated by the motion of a


machine part or presence of an object. They are used for control of a machine, as
safety interlocks, or to count objects passing a point.

Department of E.C.E, Gudlavalleru Engineering College 22


A limit switch is an electromechanical device that consists of an actuator
mechanically linked to a set of contacts. When an object comes into contact with the actuator,
the device operates the contacts to make or break an electrical connection. Limit switches are
used in a variety of applications and environments because of their ruggedness, ease of
installation, and reliability of operation. They can determine the presence or absence, passing,
positioning, and end of travel of an object. They were first used to define the limit of travel of
an object; hence the name Limit Switch.

Standardized limit switches are industrial control components manufactured with a


variety of operator types, including lever, roller plunger, and whisker type. Limit switches
may be directly mechanically operated by the motion of the operating lever.

Rarely, a final operating device such as a lamp or solenoid valve will be directly
controlled by the contacts of an industrial limit switch, but more typically the limit switch
will be wired through a control relay, a motor contactor control circuit, or as an input to
a programmable logic controller.

Fig. 3.14 Limit Switch Diagram

3.13 Serial Communication

Main requirements for serial communication are:

1. Microcontroller
2. PC or any external device which can be interfaced with the microcontroller through
serial communication.

Department of E.C.E, Gudlavalleru Engineering College 23


3. RS 232 cable
4. MAX 232 IC
5. HyperTerminal

When the pins P3.0 and P3.1 of microcontroller are set, UART which is inbuilt in the
microcontroller will be enabled to start the serial communication.

Major registers used for Serial Communication are:

1. TMOD to select the timer.


2. SCON for data framing.
3. SBUF which is solely used for Serial Communication.

3.13.1 TMOD (Timer Mode) Register

Both timers 0 and 1 use the same register TMOD to set the various operation modes.
TMOD is an 8-bit register in which the lower 4 bits are set aside for Timer 0 and the upper 4
bits for Timer 1. In each case, the lower 2 bits are used to set the timer mode and the upper 2
bits to specify the operation. The syntax for TMOD register is given in table 3.4.

Table 3.4 TMOD Register


(MSB) (LSB)
GATE C/T M1 M0 GATE C/T M1 M0
TIMER 1 TIMER 0

GATE
Every timer has a means of starting and stopping. Some timers do this by software,
some by hardware and some have both software and hardware controls. The timers in the
8051 have both. The start and stop of the timer are controlled by the way of software by the
TR (timer start) bits TR0 and TR1. These instructions start and stop the timers as long as
GATE=0 in the TMOD register. The hardware way of starting and stopping the timer by an
external source is achieved by making GATE=1 in the TMOD register.

Department of E.C.E, Gudlavalleru Engineering College 24


C/T

Timer or counter selected. Cleared for timer operation and set for counter operation.

Table 3.5 shows the operating modes of the timers in according to the register values.

Table 3.5 Operating Modes of Timers


M1 M0 Mode Operating Mode
0 0 0 13-bit timer mode
8-bit timer/counter THx with TLx as 5-bit prescaler
0 1 1 16-bit timer mode
16-bit timer/counters THx and TLx are cascaded
1 0 2 8-bit auto reload timer/counter
THx holds a value that is to be reloaded into TLx each time
it overflows

1 1 3 Split timer mode

3.13.2 MAX 232 IC


To allow compatibility among data communication equipment made by various
manufacturers, an interfacing standard called RS232 was set by Electronics Industries
Association (EIA) in 1960. Today RS232 is the most widely used serial I/O interfacing
standard. This Standard is used in the PC's and numerous types of equipment. Since, the
standard was set long before the advent of the TTL logic family. Its input and output voltage
levels are not TTL compatible. In RS232, logic 1 is represented by -3v to -25v, while logic 0
is represented by 3v to 25v, making -3v to 3v undefined .For this reason, to connect any
RS232. The pin diagram of MAX232 is shown in the Figure.3.17.

Fig.3.15 Pin Diagram of MAX232

Department of E.C.E, Gudlavalleru Engineering College 25


To a micro controller system we must use voltage converter such as MAX232 to
convert the TTL logic to the RS232 voltage levels, and vice-versa. MAX232 IC chips are
commonly referred as line drivers (voltage converters).
IC MAX232 is the voltage level converter, which converts TTL level signals in to
RS232C compatible with today's microprocessors and microcontroller. We need a line driver
(voltage converter) to convert the RS232's signals to TTL voltage levels that will be
acceptable to the micro controllers TXD and RXD pins. One example of such converter is
MAX232 from MAXIM Corporation. The MAX232 converts RS232 voltage levels to TTL
voltage levels and vice-versa .One advantage of the MAX232 chip is that uses a +5v power
source, which is the same as the source voltage for the micro controller. In other words, with
a single +5v power supply we can power both the 89S52 and MAX232, with no need for dual
power supplies that are common in many older systems. ICMAX232 is used as an RS232
level converter. Pins 10(TXD) and 11(RXD) of IC are connected to pins 3 and 2 of 9-pin D
connecter, respectively.
One of the easiest and most frequently used solutions to the voltage differences for
TTL/CMOS and RS-232 is theMAX-232 chip from MAXIM semiconductors. This chip
converts 5-volts TTL/CMOS signal to a minimum of +8 to-8volts. There are several
variations of these chips .The two biggest difference are the number of RS-232 interfaces and
the use of internal or external capacitors .For our need we will use the basic MAX-232 chip,
Each level converter handles the conversion of two TTL/CMOS lines .We will use the first
for data transmit & receive and the second for CTS/RTS handshaking.
The MAX-232 is compatible chip as a direct replacement for the TI chip since they
all share the same pin outs. Power& ground connectors are not same on all versions of the
MAX-232 chips. The MAX-232 chip requires one-microfarad capacitors .The MAX-232 is
a16-pin chip that has two complete RS-232 transceivers. These chips work by using the
capacitors to boost the signal voltage levels to operate within the RS-232 signal definitions.
These types of circuits are known as charge pump. The capacitor charges and when it reaches
its discharge level, it pumps the higher voltage to the circuit.
This chip comes in several different forms, but our purpose we will use the 16-pin dip,
which is easy to work with and does not require surface mounting.
Figure 3.18 shows the connection diagram of MAX232, which is representing the
interface with microcontroller.

Department of E.C.E, Gudlavalleru Engineering College 26


Fig. 3.16 Connection Diagram of MAX232

The MAX232 has two sets of line drivers for transferring and receiving data. The line
drivers used for TXD are called T1 and T2 with the line drivers for RXD are designated as
R1 and R2. In many applications only one of each are used. For example, T1 and R1 are used
together for TXD and RXD of 89S52, and the second set is left unused. In MAX232 T1 line
driver has a designation of T1in andT1out as pin numbers 11 and 14 respectively. The T1 pin
is the TTL side and is connected to TXD of the micro-controller, while T1 out is the RS232
side that is connected to the RXD pin of the RS232 DB connecter .The line drivers has a
designation of R1 in and R1out on pin numbers 13 and 12 respectively.

3.13.3 SCON (Serial Control) Register

The SCON register is an 8-bit register used to program the start bit, stop bit and data
bits of data framing. The syntax for SCON register, its pins functions and the modes of serial
communication are given in table 3.6, table 3.7 and table 3.8 respectively.

Table 3.6 SCON Register


SM0 SM1 SM2 REN TB8 RB8 TI RI

Department of E.C.E, Gudlavalleru Engineering College 27


Table 3.7 Pin Functions of SCON Register
Label Pin Description
SM0 SCON.7 Serial port mode specifier
SM1 SCON.6 Serial port mode specifier
SM2 SCON.5 Used for multiprocessor communication
REN SCON.4 Set/cleared by software to enable/disable
reception
TB8 SCON.3 Not widely used
RB8 SCON.2 Not widely used
TI SCON.1 Transmit interrupt flag. Set by hardware at the
beginning of the stop bit in mode 1. Must be
cleared by software.
RI SCON.0 Receive interrupt flag. Set by hardware at the
beginning of the stop bit in mode 1. Must be
cleared by software.

Table 3.8 Modes of Serial Communication


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

3.13.4 RS-232 Standards

RS-232 is a standard developed by Electronics Industry Association (EIA). This is


one of the oldest and most communication interfaces. The PC will have two RS-232 ports
designated as com1& com2. Most of the micro controllers have on-chip serial interface. The
evaluation to the host system using RS-232.
RS-232 is used to connect a DTE (Data Terminal Equipment) to a Data Circuit
Terminating Equipment (DCE). A DTE can be a pc a modem, mouse, digitizer or scanner.
RS-232 interface specifies the physical layer interface only. The specifications describe the
physical, mechanical, electrical & procedural characteristics for serial communication. RS-
232 is the standard for serial communication i.e. the bits are transmitted serially. The

Department of E.C.E, Gudlavalleru Engineering College 28


communication between two devices is in full duplex, i.e. the data transfer can take place in
both directions.

3.14 Zigbee Module

Xbee is the module using Zigbee protocol. Zigbee is a wireless communication


protocol like wifi and bluetooth. This is the very popular 2.4GHz XBee module from Digi
(formally Maxstream). These modules take the 802.15.4 stack (the basis for Zigbee) and wrap
it into a simple to use serial command set. These modules allow a very reliable and simple
communication between microcontrollers, computers, systems, really anything with a serial
port! Point to point and multi-point networks supported.

Fig. 3.17 Zigbee Module used in this System


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

The current list of application profiles either published or in the works are:

Home Automation
Zigbee Smart Energy
Commercial Building Automation
Telecommunication Applications
Personal, Home, and Hospital Care
Toys

Department of E.C.E, Gudlavalleru Engineering College 29


3.14.1 Why Zigbee
Zigbee can activate (go from sleep to active mode) in 15 msec or less, the latency can
be very low and devices can be very responsive particularly compared to Bluetooth wake-
up delays, which are typically around three seconds. Because Zigbees can sleep most of the
time, average power consumption can be very low, resulting in long battery life.

Protocols

The protocols build on recent algorithmic research (Ad-hoc On-demand Distance


Vector, neuRFon) to automatically construct a low-speed ad-hoc network of nodes. In most
large network instances, the network will be a cluster of clusters. It can also form a mesh or a
single cluster. The current profiles derived from the Zigbee protocols support beacon and
non-beacon enabled networks.

3.15 Transmitter Schematic

Fig. 3.18 Schematic Diagram of Transmitter

Department of E.C.E, Gudlavalleru Engineering College 30


The schematic of the transmitter section of the system is shown in figure 3.18
which deals with the circuit connection of the transmitter circuit.
The main device in the transmitter system is the Atmel 89S52 microcontroller,
which has four ports in which port 1 is used for taking the inputs from IR sensor and the
limit switch and port 3 is used for interfacing the microcontroller with the Zigbee
module.
In the transmitter section IR sensors and limit switch are connected to the input of the
microcontroller. In this project we are use two sets of IR LEDs and photo diodes. One of the
set is connected to the pin 1.0 and other one is connected to pin 1.1 of the microcontroller.
Limit switch is connected to the pin 1.3. 18th and 19th pins of microcontroller are connected to
the crystal oscillator which enables the internal clock generator in the microcontroller to
generate a 12MHz signal. The 20th and the 40th pins of the microcontroller are connected to
the ground and Vcc respectively.

As the output we get from the IR sensor is very low for the controller to get operated
we use a conditioning circuit by using LM 358 IC which acts as non-inverting amplifier and
whose output is connected to the microcontroller.

The reset switch is connected at the 9th pin of the microcontroller. The 2nd port of pins
(pin 2.0 to 2.7) are connected to the LCD display device which is used for displaying the
name of the system.

As the 3rd port pins have alternate functionalities the 10th and 11th pins of the
microcontroller are connected to the Xbee module through the MAX 232 IC.

MAX 232 is a 16 pin IC and the 10th pin of microcontroller is connected to 11th pin of
the MAX 232 IC and the 11th pin of the controller is connected to 12th pin of IC. The Xbee
module is connected between the pins 13 and 14 of the Max 232 IC.

Department of E.C.E, Gudlavalleru Engineering College 31


3.16 Receiver Schematic

Fig. 3.19 Schematic Diagram of Receiver

The schematic of the receiver section of the system is shown in figure 3.19 which
deals with the circuit connection of the receiver circuit.
The receiver section is almost same as that of the transmitter section and it also
consists of the Xbee module (Zigbee transceiver) which is connected to the microcontroller
through the MAX 232 IC. Same as that of in the transmitter section the MAX 232 IC is
connected in between 10 and 11 pins of the microcontroller.

Department of E.C.E, Gudlavalleru Engineering College 32


The output display unit (LCD Display) is connected to the pins of port 2 of the
microcontroller and the 20th and the 40th pins of the microcontroller are connected to the
ground and Vcc respectively. 18th and 19th pins of microcontroller are connected to the crystal
oscillator which enables the internal clock generator in the microcontroller to generate a
12MHz signal.

The Zigbee transceiver here receives the information from the transmitter and
sends it to the microcontroller through the MAX232 IC and the microcontroller
processes it accordingly and displays the count of the persons entering the room by
incrementing the count value and by decrementing the value shows the number of
persons coming out of the room and the available status of the person is given by the
limit switch as IN/OUT. This information is displayed in the LCD display at the receiver
end.

Department of E.C.E, Gudlavalleru Engineering College 33


CHAPTER 4

SOFTWARE IMPLEMENTATION

This chapter deals with the software we had used in this project for executing the
program we had written. We had chosen the Keil software for our programming.

4.1 Introduction to Micro vision Keil

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

4.1.1 Concept of compiler

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

4.1.2 Concept of cross compiler

A cross compiler is similar to the compilers but we write a program for the target
processor (like 8051 and its derivatives) on the host processors (like computer of x86)

It means being in one environment you are writing a code for another environment is
called cross development. And the compiler used for cross development is called cross
compiler.

4.2 Keil C cross compiler

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


tools like

IDE (Integrated Development environment)


Project Manager
Simulator

Department of E.C.E, Gudlavalleru Engineering College 34


Debugger
C Cross Compiler , Cross Assembler, Locator/Linker

Keil Software provides you with software development tools for the 8051 family of
microcontrollers. With these tools, you can generate embedded applications for the multitude
of 8051 derivatives. Keil provides following tools for 8051 development

C51 Optimizing C Cross Compiler,


A51 Macro Assembler,
8051 Utilities (linker, object file converter, library manager),
Source-Level Debugger/Simulator,
Vision for Windows Integrated Development Environment.

The keil 8051 tool kit includes three main tools, assembler, compiler and linker. An
assembler is used to assemble your 8051 assembly program. A compiler is used to compile
your C source code into an object file. A linker is used to create an absolute object module
suitable for your in-circuit emulator.

4.3 Program explanation

In this project we are using two IR sensors and limit switch as inputs to the
microcontroller. The program flowchart and algorithm of this project are explained in this
chapter.

4.4 Algorithm

Step1: start

Step2: Initialise IR1 and IR2 to one and limit switch to one.

Step3: Take count variable and initialise it to zero.

Step4: If IR1=0 then increase the count value and go to step7

If IR2=0 then decrease the count value and go to step7

Step5: If limit switch=1 then go to step8

Step6: If limit switch=0 then go to step9

Step7: Display the count value

Department of E.C.E, Gudlavalleru Engineering College 35


Step8: Display that person is in cabin

Step9: Display that person is not in cabin

Step10: Stop.

The result of the above given algorithm is that the system takes the input and
processes it and displays either the person is present or not in the output display unit
according to the taken conditions.

4.5 Program Flow Chart

Start

Make IR1=1and
IR2=1 Limit
Switch=0 and
Count=0

IF IR1=0
=>Count++
Display the count value
IF IR2=0 =>Count--

IF
LS=1
Person is in Cabin

Person is not in Cabin

Stop

Fig. 4.1 Flowchart of the Program

Department of E.C.E, Gudlavalleru Engineering College 36


The program flow chart for the working of the system is shown in the figure 4.1
according to which the system takes input and gives the output by processing the inputs. First
the input ports are initialized by 1 and output ports by 0.

Then the values from the IR sensor and limit switch are taken and accordingly the
conditions are checked and the output is displayed on the LCD display.

Department of E.C.E, Gudlavalleru Engineering College 37


CHAPTER 5

RESULTS AND DISCUSSIONS

5.1 RESULT
The results obtained from the project are shown in the figures 5.1, 5.2, 5.3 and 5.4 and
they make a view to users how the project works and the usage of the project. The images
shown below are about when power supply is not given to the circuit.

Fig. 5.1 Photograph of Interconnection of Modules of Transmitter on PCB

The figure 5.1 shows the interconnection of the modules in the transmitter section
like microcontroller, LCD display, IR sensor, limit switch, Xbee module, on the PCB when
the power supply is not given to the circuit. The result of the circuit when the supply is given
is shown in the figure 5.3.

Fig. 5.2 Photograph of Interconnection of Modules of Receiver on PCB

Department of E.C.E, Gudlavalleru Engineering College 38


Figure 5.2 shows the interconnection of the modules in the receiver section like
microcontroller, LCD display, Zigbee transceiver, on the PCB when the power supply is not
given to the circuit. The result of the circuit when the supply is given is shown in the figure
5.4.

Fig. 5.3 Photograph of Transmitter Circuit when Supply is given

Figure 5.3 shows the transmitter section circuit when the supply is given to the circuit.
The LCD display show the title of the system and the LEDs glow on the board connected to
the IR sensors and they get OFF when an obstacle is placed in between them. the output is
transmitted to the receiver section using the Zigbee transceiver.

Fig. 5.4 Photograph of Receiver Circuit when Supply is given

Department of E.C.E, Gudlavalleru Engineering College 39


Figure 5.4 shows the receiver section circuit connection when the power supply is
given to it. It takes the output transmitted from the transmitter section and displays the count
of the persons in the room and also the available status of the person in the LCD display.

5.2 Discussions & Observations

For IR sensors:

Table 5.1 Sensor Results


SENSORS OBSTACLE OUTPUT
IR1 yes 0(LED off)
IR1 No 1(LED on)
IR2 yes 0(LED off)
IR2 No 1(LED on)

Table 5.1 shows the outputs of IR sensors based on the presence of obstacle. After
integration the results are obtained as the microcontroller identifies the sensor signal and
responds by glowing corresponding LEDs, indicating LCD display.

For Limit switch:

Table 5.2 Limit Switch Results


PRESS OUTPUT
Yes 1
No 0

Table 5.2 shows the outputs of the limit switch based on the connection of the limit
switch. After integration the results are obtained as the microcontroller identifies the if the
limit switch is pressed then the microcontroller responds by displaying the status of the
person.

Department of E.C.E, Gudlavalleru Engineering College 40


CONCLUSION AND FUTURE SCOPE

Some of the considerations should be taken while introducing the product into the
market.Some of them are Cost of the objective ,as this project is implemented with the basic
embedded components the preparation and placement cost is low its a good advantage.
Complexity of establishment, here the only main thing is connections and placement as both
are easier the complexity is very less.

Scope and usage are at cabins of the higher officials where people go and just look at
the display device and get their work done when the respective person is free and thus the
time doesnot get wasted.

This project may be extended by maintaing a database for the person availability and
in real time the basic limit switch can be repalced by high level cameras and by using the
concepts of Digital Image Processing.

Department of E.C.E, Gudlavalleru Engineering College 41


REFERENCES

[1] S.Salivahanan , N.Suresh Kumar , V.Vallavaraja ELECTRONIC DEVICES AND


CIRCUITS , TATA Mc GRAW HILL publications, 3rd Edition , 2007.

[2] Ramakanth A. Gayakwad OP-AMPS AND LINEAR INTEGRATED CIRCUITS


Prentice Hall of India Pvt Limited , 4th Edition 2004.

[3] N.Sentil Kumar, M.Saravanan, S.Jeevananthan MICROPROCESSORS AND


MICROCONTROLLERS Oxford University Press 5th Edition 2012.

[4] Upena Dalal WIRELESS COMMUNICATION Oxford Higher education pvt limited
First published in 2009.

[5] Vijay.K.Garg WIRELESS COMMUNICATIONS AND NETWORKING Morgan


Kaufman Publishers First Printed in 2009.

URLs

[6] www.atmel.in/images/doc1919.pdf

[7] http://www.alldatasheet.com/datasheet/MOTOROLA/LM358N

[8] www.alldatasheet.com/MAX232+datasheet

Department of E.C.E, Gudlavalleru Engineering College 42


APPENDIX

Appendix A

Program Code

Program for transmitter

#include<reg51.h>

#define lcd_data P2

sbit ir1=P1^0;

sbit ir2=P1^1;

sbithod=P1^2;

sbitlcd_rs = P2^0;

sbitlcd_en = P2^1;

int x=0,y=0;

unsigned convert(unsigned int );

void delay(unsigned int value)

unsignedintx,y;

for(x=0;x<value;x++)

for(y=0;y<200;y++);

voidlcdcmd(unsigned char value) // LCD COMMAND

lcd_data=value&(0xf0); //send msb 4 bits

lcd_rs=0; //select command register

lcd_en=1; //enable the lcd to execute command

Department of E.C.E, Gudlavalleru Engineering College 43


delay(3);

lcd_en=0;

lcd_data=((value<<4)&(0xf0)); //send lsb 4 bits

lcd_rs=0; //select command register

lcd_en=1; //enable the lcd to execute command

delay(3);

lcd_en=0;

voidlcd_init(void)

lcdcmd(0x02);

lcdcmd(0x02);

lcdcmd(0x28); //intialise the lcd in 4 bit mode*/

lcdcmd(0x28); //intialise the lcd in 4 bit mode*/

lcdcmd(0x0e); //cursor blinking

lcdcmd(0x06); //move the cursor to right side

lcdcmd(0x01); //clear the lcd

voidlcddata(unsigned char value)

lcd_data=value&(0xf0); //send msb 4 bits

lcd_rs=1; //select data register

lcd_en=1; //enable the lcd to execute data

delay(3);

lcd_en=0;

lcd_data=((value<<4)&(0xf0)); //send lsb 4 bits

Department of E.C.E, Gudlavalleru Engineering College 44


lcd_rs=1; //select data register

lcd_en=1; //enable the lcd to execute data

delay(3);

lcd_en=0;

delay(3);

voidmsgdisplay(unsigned char b[]) // send string to lcd

unsigned char s,count=0;

for(s=0;b[s]!='\0';s++)

count++;

if(s==16)

lcdcmd(0xc0);

if(s==32)

lcdcmd(1);

count=0;

lcddata(b[s]);

voidserinit()

TMOD=0x20;

TH1=0xFD; //9600

SCON=0x50;

Department of E.C.E, Gudlavalleru Engineering College 45


TR1=1;

unsigned char receive()

unsigned char rx;

while(RI == 0);

rx=SBUF;

RI=0;

returnrx;

voidsertxs(unsigned char *tx)

for(;*tx != '\0';tx++)

SBUF=*tx;

while(TI == 0);

TI=0;

voidsertx(unsigned char tx)

SBUF=tx;

while(TI == 0);

TI=0;

void main()

Department of E.C.E, Gudlavalleru Engineering College 46


{

unsigned char tt=0,ll;

ir1=1;

ir2=1;

hod=0;

serinit();

lcd_init();

msgdisplay("DYNAMIC DETECTION");

lcdcmd(0xc0);

msgdisplay(" OF A PERSON ");

delay(200);

lcdcmd(0x80);

msgdisplay("COUNT:");

while(1)

if(hod==1) //in

{ tt='1';

//sertx('c');

// lcdcmd(0xc0);

//msgdisplay(" SIR IS IN ");

if(hod==0) //out

{ tt='0';

//sertx('d');

//lcdcmd(0xc0);

//msgdisplay(" SIR IS OUT ");

Department of E.C.E, Gudlavalleru Engineering College 47


}

if(ir1 == 1)

{while(ir1 == 1);

x++;

// sertx('a');

if(ir2 == 1)

{while(ir2 == 1);

x--;

if(x <= 0)

x=0;

sertx('*');

sertx(tt);

convert(x);

sertxs("lkjlskajflksjflkjsdflkjsdlfkjslkfj");

unsigned convert(unsigned int value)

unsigned char a,b,c,d;

a=value/100;

b=value%100;

c=b/10;

Department of E.C.E, Gudlavalleru Engineering College 48


d=b%10;

a=a|0x30;

c=c|0x30;

d=d|0x30;

// lcddata(a);

// lcddata(c);

// lcddata(d);

sertx(a);sertx(c);sertx(d);

return 1;

Program for receiver

#include<reg51.h>

#define lcd_data P2

sbitlcd_rs = P2^0;

sbitlcd_en = P2^1;

unsignedint x=0,y=0, value;

unsigned char rcv;

unsigned convert(unsigned int );

void delay(unsigned int value)

unsignedintx,y;

for(x=0;x<value;x++)

for(y=0;y<200;y++);

Department of E.C.E, Gudlavalleru Engineering College 49


voidlcdcmd(unsigned char value) // LCD COMMAND

lcd_data=value&(0xf0); //send msb 4 bits

lcd_rs=0; //select command register

lcd_en=1; //enable the lcd to execute command

delay(3);

lcd_en=0;

lcd_data=((value<<4)&(0xf0)); //send lsb 4 bits

lcd_rs=0; //select command register

lcd_en=1; //enable the lcd to execute command

delay(3);

lcd_en=0;

voidlcd_init(void)

lcdcmd(0x02);

lcdcmd(0x02);

lcdcmd(0x28); //intialise the lcd in 4 bit mode*/

lcdcmd(0x28); //intialise the lcd in 4 bit mode*/

lcdcmd(0x0e); //cursor blinking

lcdcmd(0x06); //move the cursor to right side

lcdcmd(0x01); //clear the lcd

voidlcddata(unsigned char value)

lcd_data=value&(0xf0); //send msb 4 bits

Department of E.C.E, Gudlavalleru Engineering College 50


lcd_rs=1; //select data register

lcd_en=1; //enable the lcd to execute data

delay(3);

lcd_en=0;

lcd_data=((value<<4)&(0xf0)); //send lsb 4 bits

lcd_rs=1; //select data register

lcd_en=1; //enable the lcd to execute data

delay(3);

lcd_en=0;

delay(3);

voidmsgdisplay(unsigned char b[]) // send string to lcd

unsigned char s,count=0;

for(s=0;b[s]!='\0';s++)

count++;

if(s==16)

lcdcmd(0xc0);

if(s==32)

lcdcmd(1);

count=0;

lcddata(b[s]);

Department of E.C.E, Gudlavalleru Engineering College 51


}

voidserinit()

TMOD=0x20;

TH1=0xFD; //9600

SCON=0x50;

TR1=1;

unsigned char receive()

unsigned char rx;

while(RI == 0);

rx=SBUF;

RI=0;

returnrx;

voidsertxs(unsigned char *tx)

for(;*tx != '\0';tx++)

SBUF=*tx;

while(TI == 0);

TI=0;

voidsertx(unsigned char tx)

Department of E.C.E, Gudlavalleru Engineering College 52


{

SBUF=tx;

while(TI == 0);

TI=0;

voidsie()

ET0 = 0;

ES = 1; /* allow serial interrupts */

EA = 1;

voidsid()

ET0 = 1;

ES = 0; /* allow serial interrupts */

EA = 0;

void main()

unsigned char rcv1,rcv2,rcv3,rcv4,rcv5,x=0;

serinit();

//sie();

//delay(10);

lcd_init();

msgdisplay("DYNAMIC DETECTION");

lcdcmd(0xc0);

Department of E.C.E, Gudlavalleru Engineering College 53


msgdisplay(" OF A PERSON ");

delay(400);lcdcmd(1);

lcdcmd(0x80);

msgdisplay("COUNT:");//0x86..8a

lcdcmd(0x8a);

lcddata('-');//0x8b

//msgdisplay("Norml");

//lcdcmd(0xc0);

while(1)

do{

rcv1 = receive();

}while(rcv1 != '*');

rcv2 = receive();

rcv3 = receive();

rcv4 = receive();

rcv5 = receive();

lcdcmd(0x86);

lcddata(rcv3);lcddata(rcv4);lcddata(rcv5);

x = (((rcv3-0x30)*100) + ((rcv4-0x30)*10) + ((rcv5-0x30)));

if(x <= 5)

lcdcmd(0x8b);msgdisplay("Norml");

if(x > 5)

Department of E.C.E, Gudlavalleru Engineering College 54


lcdcmd(0x8b);msgdisplay("High ");

//lcdcmd(0x8b);

if(rcv2 == '1')

lcdcmd(0xc0);

msgdisplay(" HOD SIR IN ");

if(rcv2 == '0')

lcdcmd(0xc0);

msgdisplay("HOD SIR OUT");

delay(300);

unsigned convert(unsigned int value)

unsigned char a,b,c,d;

a=value/100;

b=value%100;

c=b/10;

d=b%10;

a=a|0x30;

c=c|0x30;

d=d|0x30;

Department of E.C.E, Gudlavalleru Engineering College 55


lcddata(a);

lcddata(c);

lcddata(d);

return 1;

Department of E.C.E, Gudlavalleru Engineering College 56


APPENDIX B

AT89S52 Data Sheet

Absolute Maximum Ratings

DC Characteristics of AT89S52

Department of E.C.E, Gudlavalleru Engineering College 57


Appendix C

LCD Display

Electrical specifications of 16x2 LCD Display

Department of E.C.E, Gudlavalleru Engineering College 58


Appendix D

MAX 232 DATASHEET


Recommended Operating Conditions

Department of E.C.E, Gudlavalleru Engineering College 59

Вам также может понравиться