density based traffic control system

67
DENSITY BASED TRAFFIC CONTROL SYSTEM A Thesis Submitted in partial fulfillment of the requirements for the award of Degree of Bachelor of Technology IN ELECTRICAL AND ELECTRONICS ENGINEERING By D.MANOJ (09261A0215) Department of Electrical and Electronics Engineering

Upload: manoj-dara

Post on 16-Apr-2015

162 views

Category:

Documents


9 download

DESCRIPTION

hi this is the project regarding density based traffic control system very useful and nice topic for the project as well as seminar purpose

TRANSCRIPT

Page 1: Density based traffic control system

DENSITY BASED TRAFFIC CONTROL SYSTEM

A Thesis

Submitted in partial fulfillment of the requirements for the award of

Degree of

Bachelor of Technology

IN

ELECTRICAL AND ELECTRONICS ENGINEERING

By

D.MANOJ (09261A0215)

Department of Electrical and Electronics Engineering

MAHATMA GANDHI INSTITUTE OF TECHNOLOGY

(Affiliated to Jawaharlal Nehru Technological University, Hyderabad, A.P.)

Chaitanya Bharathi P.O., Gandipet, Hyderabad – 500 075

2012

Page 2: Density based traffic control system

DENSITY BASED TRAFFIC CONTROL

SYSTEM

A Thesis

Submitted in partial fulfillment of the requirements for the award of

Degree of

Bachelor of Technology

IN

ELECTRICAL AND ELECTRONICS ENGINEERING

By

D.MANOJ (09261A0215)

Under the esteemed guidance of

Dr.P.ChandrasekharAssosciate Professor

Page 3: Density based traffic control system

Department of Electrical and Electronics EngineeringMAHATMA GANDHI INSTITUTE OF TECHNOLOGY(Affiliated to Jawaharlal Nehru Technological University, Hyderabad, A.P.)

Chaitanya Bharathi P.O., Gandipet, Hyderabad – 500 0752012

MAHATMA GANDHI INSTITUTE OF TECHNOLOGY

(Affiliated to Jawaharlal Nehru Technological University, Hyderabad, A.P.)Chaitanya Bharathi P.O., Gandipet, Hyderabad-500 075

Department of Electrical and Electronics Engineering

CERTIFICATE

This is to certify that the project work entitled DENSITY BASED TRAFFIC

CONTROL SYSTEM is being submitted by D.MANOJ(09261A0215) in partial fulfillment

for the award of Degree of BACHELOR OF TECHNOLOGY in ELECTRICAL &

ELCTRONICS ENGINEERING to the Jawaharlal Nehru Technological University,

Hyderabad during the academic year 2012-13 is a record of bonafide work carried out by

him under our guidance and supervision .

The results embodied in this report have not been submitted by the student(s) to any

other University or Institution for the award of any degree or diploma. (Font: 14, TNR, italic)

Page 4: Density based traffic control system

MINIPROJECT COORDINATOR HEAD OF DEPARTMENT

Dr.P.Chandrasekhar Dr.M.Ramachandra Rao, Associate Professor, Professor & Head, Dept. of EEE, Dept. of EEE, MGIT, MGIT, Hyderabad. Hyderabad. “CERTIFICATE OF THE INTITUTE”

Page 5: Density based traffic control system

ACKNOWLEDGEMENT

I express my deep sense of gratitude to my beloved Principal Dr. G Chandra

Mohan Reddy, for the valuable guidance and for permitting us to carry out this project.

I express my deep sense of gratitude to my beloved professor Dr. D Raghu

Rami Reddy, Professor and Head, Department of Electrical & Electronics Engineering

for the valuable guidance and suggestions, keen interest and through encouragement

extended throughout period of project work.

I express my deep sense of gratitude to my beloved project guide

Mr.V.Ramakrishna for the valuable guidance and suggestions, keen interest and through

encouragement extended throughout period of project work.

I take immense pleasure to express my deep sense of gratitude to our beloved Guide

Dr.P.Chandrasekhar,Associate professor in Electrical and Electronics Engineering, for

his valuable suggestions and rare insights, for constant source of encouragement and

inspiration through out my project work.

I express my thanks to all those who contributed for the successful completion

of my project work.

With gratitude,

Page 6: Density based traffic control system

1 D.MANOJ ________________

CONTENTS

PAGE NO

ABSTRACT i

LIST OF FIGURES ii

LIST OF TABLES iii

CHAPTER1:INTRODUCTION

1.1 AIM---------------------------------------------------------------------- 1

1.2 BLOCK DIAGRAM--------------------------------------------------- 2

1.3 BLOCK DIAGRAM EXPLANATION----------------------------- 3

1.4 IR TRANSMITTER & IR RECEIVER----------------------------- 3

1.5 SCHEMATIC DIAGRAM------------------------------------------- 6

1.6 SCHEMATIC DIAGRAM EXPLANATION---------------------- 7

CHAPTER 2:HARDWARE COMPONENTS

2.1 AT89S52 MICROCONTROLLER---------------------------------- 8

2.1.1 DISCRIPTION---------------------------------------------------- 8

2.1.2 FEATURES------------------------------------------------------- 9

2.1.3 BLOCK DIAGRAM--------------------------------------------- 10

2.1.4 PIN DIAGRAM-------------------------------------------------- 11

2.1.5 PIN DISCRIPTION---------------------------------------------- 12

2.2 POWER SUPPLY------------------------------------------------------ 20

Page 7: Density based traffic control system

2.3 REGULATOR---------------------------------------------------------- 20

2.4 TRANSFORMER------------------------------------------------------ 21

2.5 CAPACITOR FILTER------------------------------------------------ 22

2.6 LEDS--------------------------------------------------------------------- 23

2.6.1 FUNCTION-------------------------------------------------------- 23

2.6.2 CONNECTING AND SOLDERING--------------------------- 23

2.6.3 TESTING AN LED----------------------------------------------- 24

2.7 IR LED------------------------------------------------------------------- 24

2.7.1 DESCRIPTION----------------------------------------------------24

2.7.2 FEATURES-------------------------------------------------------- 25

CHAPTER3: LCD INTEERFACING

3.1 INTRODUCTION------------------------------------------------------ 25

3.2 PIN DISCRIPTION---------------------------------------------------- 25

CHAPTER4: WORKING FLOW OF PROJECT & CONCLUSION

4.1 BLOCK DIAGRAM---------------------------------------------------- 30

4.2 CIRCUIT DESCRIPTION--------------------------------------------- 31

4.3 SOFTWARE------------------------------------------------------------- 32

4.3.1 KEIL VISION------------------------------------------------------ 32

4.3.2 EMBEDDED------------------------------------------------------- 33

4.4 CONCLUSION---------------------------------------------------------- 34

REFERENCES------------------------------------------------------------------- 35

Page 8: Density based traffic control system

ABSTRACT

Traffic is formally organized in many jurisdictions, with marked lanes, junctions,

intersections, interchanges, traffic signals, or signs. Traffic is often classified by type: heavy

motor vehicle (e.g., car, truck); other vehicle (e.g., moped, bicycle); and pedestrian. Different

classes may share speed limits and easement, or may be segregated. Some jurisdictions may

have very detailed and complex rules of the road.

One of the main problems in our city’s is traffic, this project proposed new solution to

traffic control. The main design accept of this project is to control the traffic automatically

and adding human inelegancy to that automatic controller. "Four-way" intersection is the

most common configuration for roads that cross each other, and the most basic type. If

signals do not control a 4-way intersection, signs or other features are typically used to

control movements and make clear priorities.

In this project we are going to use IR communication to analyze traffic density. IR

signals from IR receiver are given to microcontroller and microcontroller gives appropriate

result according to traffic. For better result we are going to use some bunch of IR transmitters

and IR receivers in all directions. When there is a more traffic in one side more no. of IR

receivers will not get the signals and result will compare with all other directions and

microcontroller gives green signals at one side where more no of IR receivers will not get the

signals.

Page 9: Density based traffic control system

For IR communication we are using an IR transmitter and IR receiver. Here IR LED

will acts as a transmitter. As we know microcontroller having inbuilt I/O ports and we are

interfacing IR receivers to those I/O ports. For controlling of traffic we are using red, green

and yellow color LED’s. These LED’s are connected to different I/O ports of

microcontroller. When there is a more traffic microcontroller gives signal to green LED and

it will glow. So by using this project we can control the traffic automatically like a human

being.

(i)

LIST OF FIGURES

FIG 1.1.a: A JUNCTION WITH LED & IR SENSORS--------------------------------------- 1

FIG 1.2.a: BLOCK DIAGRAM------------------------------------------------------------------- 2

FIG 1.4.a: CIRCUIT OF IR TRANSMITTER--------------------------------------------------- 4

FIG 1.4.b: CIRCUIT OF IR RECEIVER--------------------------------------------------------- 4

FIG 1.5.a : SCHEMATIC DIAGRAM OF CIRCUIT------------------------------------------- 6

FIG 2.1.a: AT89S52 MICROCONTROLLER--------------------------------------------------- 9

FIG 2.1.b: BLOCK DIAGRAM OF AT89S52 MICROCONTROLLER------------------- 10

FIG 2.1.c: PIN DIAGRAM OF AT89S52---------------------------------------------- 11

FIG 2.1.d: OSCILLATOR CONNECTIONS--------------------------------------------------- 18

FIG 2.1.e: EXTERNAL CLOCK DRIVE CONFIGURATION------------------------------ 19

FIG 2.2.a: REGULATED POWER SUPPLY--------------------------------------------------- 20

FIG 2.3.a: EXAMPLE CIRCUIT SHOWING

5V DC OUTPUT ----------------------------------------------------------- 21

FIG 2.4.a: AN ELECTRICAL TRANSFORMER--------------------------------------------- 22

FIG 2.6.a: LED-------------------------------------------------------------------------------------- 23

FIG 2.6.b: CIRCUIT DIAGRAM OF LED----------------------------------------------------- 23

FIG 2.7.a: IR LED---------------------------------------------------------------------------------- 24

FIG 2.7.b: SCHEMATIC DIAGRAM OF IR LED-------------------------------------------- 24

FIG 4.1.a: BLOCK DIAGRAM OF WORKING OF PROJECT---------------------------- 30

Page 10: Density based traffic control system

(ii)

LIST OF TABLES

TABLE 2.1.A: PORTS SHOWING THE ALTERNATE FUNCTIONS AT PORT 1----- 12

TABLE 2.1.B: PORTS SHOWING THE ALTERNATE FUNCTIONS AT PORT 3----- 14

TABLE2.1.C: TIMER 2 OPERATING MODES--------------------------------------- 17

TABLE 3.2.A: PIN DISCRIPTION OF LCD------------------------------------------- 26

TABLE4.3.A: EMBEDDED “C” DATA TYPES------------------------------------------------ 33

Page 11: Density based traffic control system

(iii)

CHAPTER-1

Introduction

1.1 AIM:

The project “intelligent traffic management system for metro cites”, is based on the

microcontroller which will provide the controlling of the traffic depending upon the density.

According to the signaling i.e. continuity between the IR transmitter and IR receiver the

Timing of the green, red lights will be glown for the particular time depending upon the

density.

The micro controller will monitor the all control functionalities. According to the controller

signalling the density will be monitored by lights.

Microcontroller based traffic control system is an application specific project, which is used

to control the traffic. An embedded system is developed which consists of a microcontroller,

IR transmitter and receiver, LED’s

This project is implemented by placing IR transmitters, receivers and led’s at the 4 way

junction, the four paths are represented as R1,R2,R3,R4

Page 12: Density based traffic control system

FIG 1.1.a: A JUNCTION WITH LED & IR SENSORS

Transmitters and receivers are placed at either sides of the four paths, and 4 led’s at corner of

the junction When there is a traffic along the paths,value of R would be 000 which are the

values of IR sensors and if there is no traffic the value is 111

1

1.2 BLOCK DIAGRAM:

Page 13: Density based traffic control system

FIG 1.2.a: BLOCK DIAGRAM

2

1.3 Block diagram explanation:

Micro controller(ATS8952)

POWER SUPPLY

Signals from IR receivers from all directions

RED

GREEN

ROAD 3

RED

GREEN

ROAD 4

RED

GREEN

ROAD 1 RED

GREEN

ROAD 2

IR Transmitter signalsFrom all directions

Page 14: Density based traffic control system

The main objective of this project is to control the traffic depending upon the

density .As there is much time wastage with the traffic lights which involves the Time, we

are designing the new system which controls the traffic depending upon the density.

Here we place IR transmitter and the IR receivers at both ends of the roads. Whenever the

vehicles pass in-between them the continuity will be lost. Hence the microcontroller senses

the density is high.

Then the microcontroller will be making the light (green) to be glow much time at the place

where the traffic is high.

The same procedure will be followed by four sides of the road. The signalling from the four

sides will be taken into consideration and depending upon the density controller will make

the decision .

The system uses a compact circuitry build around flash version of AT89S52

Microcontroller with a non-volatile memory. Programs will be developed in EMBEDDED C

language. FLASH MAGIC is used for loading of programs into microcontroller.

1.4 IR TRANSMITTER & RECEIVER:

The purpose of the transmitter is to transform the information we want to send into a signal

that can be propagated by the channel. In the case of our wired copper channel, this means

we want the information to be transformed into a modulated voltage level, something like the

pulse train. For a wireless channel, however, the transmitter needs to encode the information

onto an EM wave that can be easily propagated.

3

IR TRANSMITTER:

Page 15: Density based traffic control system

FIG 1.4.a: CIRCUIT OF IR TRANSMITTER

The IR transmitter part consists of an Infra red light emitting diode that can capable of

sending modulated data within infra red band. To match the receiver frequency the the data is

modulated at 38.7 KHZ by configuring 555 timer at astable mode of operation, which

generates frequency using the components R2 and C2 as shown in above fig. This frequency

can be varied over a long range just by varying the preset R1 and C1.

IR RECEIVER:

FIG 1.4.b: CIRCUIT OF IR RECEIVER

4

Page 16: Density based traffic control system

The IR receiver consists of TSOP 1738 module which is a simple yet effective IR proximity

sensor built around the TSOP 1738 module. The TSOP module is commonly found at the

receiving end of an IR remote control system; e.g., in TVs, CD players etc. These modules

require the incoming data to be modulated at a particular frequency and would ignore any

other IR signals. It is also immune to ambient IR light, so one can easily use these sensors

Outdoororunderheavilyconditions.

Such modules are available for different carrier frequencies from 32 kHz to 42kHz.

In this particular proximity sensor, we will be generating a constant stream of square wave

signal using IC555 centered at 38 kHz and would use it to drive an IR led. So whenever this

signal bounces off the obstacles, the receiver would detect it and change its output. Since the

TSOP 1738 module works in the active-low configuration, its output would normally remain

high and would go low when it detects the signal (the obstacle).

Basically an ir sensor is used for detecting an obstacle, there are some areas where valuable

things are placed, an IR transmitter and receiver is placed there, an infrared path is

established and if any person comes into that path the buzzer gets on which gives out a long

beep Similarly a fire sensor is used to detect fire

The sensed data is given to the microcontroller, processing is done according to the logic in

the microcontroller and then writes onto GSM which will further send sms to the mobile at

the user

A buzzer is interfaced to microcontroller to give out a beep sound whenever an obstacle and

fire is detected

Page 17: Density based traffic control system

5

Page 18: Density based traffic control system

1.5 SCHEMATIC DIAGRAM:

FIG 1.5.a : SCHEMATIC DIAGRAM OF CIRCUIT

6

Page 19: Density based traffic control system

1.6 SCHEMATIC EXPLANATION:power supply:

The schematic diagram gives the basic hardware connections used in the project.

Beginning from the power supply the secondary of the step-down transformer wires are

given to the two ends (2,4) of bridge rectifier which is having the four diodes in the bridge

formate.The other two ends 1,3)are connected to the input(pin 1) and output pin 3 of the 7805

regulator and pin no 2 is connected to ground as shown in schematic diagram. The 1000

micro farad capacitor is connected in between the bridge rectifier and regulator to eliminate

the ac ripples presented in the rectified output. The 100 micro farad capacitor is used to

eliminate the noise at regulator output. Now 5V is available at the pin no 3 of regulator and

connected to pin no 40 of micro controller.

AT89S52 Micro controller :

The 8051 micro controller consists 40 pins and every pin has its own functionality as

shown in the schematic diagram.

The port 0 is having the pull up resistor which is having eight 10K resistors in

parallel each connected to the each pin of it.

IR LED:

The IR LED is arranged with a resistor ,in such a way that Vcc is applied to the positive

terminal of the IR LED.These are connected to the port 1 of the microcontroller.

IR RECEIVER:

The IR receivers are arranged with the transistor logic as shown in the diagram.

The two transistors are connected in such a manner that collector terminal is connected to the

base terminal of the other. The photo diode is connected to the base of the transistor along

with the combination of the resistor.

The IR Receivers are connected to the port 2 P2.0,,P2.1,P2.2,P2.3 pins of the

microcontroller.

7

Page 20: Density based traffic control system

CHAPTER-2HARDWARE COMPONENTS

2.1 AT89S52 MICROCONTROLLER:

2.1.1Description:

The AT89S52 is a low-power, high-performance CMOS 8-bit microcontroller with

8K bytes of in-system programmable Flash memory. The device is manufactured

using Atmel’s high-density nonvolatile memory technology and is compatible with

the indus-try-standard 80C51 instruction set and pinout. The on-chip Flash allows the

program memory to be reprogrammed in-system or by a conventional nonvolatile

memory pro-grammer. By combining a versatile 8-bit CPU with in-system

programmable Flash on a monolithic chip, the Atmel AT89S52 is a powerful

microcontroller which provides a highly-flexible and cost-effective solution to many

embedded control applications. The AT89S52 provides the following standard

features: 8K bytes of Flash, 256 bytes of RAM, 32 I/O lines, Watchdog timer, two

data pointers, three 16-bit timer/counters, a six-vector two-level interrupt architecture,

a full duplex serial port, on-chip oscillator, and clock circuitry. In addition, the

AT89S52 is designed with static logic for operation down to zero frequency and

supports two software selectable power saving modes. The Idle Mode stops the CPU

while allowing the RAM, timer/counters, serial port, and interrupt system to continue

functioning. The Power-down mode saves the RAM con-tents but freezes the

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

8

Page 21: Density based traffic control system

FIG 2.1.a: AT89S52 MICROCONTROLLER

2.1.2 Features :

• Compatible with MCS®-51 Products

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

• 4.0V to 5.5V Operating Range

• Fully Static Operation: 0 Hz to 33 MHz

• Three-level Program Memory Lock

• 256 x 8-bit Internal RAM

• 32 Programmable I/O Lines

• Three 16-bit Timer/Counters

• Eight Interrupt Sources

• Full Duplex UART Serial Channel

• Low-power Idle and Power-down Modes

• Interrupt Recovery from Power-down Mode

• Watchdog Timer

• Dual Data Pointer

9

Page 22: Density based traffic control system

• Power-off Flag

• Fast Programming Time

• Flexible ISP Programming (Byte and Page Mode)

• Green (Pb/Halide-free) Packaging Option

2.1.3BlockDiagram:

FIG 2.1.b: BLOCK DIAGRAM OF AT89S52 MICROCONTROLLER

10

Page 23: Density based traffic control system

2.1.4 PIN DIAGRAM:

FIG 2.1.c: PIN DIAGRAM OF AT89S52

11

Page 24: Density based traffic control system

Pin Description:

VCC :Supply voltage.

GND: Ground.

Port 0 :Port 0 is an 8-bit open drain bidirectional I/O port. As an output port, each pin can

sink eight TTL inputs. When 1s are written to port 0 pins, the pins can be used as high-

impedance inputs. Port 0 can also be configured to be the multiplexed low-order address/data

bus during accesses to external program and data memory. In this mode, P0 has internal pull-

ups. Port 0 also receives the code bytes during Flash programming and outputs the code bytes

dur-ing program verification.

Port 1:

Port 1 is an 8-bit bidirectional I/O port with internal pull-ups. The Port 1 output buffers can

sink/source four TTL inputs. When 1s are written to Port 1 pins, they are pulled high by the

inter-nal pull-ups and can be used as inputs. As inputs, Port 1 pins that are externally being

pulled low will source current (IIL) because of the internal pull-ups. In addition, P1.0 and

P1.1 can be configured to be the timer/counter 2 external count input (P1.0/T2) and the

timer/counter 2 trigger input (P1.1/T2EX), respectively, as shown in the follow-ing table.

Port 1 also receives the low-order address bytes during Flash programming and verification.

TABLE 2.1.A: PORTS SHOWING THE ALTERNATE FUNCTIONS AT PORT 1

12

Page 25: Density based traffic control system

Port 2:

Port 2 is an 8-bit bidirectional I/O port with internal pull-ups. The Port 2 output buffers can

sink/source four TTL inputs. When 1s are written to Port 2 pins, they are pulled high by the

inter-nal pull-ups and can be used as inputs. As inputs, Port 2 pins that are externally being

pulled low will source current (IIL) because of the internal pull-ups. Port 2 emits the high-

order address byte during fetches from external program memory and dur-ing accesses to

external data memory that use 16-bit addresses (MOVX @ DPTR). In this application, Port 2

uses strong internal pull-ups when emitting 1s. During accesses to external data memory that

use 8-bit addresses (MOVX @ RI), Port 2 emits the contents of the P2 Special Function

Register. Port 2 also receives the high-order address bits and some control signals during

Flash program-ming and verification.

Port Pin Alternate Functions:

P1.0 T2 (external count input to Timer/Counter 2), clock-out P1.1 T2EX (Timer/Counter 2

capture/reload trigger and direction control) P1.5 MOSI (used for In-System Programming)

P1.6 MISO (used for In-System Programming) P1.7 SCK (used for In-System

Programming)5 1919D–MICRO–6/

Port 3:

Port 3 is an 8-bit bidirectional I/O port with internal pull-ups. The Port 3 output buffers can

sink/source four TTL inputs. When 1s are written to Port 3 pins, they are pulled high by the

inter-nal pull-ups and can be used as inputs. As inputs, Port 3 pins that are externally being

pulled low will source current (IIL) because of the pull-ups. Port 3 receives some control

signals for Flash programming and verification. Port 3 also serves the functions of various

special features of the AT89S52, as shown in the fol-lowing table.

13

Page 26: Density based traffic control system

TABLE 2.1.B:PORTS SHOWING THE ALTERNATE FUNCTIONS AT PORT 3

RST:

Reset input. A high on this pin for two machine cycles while the oscillator is running resets

the device. This pin drives high for 98 oscillator periods after the Watchdog times out. The

DISRTO bit in SFR AUXR (address 8EH) can be used to disable this feature. In the default

state of bit DISRTO, the RESET HIGH out feature is enabled.

ALE/PROG:

Address Latch Enable (ALE) is an output pulse for latching the low byte of the address

during accesses to external memory. This pin is also the program pulse input (PROG) during

Flash programming. In normal operation, ALE is emitted at a constant rate of 1/6 the

oscillator frequency and may be used for external timing or clocking purposes. Note,

however, that one ALE pulse is skipped dur-ing each access to external data memory. If

desired, ALE operation can be disabled by setting bit 0 of SFR location 8EH. With the bit

set, ALE is active only during a MOVX or MOVC instruction. Otherwise, the pin is weakly

pulled high. Setting the ALE-disable bit has no effect if the microcontroller is in external

execution mode

14

Page 27: Density based traffic control system

PSEN: Program Store Enable (PSEN) is the read strobe to external program memory.When

the AT89S52 is executing code from external program memory, PSEN is activated twice

each machine cycle, except that two PSEN activations are skipped

XTAL1: Input to the inverting oscillator amplifier and input to the internal clock operating

circuit.

XTAL2 :Output from the inverting oscillator amplifier.

Program Memory:

If the EA pin is connected to GND, all program fetches are directed to external memory. On

the AT89S52, if EA is connected to VCC, program fetches to addresses 0000H through

1FFFH are directed to internal memory and fetches to addresses 2000H through FFFFH are

to external memory.

Data Memory: The AT89S52 implements 256 bytes of on-chip RAM. The upper 128

bytes occupy a parallel address space to the Special Function Registers. This means that the

upper 128 bytes have the same addresses as the SFR space but are physically separate from

SFR space. When an instruction accesses an internal location above address 7FH, the address

mode used in the instruction specifies whether the CPU accesses the upper 128 bytes of

RAM or the SFR space. Instructions which use direct addressing access the SFR space. For

example, the following direct addressing instruction accesses the SFR at location 0A0H

(which is P2). MOV 0A0H, #data Instructions that use indirect addressing access the upper

128 bytes of RAM. For example, the following indirect addressing instruction, where R0

contains 0A0H, accesses the data byte at address 0A0H, rather than P2 (whose address is

0A0H). MOV @R0, #data Note that stack operations are examples of indirect addressing, so

the upper 128 bytes of data RAM are available as stack space.

15

Page 28: Density based traffic control system

Watchdog Timer (One-time Enabled with Reset-out):

The WDT is intended as a recovery method in situations where the CPU may be subjected to

software upsets. The WDT consists of a 14-bit counter and the Watchdog Timer Reset

(WDTRST) SFR. The WDT is defaulted to disable from exiting reset. To enable the WDT, a

user must write 01EH and 0E1H in sequence to the WDTRST register (SFR location 0A6H).

When the WDT is enabled, it will increment every machine cycle while the oscillator is

running. The WDT timeout period is dependent on the external clock frequency. There is no

way to disable the WDT except through reset (either hardware reset or WDT overflow reset).

When WDT over-flows, it will drive an output RESET HIGH pulse at the RST pin.

Using the WDT:

To enable the WDT, a user must write 01EH and 0E1H in sequence to the WDTRST register

(SFR location 0A6H). When the WDT is enabled, the user needs to service it by writing

01EH and 0E1H to WDTRST to avoid a WDT overflow. The 14-bit counter overflows when

it reaches 16383 (3FFFH), and this will reset the device. When the WDT is enabled, it will

increment every machine cycle while the oscillator is running. This means the user must reset

the WDT at least every 16383 machine cycles. To reset the WDT the user must write 01EH

and 0E1H to WDTRST. WDTRST is a write-only register. The WDT counter cannot be read

or written. WhenWDT overflows, it will generate an output RESET pulse at the RST pin.

The RESET pulse dura-tion is 98xTOSC, where TOSC = 1/FOSC. To make the best use of

the WDT, it should be serviced in those sections of code that will periodically be executed

within the time required to prevent a WDT reset.

UART :The UART in the AT89S52 operates the same way as the UART in the AT89S52

and AT89C52.

16

Page 29: Density based traffic control system

Timer 0 and 1

Timer 0 and Timer 1 in the AT89S52 operate the same way as Timer 0 and Timer 1 in the

AT89S52 and AT89C52.

Timer 2

Timer 2 is a 16-bit Timer/Counter that can operate as either a timer or an event counter. The

type of operation is selected by bit C/T2 in the SFR T2CON (shown in Table 5-2). Timer 2

has three operating modes: capture, auto-reload (up or down counting), and baud rate

generator. The modes are selected by bits in T2CON, as shown in Table 10-1. Timer 2

consists of two 8-bit registers, TH2 and TL2. In the Timer function, the TL2 register is

incremented every machine cycle. Since a machine cycle consists of 12 oscillator periods, the

count rate is 1/12 of the oscil-lator frequency.

TABLE2.1.C: TIMER 2 OPERATING MODES

In the Counter function, the register is incremented in response to a 1-to-0 transition at its

corre-sponding external input pin, T2. In this function, the external input is sampled during

S5P2 of every machine cycle. When the samples show a high in one cycle and a low in the

next cycle, the count is incremented. The new count value appears in the register during

S3P1 of the cycle following the one in which the

17

Page 30: Density based traffic control system

transition was detected. Since two machine cycles (24 oscillator periods) are required to

recognize a 1-to-0 transition, the maximum count rate is 1/24 of the oscillator frequency. To

ensure that a given level is sampled at least once before it changes, the level should be held

for at least one full machine cycle.

Oscillator Characteristics:

XTAL1 and XTAL2 are the input and output, respectively, of an inverting amplifier that can

be configured for use as an on-chip oscillator, as shown in Figure 16-1. Either a quartz

crystal or ceramic resonator may be used. To drive the device from an external clock source,

XTAL2 should be left unconnected while XTAL1 is driven, as shown in Figure 16-2. There

are no requirements on the duty cycle of the external clock signal, since the input to the

internal clock-ing circuitry is through a divide-by-two flip-flop, but minimum and maximum

voltage high and low time specifications must be observed.

FIG2.1.d: oscillator connections

18

Page 31: Density based traffic control system

FIG 2.1.e: External clock drive configuration

Programming the Flash – Parallel Mode:

The AT89S52 is shipped with the on-chip Flash memory array ready to be programmed. The

programming interface needs a high-voltage (12-volt) program enable signal and is

compatible with conventional third-party Flash or EPROM programmers. The AT89S52

code memory array is programmed byte-by-byte.

Programming Algorithm:

Before programming the AT89S52, the address, data, and control signals should be set up

according to the “Flash Programming Modes” (Table 22-1) and Figure 22-1 and Figure 22-2.

To program the AT89S52, take the following steps: 1. Input the desired memory location on

the address lines. 2. Input the appropriate data byte on the data lines. 3. Activate the correct

combination of control signals. 4. Raise EA/VPP to 12V. 5. Pulse ALE/PROG once to

program a byte in the Flash array or the lock bits. The byte-write cycle is self-timed and

typically takes no more than 50 μs. Repeat steps 1 through 5, changing the address and data

for the entire array or until the end of the object file is reached.

19

Page 32: Density based traffic control system

2.2 Power supply:

The power supplies are designed to convert high voltage AC mains electricity to a

suitable low voltage supply for electronics circuits and other devices. A power supply can by

broken down into a series of blocks, each of which performs a particular function. A d.c

power supply which maintains the output voltage constant irrespective of a.c mains

fluctuations or load variations is known as “Regulated D.C Power Supply”

FIG 2.2.a: 5V Regulated power supply

2.3 VOLTAGE REGULATOR

Voltage regulator ICs is available with fixed (typically 5, 12 and 15V) or variable output

voltages. The maximum current they can pass also rates them. Negative voltage regulators

are available, mainly for use in dual supplies. Most regulators include some automatic

protection from excessive current ('overload protection') and overheating ('thermal

protection'). Many of the fixed voltage regulator ICs have 3 leads and look like power

transistors, such as the 7805 +5V 1A regulator shown on the right. The LM7805 is simple to

20

Page 33: Density based traffic control system

use. You simply connect the positive lead of your unregulated DC power supply (anything

from 9VDC to 24VDC) to the Input pin, connect the negative lead to the Common pin and

then when you turn on the power, you get a 5 volt supply from the output pin.

FIG 2.3.a: example circuit showing 5v DC output

2.4 Transformer

A transformer is an electrical device which is used to convert electrical power from one

Electrical circuit to another without change in frequency.

Transformers convert AC electricity from one voltage to another with little loss of

power. Transformers work only with AC and this is one of the reasons why mains electricity

is AC. Step-up transformers increase in output voltage, step-down transformers decrease in

output voltage. Most power supplies use a step-down transformer to reduce the dangerously

high mains voltage to a safer low voltage. The input coil is called the primary and the output

coil is called the secondary. There is no electrical connection between the two coils; instead

they are linked by an alternating magnetic field created in the soft-iron core of the

transformer. The two lines in the middle of the circuit symbol represent the core.

Transformers waste very little power so the power out is (almost) equal to the power in. Note

that as voltage is stepped down current is stepped up. The ratio of the number of turns on

each coil, called the turn’s ratio, determines the ratio of the voltages. A step-down

transformer has a large number of turns on its primary (input) coil which is connected to the

high voltage mains supply, and a small number of turns on its secondary (output) coil to give

a low output voltage.

21

Page 34: Density based traffic control system

FIG 2.4.a: An Electrical Transformer

Turns ratio = Vp/ VS = Np/NS

Power Out= Power In

VS X IS=VP X IP

Vp = primary (input) voltage

Np = number of turns on primary coil

Ip  = primary (input) current    

2.5 Capacitor Filter

We have seen that the ripple content in the rectified output of half wave rectifier is 121%

or that of full-wave or bridge rectifier or bridge rectifier is 48% such high percentages of

ripples is not acceptable for most of the applications. Ripples can be removed by one of the

following methods of filtering.

(a) A capacitor, in parallel to the load, provides an easier by –pass for the ripples voltage

though it due to low impedance. At ripple frequency and leave the d.c.to appears the load.

(b) An inductor, in series with the load, prevents the passage of the ripple current (due to

high impedance at ripple frequency) while allowing the d.c (due to low resistance to d.c)

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

multiple section filter etc. which make use of both the properties mentioned in (a) and (b)

above. Two cases of capacitor filter, one applied on half wave rectifier and another with full

wave rectifier.

22

Page 35: Density based traffic control system

Filtering is performed by a large value electrolytic capacitor connected across the DC

supply to act as a reservoir, supplying current to the output when the varying DC voltage

from the rectifier is falling. The capacitor charges quickly near the peak of the varying DC,

and then discharges as it supplies current to the output. Filtering significantly increases the

average DC voltage to almost the peak value (1.4 × RMS value).

To calculate the value of capacitor(C),

C = ¼*√3*f*r*Rl

Where,

f = supply frequency,

r = ripple factor,

Rl = load resistance

Note: In our circuit we are using 1000µF. Hence large value of capacitor is placed to

reduce ripples and to improve the DC component.

2.6 Light Emitting Diodes (LEDs)

Example:        Circuit symbol:   

FIG 2.6.a: LED FIG 2.6.b:CIRCUIT OF LED

2.6.1 Function:

LEDs emit light when an electric current passes through them.

2.6.2 Connecting and soldering:

LEDs must be connected the correct way round, the diagram may be labelled a or +

for anode and k or - for cathode (yes, it really is k, not c, for cathode!). The cathode is the

short lead and there may be a slight flat on the body of round LEDs. If you can see inside the

LED the cathode is the larger electrode (but this is not an official identification method).

23

Page 36: Density based traffic control system

LEDs can be damaged by heat when soldering, but the risk is small unless you are

very slow. No special precautions are needed for soldering most LEDs.

2.6.3 Testing an LED:

Never connect an LED directly to a battery or power supply!

It will be destroyed almost instantly because too much current will pass through and burn it

out. LEDs must have a resistor in series to limit the current to a safe value, for quick testing

purposes a 1k resistor is suitable for most LEDs if your supply voltage is 12V or less.

Remember to connect the LED the correct way round!

2.7 IR LED:

2.7.1 DESCRIPTION:

The QED233 / QED234 is a 940 nm GaAs/AlGaAs LED encapsulated in a clear untinted,

plastic T-1 3/4 package.

FIG2.7.A: IR LED FIG2.7.B: SCHEMATIC OF IR LED

24

Page 37: Density based traffic control system

2.7.2 FEATURES:

• Lambda= 940 nm

• Chip material =GaAs with AlGaAs window

• Package type: T-1 3/4 (5mm lens diameter)

• Matched Photo sensor: QSD122/123/124

• Medium Emission Angle, 40°

• High Output Power

• Package material and color: Clear, untinted, plastic

• Ideal for remote control applications

CHAPTER-3

LCD INTERFACING

3.1 Introduction:

The most commonly used Character based LCDs are based on Hitachi's HD44780 controller

or other which are compatible with HD44580. In this tutorial, we will discuss about character

based LCDs, their interfacing with various microcontrollers, various interfaces (8-bit/4-bit),

programming, special stuff and tricks you can do with these simple looking LCDs which can

give a new look to your application.

3.2 Pin Discription:

The most commonly used LCD’s found in the market today are 1 Line, 2 Line or 4 Line

LCDs which have only 1 controller and support at most of 80 characters, whereas LCDs

supporting more than 80 characters make use of 2 HD44780 controllers.

Most LCDs with 1 controller has 14 Pins and LCDs with 2 controller has 16 Pins (two pins

are extra in both for back-light LED connections). Pin description is shown in the table

below.

25

Page 38: Density based traffic control system

TABLE 3.2.A: PIN DISCRIPTION OF LCD

26

Pin No. Name Description

Pin no. 1 VSS Power supply (GND)

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

Pin no. 3 VEE Contrast adjust

Pin no. 4 RS0 = Instruction input

1 = Data input

Pin no. 5 R/W0 = Write to LCD module

1 = Read from LCD module

Pin no. 6 EN Enable signal

Pin no. 7 D0 Data bus line 0 (LSB)

Pin no. 8 D1 Data bus line 1

Pin no. 9 D2 Data bus line 2

Pin no. 10 D3 Data bus line 3

Pin no. 11 D4 Data bus line 4

Pin no. 12 D5 Data bus line 5

Pin no. 13 D6 Data bus line 6

Pin no. 14 D7 Data bus line 7 (MSB)

Page 39: Density based traffic control system

DDRAM - Display Data RAM:

Display data RAM (DDRAM) stores display data represented in 8-bit character codes. Its

extended capacity is 80 X 8 bits, or 80 characters. The area in display data RAM (DDRAM)

that is not used for display can be used as general data RAM. So whatever you send on the

DDRAM is actually displayed on the LCD. For LCDs like 1x16, only 16 characters are

visible, so whatever you write after 16 chars is written in DDRAM

CGROM - Character Generator ROM:

Now you might be thinking that when you send an ASCII value to DDRAM, how the

character is displayed on LCD? So the answer is CGROM. The character generator ROM

generates 5 x 8 dot or 5 x 10 dot character patterns from 8-bit character codes (see Figure 5

and Figure 6 for more details). It can generate 208 5 x 8 dot character patterns and 32 5 x 10

dot character patterns. User defined character patterns are also available by mask-

programmed ROM.As you can see in both the code maps, the character code from 0x00 to

0x07 is occupied by the CGRAM characters or the user defined characters. If user wants to

display the fourth custom character then the code to display it is 0x03 i.e. when user sends

0x03 code to the LCD DDRAM then the fourth user created character or pattern will be

displayed on the LCD.

CGRAM - Character Generator RAM:

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

character generator RAM, the user can rewrite character patterns by program. For 5 x 8 dots,

eight character patterns can be written, and for 5 x 10 dots, four character patterns can be

written.

BF - Busy Flag:

Busy Flag is a status indicator flag for LCD. When we send a command or data to the LCD

for processing, this flag is set (i.e. BF =1) and as soon as the instruction is executed

27

Page 40: Density based traffic control system

successfully this flag is cleared (BF = 0). This is helpful in producing and exact amount of

delay for the LCD processing.To read Busy Flag, the condition RS = 0 and R/W = 1 must be

met and The MSB of the LCD data bus (D7) act as busy flag. When BF = 1 means LCD is

busy and will not accept next command or data and BF = 0 means LCD is ready for the next

command or data to process.

Instruction Register (IR) and Data Register (DR):

There are two 8-bit registers in HD44780 controller Instruction and Data register. Instruction

register corresponds to the register where you send commands to LCD e.g. LCD shift

command, LCD clear, LCD address etc. and Data register is used for storing data which is to

be displayed on LCD. When send the enable signal of the LCD is asserted, the data on the

pins is latched in to the data register and data is then moved automatically to the DDRAM

andhenceisdisplayedontheLCD.

Data Register is not only used for sending data to DDRAM but also for CGRAM, the address

where you want to send the data, is decided by the instruction you send to LCD.

4-bit programming of LCD:

In 4-bit mode the data is sent in nibbles, first we send the higher nibble and then the lower

nibble. To enable the 4-bit mode of LCD, we need to follow special sequence of initialization

that tells the LCD controller that user has selected 4-bit mode of operation. We call this

special sequence as resetting the LCD. Following is the reset sequence of LCD.

Wait for about 20mS

Send the first init value (0x30)

Wait for about 10mS

Send second init value (0x30)

Wait for about 1mS

Send third init value (0x30)

Wait for 1mS

Select bus width (0x30 - for 8-bit and 0x20 for 4-bit)

28

Page 41: Density based traffic control system

The busy flag will only be valid after the above reset sequence. Usually we do not use busy

flag in 4-bit mode as we have to write code for reading two nibbles from the LCD. Instead

we simply put a certain amount of delay usually 300 to 600uS. This delay might vary

depending on the LCD you are using, as you might have a different crystal frequency on

which LCD controller is running. So it actually depends on the LCD module you are using.

In 4-bit mode, we only need 6 pins to interface an LCD. D4-D7 are the data pins connection

and Enable and Register select are for LCD control pins. We are not using Read/Write (RW)

Pin of the LCD, as we are only writing on the LCD so we have made it grounded

permanently. If you want to use it, then you may connect it on your controller but that will

only increase another pin and does not make any big difference. Potentiometer RV1 is used

to control the LCD contrast. The unwanted data pins of LCD i.e. D0-D3 are connected to

ground.

Sending data/command in 4-bit Mode:

We will now look into the common steps to send data/command to LCD when working in 4-

bit mode. In 4-bit mode data is sent nibble by nibble, first we send higher nibble and then

lower nibble. This means in both command and data sending function we need to separate the

higher 4-bits and lower 4-bits.The common steps are:

Mask lower 4-bits

Send to the LCD port

Send enable signal

Mask higher 4-bits

Send to LCD port

Send enable signal

29

Page 42: Density based traffic control system

CHAPTER-4

WORKING FLOW OF THE PROJECT&CONCLUSION

4.1 BLOCK DIAGRAM:

FIG 4.1.a: BLOCK DIAGRAM OF WORKING OF PROJECT

This project is mainly designed to reduce traffic problems. i.e. in general the four sides of the

road at a signal point are controlled at regular intervals of time with a certain time delay. But

in order to reduce the time at one side of the signal point with respect to the other side where

there is more traffic we use IR sensors. It mainly consists of a microcontroller. IR transmitter

placed nearer to the signal point and when it detects more density of traffic at any side it and

it transmits signal to the receiver. The receiver receives this signal to the microcontroller.

30

8051MICRO

CONTROLLER

LCD

IR RECIEVER

IR TRANSMITTER

REGULATEDPOWERSUPPLY

Page 43: Density based traffic control system

Thus accordingly the LCD displays the time depending on the density of traffic. Here the

regulated power supply is used to drive the microcontroller. Hence with the help of IR

transmitter we can easily control traffic.

4.2 Circuit description:

In this project we required operating voltage for Microcontroller 89C51 is 5V. Hence the 5V

D.C. power supply is needed for the IC’s. This regulated 5V is generated by stepping down

the voltage from 230V to 18V now the step downed a.c voltage is being rectified by the

Bridge Rectifier using 1N4007 diodes. The rectified a.c voltage is now filtered using a ‘C’

filter. Now the rectified, filtered D.C. voltage is fed to the Voltage Regulator. This voltage

regulator provides/allows us to have a Regulated constant Voltage which is of +5V. The

rectified; filtered and regulated voltage is again filtered for ripples using an electrolytic

capacitor 100μF. Now the output from this section is fed to 40th pin of 89C51 microcontroller

to supply operating voltage. The microcontroller 89C51 with Pull up resistors at Port0 and

crystal oscillator of 11.0592 MHz crystal in conjunction with couple of 30-33pf capacitors is

placed at 18th & 19th pins of 89s52 to make it work (execute) properly.

One of the main problems in our city’s is traffic, this project proposed new solution to

traffic control. The main design accept of this project is to control the traffic automatically

and adding human inelegancy to that automatic controller. "Four-way" intersection is the

most common configuration for roads that cross each other, and the most basic type. If

signals do not control a 4-way intersection, signs or other features are typically used to

control movements and make clear priorities.

For IR communication we are using an IR transmitter and IR receiver. Here IR LED

will acts as a transmitter. As we know microcontroller having inbuilt I/O ports and we are

interfacing IR receivers to those I/O ports. For controlling of traffic we are using red, green

and yellow color LED’s. These LED’s are connected to different I/O ports of

microcontroller. When there is a more traffic microcontroller gives signal to green LED and

it will glow. So by using this project we can control the traffic automatically like a human

being.

31

Page 44: Density based traffic control system

4.3 SOFTWARE

Software used is:

*Keil software for C programming

*Express PCB for lay out design

*Express SCH for schematic design

4.3.1 KEIL µVision:

What's New in µVision3?

µVision3 adds many new features to the Editor like Text Templates, Quick Function

Navigation, and Syntax Coloring with brace high lighting Configuration Wizard for dialog

based startup and debugger setup. µVision3 is fully compatible to µVision2 and can be used

in parallel with µVision2.

What is µVision3?

µVision3 is an IDE (Integrated Development Environment) that helps you write, compile,

and debug embedded programs. It encapsulates the following components:

A project manager.

A make facility.

Tool configuration.

Editor.

A powerful debugger.

Express PCB: Express PCB is a Circuit Design Software and PCB manufacturing service.

One can learn almost everything you need to know about Express PCB from the help topics

included with the programs given.

Details: Express PCB, Version 5.6.0

Express SCH

The Express SCH schematic design program is very easy to use. This

software enables the user to draw the Schematics with drag and drop options. A Quick Start

Guide is provided by which the user can learn how to use it.

Details: Express SCH, Version 5.6.0

32

Page 45: Density based traffic control system

4.3.2 EMBEDDED C:

The programming Language used here in this project is an Embedded

C Language. This Embedded C Language is different from the generic C language in few

things like

a) Data types

b) Access over the architecture addresses.

The Embedded C Programming Language forms the user friendly language with access over

Port addresses, SFR Register addresses etc.

Data Types Size in Bits Data Range/Usage

unsigned char 8-bit 0-255

signed char 8-bit -128 to +127

unsigned int 16-bit 0 to 65535

signed int 16-bit -32,768 to +32,767

sbit 1-bit SFR bit addressable only

Bit 1-bit RAM bit addressable only

sfr 8-bit RAM addresses 80-FFH

only

TABLE4.3.A: EMBEDDED “C” DATA TYPES

33

Page 46: Density based traffic control system

4.4 CONCLUSION:

The project “density based traffic control system” has been successfully designed and

tested. Integrating features of all the hardware components used have developed it. Presence

of every module has been reasoned out and placed carefully thus contributing to the best

working of the unit. Secondly, using highly advanced IC’s and with the help of growing

technology the project has been successfully implemented.

34

Page 47: Density based traffic control system

REFERENCES:

The 8051 Micro controller and Embedded Systems -Muhammad Ali Mazidi Janice Gillispie Mazidi

The 8051 Micro controller Architecture, Programming & Applications

-Kenneth J.Ayala

Fundamentals Of Micro processors and Micro computers

-B.Ram

Micro processor Architecture, Programming & Applications

-Ramesh S.Gaonkar

Electronic Components

-D.V.Prasad

Wireless Communications - Theodore S. Rappaport

Mobile Tele Communications - William C.Y. LeeREFERENCE ON WEB:

www.national.comwww.nxp.comwww.8052.com www.microsoftsearch.comwww.geocities.com

Page 48: Density based traffic control system

35