Vous êtes sur la page 1sur 57

TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

CHAPTER -1

INTRODUCTION

1.1 Introduction:

In today’s high speed life, traffic congestion becomes a serious issue in our day to day
activities. It brings down the productivity of individual and thereby the society as lots of work
hour is wasted in the signals. High volume of vehicles, the inadequate infrastructure and the
irrational distribution of the signalling system are main reasons for this chaotic congestions. It
indirectly also adds to the increase in pollution level as engines remain on in most cases, a huge
volume of natural resources in forms of petrol and diesel is consumed without any fruitful
outcome. Therefore, in order to get rid of these problems or at least reduce them to significant
level, newer schemes need to be implemented by bringing in sensor based automation technique
in this field of traffic signalling system.

1.2 Embedded Systems

An embedded system is a special-purpose computer system designed to perform one or a


few dedicated functions, often with real-time computing constraints. It is usually embedded as
part of a complete device including hardware and mechanical parts. In contrast, a general-
purpose computer, such as a personal computer, can do many different tasks depending on
programming. Embedded systems control many of the common devices in use today.

Since the embedded system is dedicated to specific tasks, design engineers can optimize
it, reducing the size and cost of the product, or increasing the reliability and performance. Some
embedded systems are mass-produced, benefiting from economics of scale. Physically,
embedded systems range from portable devices such as digital watches and mp4 players, to large
stationary installations like traffic lights, factory controllers, or the systems controlling nuclear
power stations. Complexity varies from low, with a single microcontroller chip, to very high
with multiple units, peripherals and networks mounted inside a large chassis or enclosure.

Department of ECE PRIW- KHAMMAM 1


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

In general, "embedded system" is not an exactly defined term, as many systems have
some element of programmability. For example, handheld computers share some elements with
embedded systems — such as the operating systems and microprocessors which power them —
but are not truly embedded systems, because they allow different applications to be loaded and
peripherals to be connected.

1.2.1 Characteristics

1. Embedded systems are designed to do some specific task, rather than be a general-
purpose computer for multiple tasks. Some also have real-time performance constraints
that must be met, for reasons such as safety and usability; others may have low or no
performance requirements, allowing the system hardware to be simplified to reduce costs.
2. Embedded systems are not always standalone devices. Many embedded systems consist
of small, computerized parts within a larger device that serves a more general purpose.
For example, the features an embedded system for tuning the strings, but the overall
purpose of the Robot Guitar is, of course, to play music. Similarly, an embedded system
in automobiles provides a specific function as a subsystem of the car itself.
3. The program instructions written for embedded systems are referred to as firmware, and
are stored in read-only memory or flash memory chips. They run with limited computer
hardware resources: little memory, small or non-existent keyboard and/or screen.

Figure 1.2 A typical embedded system block diagram

Department of ECE PRIW- KHAMMAM 2


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

1.2.2 Communication:
Communication refers to the sending, receiving and processing of information by electric
means. As such, it started with wire telegraphy in the early 80’s, developing with telephony and
radio some decades later. Radio communication became the most widely used and refined
through the invention of and use of transistor, integrated circuit, and other semi-conductor
devices. Most recently, the use of satellites and fibre optics has made communication even more
wide spread, with an increasing emphasis on computer and other data communications.

A modern communications system is first concerned with the sorting, processing and
storing of information before its transmission. The actual transmission then follows, with further
processing and the filtering of noise. Finally we have reception, which may include processing
steps such as decoding, storage and interpretation. In this context, forms of communications
include radio, telephony and telegraphy, broadcast, point to point and mobile communications
(commercial and military), computer communications, radar, radio telemetry and radio aids to
navigation. It is also important to consider the human factors influencing a particular system,
since they can always affect its design, planning and use.

Wireless communication has become an important feature for commercial products and a
popular research topic within the last ten years. There are now more mobile phone subscriptions
than wired-line subscriptions. Lately, one area of commercial interest has been low-cost, low-
power, and short-distance wireless communication used for personal wireless networks."
Technology advancements are providing smaller and more cost effective devices for integrating
computational processing, wireless communication, and a host of other functionalities. These
embedded communications devices will be integrated into applications ranging from homeland
security to industry automation and monitoring. They will also enable custom tailored
engineering solutions, creating a revolutionary way of disseminating and processing information.
With new technologies and devices come new business activities, and the need for employees in
these technological areas. Engineers who have knowledge of embedded systems and wireless
communications will be in high demand. Unfortunately, there are few adorable environments
available for development and classroom use, so students often do not learn about these
technologies during hands-on lab exercises. The communication mediums were twisted pair,
optical fibre, infrared, and generally wireless radio.
Department of ECE PRIW- KHAMMAM 3
TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

1.3 8051 Microcontroller:


A microcontroller is a general purpose device, but that is meant to read data, perform
limited calculations on that data and control its environment based on those calculations. The
prime use of a microcontroller is to control the operation of a machine using a fixed program that
is stored in ROM and that does not change over the lifetime of the system.

The microcontroller design uses a much more limited set of single and double byte
instructions that are used to move data and code from internal memory to the ALU. The
microcontroller is concerned with getting data from and to its own pins; the architecture and
instruction set are optimized to handle data in bit and byte size.

The AT89C51 is a low-power, high-performance CMOS 8-bit microcontroller with 4k


bytes of Flash Programmable and erasable read only memory (EROM). The device is
manufactured using Atmel’s high-density non-volatile memory technology and is functionally
compatible with the industry-standard 80C51 microcontroller instruction set and pin out. By
combining versatile 8-bit CPU with Flash on a monolithic chip, the Atmel’s AT89c51 is a
powerful microcomputer, which provides a high flexible and cost- effective solution to many
embedded control applications.

Intel Corporation is first company who presented 8051 microcontrollers in market. It is 8-


bit microcontroller. It has on chip 128 bytes of RAM, 4K bytes ROM, two timers, one serial port
and four general purpose input/output ports. Each port has 8-bit register. It is also knowing as
single on chip. It has 8-bit processing unit. Its mean it can process 8 bit of data at a time. Large
data must be divided into 8-bit information for processing. It can have maximum of 64k bytes
ROM. It has gain many popularities after Intel allows other manufacturers to make it. After that
its many versions with different speed, on chip RAM and ROM sizes were introduced in market
by many manufacturers. But all these versions have same instruction set and program written for
one will run on any other version without any change. 8052, 8031 are another version of its
family

Department of ECE PRIW- KHAMMAM 4


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

1.4 8051 MICROCONTROLLER FEATURES:

FEATURES QUANTITY
ROM 4K bytes
RAM 128 bytes
Input/output pins 32
Timers 2
Serial Port 1
Interrupts 6

Table:1.4 Microcontroller Features

1.4.1 8051 MICROCONTROLLER ARCHITECTURE:


In this section we will discuss its internal architecture and main registers. Registers are
mainly used while programming microcontrollers in assembly language. But for c programming,
we still need to know about some registers. Registers are used to perform MOV and ADD
instructions.

1.5 REGISTERS:

As you know in microprocessors registers are used to store temporary instructions and
data. Instructions are used to processed addresses to fetch data. 8051 microcontrollers have 8 bit
registers. 8 bit registers have 8-bit start from D0-D7. D0 is least significant bit and D7 is least
significant bit. To process data larger than 8 bit, it should be broken into 8 bit pieces. It has many
registers but general purpose registers are mostly accessible to programmers.

There are two types of registers

1) General purpose registers

2) Special purpose registers.

Department of ECE PRIW- KHAMMAM 5


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

List of mostly used general purpose registers is given below:

1. An accumulator (It is used to perform arithmetic and logic instructions)


2. B, R0, R1, R2, R3, R4, R5, R6, R7 registers (They are used to store instruction
address and data)
3. DPTR (Data pointers is used to access and process data in different addressing
modes) It consists of high byte (DPH) and a low byte (DPL). It is used to hold 16-bit
address. It is used as a base register in indirect jumps, external data transfer and
lookup table instructions.
4. PC (Program counter is 16-bit register. It is used to store the address of next
instruction to be executed).
All these registers are of 8-bits other than data pointer and program counter registers.

Department of ECE PRIW- KHAMMAM 6


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

Figure 1.4.1 Block diagram of 8051

1.6 8051 DATA TYPE:


8051 microcontroller has only one data type of 8 bit. The size of each register is also 8
bit. If data is larger than 8 bit, it is programmer responsibility to divide data into 8 bit pieces
before processing. DB directive is most widely used data directive in assembly language for
assemblers.

Department of ECE PRIW- KHAMMAM 7


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

1.7 PROGRAM STATUS WORD REGISTER:

8051 microcontroller has program status register also know as flag register. Flag register
is used to show status of arithmetic logic instructions like carry bit, zero carry bit etc. PSW is an
8 bit register. Only 6 bits are used. PSW register is also called flag register. Flag register has 8
flags. Four flags are called conditional flags which execute instruction only if condition is
fulfilled. These conditional flags are OV (overflow), P (parity), AC (auxiliary carry) and CY
(carry). Bit number 3 and 4 of PSW register is used to change the bank registers. Bit number 1
and 5 of program status register are unused and it can be used by programmer for any specific
purpose.

1.8 REGISTER BANKS:

32 Bytes of RAM are dedicated for register banks and stacks. These 32 bytes are broken
in four banks. Each back has 8 registers from R0-R7. R0 is RAM location zero and so R7 is
RAM location seven. The second bank register is started from location 8 and end 05H. The third
bank starts from 10H and finished on location 17H. The last bank is located between the 18H-
1FH.

1.9 8051 MICROCONTROLLER STACK:

Stack is a part of RAM which is used by the processor to store data or an address
temporarily. Stack is very important part of microprocessor because there are very limited
numbers of registers to store data and addresses. Stack pointer is 8051 is 8 bit wide. It means it
can hold data from 00 to FFH. Stack pointer is used by CPU to access the stack. 8051 have 8 bit
stack pointer. It means it can access values from 00H-FFH. When it is turned on, the stack
pointer contains value of 07.

1.10 MEMORY IN 8051:


It has complex memory organization. Because 8051 microcontroller have separate
address bus for program memory, Data memory and external RAM. It is based on Harvard
architecture developed by Harvard in 1944. It may consist of internal or external program
memory. It can support up to 64k bytes of external memory. I have 128 bytes of internal data
memory.

Department of ECE PRIW- KHAMMAM 8


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

1.11 ADDRESSING MODES:


Microprocessor fetches data in different ways. The data usually stored in register, memory
and can be used from immediate value. These different ways of accessing data is called
addressing modes. Different microcontrollers have different addressing modes. It depends on
design of manufacturers. 8051 has 5 addressing modes.

 Indexed
 Register indirect
 Direct
 Register
 Immediate

1.12 8051 MICROCONTROLLER I/O PORT PROGRAMMING:

It has four input/output ports to interact with external devices. As shown in figure below,
it has 40 pins but 32 pins are assigned to I/O 4 port. Port P0, P1, P2 and P3. Each port has 8 bits.
Each bit can be used either as an input or output pin. Resetting these pins make them input ports.
In other words they can be used as an input. But all ports can be configured either as an input or
output.

To configure any port as an input port writes 0 to it and to configure any port as an output
write 1 to it. But to use port 0 as an input or output each pin must be externally pulled up with
10K ohm resistor. Because port 0 is an open drain. Rest of the ports can be configured either as
an input or output by writing either 0 or 1 to all the bits. One no needs to use pull up resistor.
With P1, P2 and P3 ports. Sometimes we may need to access only one or two bits of port. 8051
microcontroller provides facility to access individual bits. For example we want to access bit 0 of
port 1 we can use P1.0 to access bit zero of port 1.

Department of ECE PRIW- KHAMMAM 9


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

CHAPTER – 2

BLOCK DIAGRAM OF TRAFFIC CONTROL SYSTEM

Figure 2.1: block diagram of 8051


 Also we have a junction where three lights (green, amber and red ) are arranged on all
four sides. We have three pairs of sensors across the roads marking as low, medium and
high density zones respectively.
 There will be a infrared transmitter and infrared receiver opposite to each other. We will
place sensors at some distance apart from another pair.
 When vehicles are filled and cross the first pair of sensors, then there will be
an obstacle between transmitter and receiver and this leads to a digital signal
(low or high) and the microcontroller assumes that there is low density
traffic.
 When the vehicle crosses second sensor then it assumes medium density and
for third sensor pair high density traffic respectively.

Department of ECE PRIW- KHAMMAM 10


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

 Depending on the above process a digital data is sent to microcontroller


whether its low or high and the microcontroller will allot the time for the
traffic to pass on.
 For high density traffic there will be more allotment of time and for low
density low time respectively. Program written to the microcontroller will make it to do
the operation.
 So the microcontroller will send its timing signal output by comparing with
the adjacent roads traffic.
 When the vehicle crosses second sensor then it assumes medium density and
for third sensor pair high density traffic respectively.
 Depending on the above process a digital data is sent to microcontroller
whether its low or high and the microcontroller will allot the time for the
traffic to pass on.
 For high density traffic there will be more allotment of time and for low
density low time respectively. Program written to the microcontroller will make it to do
the operation.
 So the microcontroller will send its timing signal output by comparing with
the adjacent roads traffic.
Components Used:

1. Power Supply
2. 8051 Microcontroller
3. LCD
4. IR Sensors

Department of ECE PRIW- KHAMMAM 11


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

2.1 POWER SUPPLY:


In this project we have power supplies with +5V & -5V option normally +5V is enough
for total circuit. Another (-5V) supply is used in case of OP amp circuit .Transformer primary
side has 230/50HZ AC voltage whereas at the secondary winding the voltage is step downed to
12/50hz and this voltage is rectified using two full wave rectifiers . The rectified output is given
to a filter circuit to filter the unwanted ac in the signal After that the output is again applied to a
regulator LM7805(to provide +5v) regulator. Whereas LM7905 is for providing –5V regulation.
(+12V circuit is used for stepper motors, Fan and Relay by using LM7812 regulator same
process like above supplies.)

2.2 TAPPED FULL WAVE RECTIFIER:

The circuit employs two diodes D1 and D2 as shown in the figure below. A center tapped
secondary winding AB is used with two diodes connected so that each uses one- half cycle of the input
ac voltage. In other words, D1 utilizes the ac voltage appearing across the upper half (OA) of secondary
winding for rectification while D2 uses the lower half winding OB.

D1

1 5
RL
6
AC Supply
4 8

D2

Figure 2.2 Centertap


Centertap full wave
full wave rectifier
rectifier

Department of ECE PRIW- KHAMMAM 12


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

2.2.1 OPERATION:
During the positive half cycle of secondary voltage, the end A of the secondary
winding becomes positive and end B negative. This makes the diode D1 forward biased and D2
reverse biased. Therefore D1 conducts while D2 does not. The conventional current flow is
through diode D1, load resistor RL and upper half of secondary winding as shown by the dotted
arrows. During the negative half cycle, end A of the secondary winding becomes negative and
end B positive. Therefore D2 conducts while D1 does not. The conventional current flow is
through D2, load RL and lower half winding as shown by solid arrows in the figure above .It is
seen that current in the load RL is in the same direction for both half cycles of input ac voltage.
Therefore dc is obtained across the load RL. Also the polarities of the output across the load
should be noted.

2.2.2 PEAK INVERSE VOLTAGE:

Suppose Vm is the maximum voltage across the half secondary winding at the instant
secondary voltage reaches its maximum value in the positive direction. At this instant D1 is
conducting while D2 is not conducting. Therefore whole of the secondary voltage appears across
the non-conducting diode. Consequently the peak inverse voltage is twice the maximum voltage
across the half secondary winding.

Block diagram:

Figure 2.2.2 : Block diagram of power supply

Department of ECE PRIW- KHAMMAM 13


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

Circuit Features: Brief description of operation: Gives out well regulated +5V output,
output current capability of 100 mA .

Circuit protection: Built-in overheating protection shuts down output when regulator IC gets
too hot .

Circuit complexity: Very simple and easy to build.

Circuit performance: Very stable +5V output voltage, reliable operation Availability.
Components: Easy to get, uses only very common basic components.

Design testing: Based on datasheet example circuit, I have used this circuit successfully as
part of many electronics projects .

Applications: Part of electronics devices, small laboratory power supply.

Power supply voltage: Unregulated DC 8-18V power supply.

Power supply current: Needed output current + 5 mA .

Component costs: Few dollars for the electronics components the input transformer cost.

Figure 2.2.2 Power Supply Unit

Department of ECE PRIW- KHAMMAM 14


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

2.3 8051 Microcontroller:

Figure 2.3 Pin Configuration

Department of ECE PRIW- KHAMMAM 15


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

2.3.1 PIN DESCRIPTION:


VC : Supply voltage
GND : Ground

Port 0
Port 0 is an 8-bit open drain bi-directional 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
access to external program and data memory. In this mode, P 0 has internal pull-ups. Port 0 also
receives the code bytes during Flash programming and outputs the code bytes during program
verification. External pull-ups are required during program verification.

Port 1

Port 1 is an 8-bit bi-directional I/O port with internal pull-ups. The port 1output buffers
can sink/source four TTL inputs. When 1s are written to port 1 pins, they are pulled high by the
internal pull-ups can be used as inputs. As inputs, Port 1 pins that are externally being pulled low
will source current (1) because of the internal pull-ups.

Port 2

Port 2 is an 8-bit bi-directional I/O port with internal pull-ups. The port 2 output buffers
can sink/source four TTL inputs. When 1s are written to port 2 pins, they are pulled high by the
internal pull-ups can be used as inputs. As inputs, Port 2 pins that are externally being pulled low
will source current because of the internal pull-ups.

Port 2 emits the high-order address byte during fetches from external program memory
and during access to DPTR. In this application Port 2 uses strong internal pull-ups when emitting
1s. During accesses to external data memory that use 8-bit data address (MOVX@R1), Port 2
emits the contents of the P2 Special Function Register. Port 2 also receives the high-order
address bits and some control signals during Flash programming and verification.

Department of ECE PRIW- KHAMMAM 16


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

Port 3

Port 3 is an 8-bit bi-directional I/O port with internal pull-ups. The port 3 output buffers
can sink/source four TTL inputs. When 1s are written to port 3 pins, they are pulled high by the
internal pull-ups can be used as inputs. As inputs, Port 3 pins that are externally being pulled low
will source current because of the internal pull-ups. Port 3 also receives some control signals for
Flash Programming and verification.

Port pin Alternate Functions

P3.0 RXD(serial input port)


P3.1 TXD(serial input port)

P3.2 INT0(external interrupt 0)

P3.3 INT1(external interrupt 1)

P3.4 T0(timer 0 external input)

P3.5 T1(timer 1 external input)

P3.6 WR(external data memory write strobe)

P3.7 RD(external data memory read strobe)

Table 2.3.1 Port 3 Description

RST
Rest input A on this pin for two machine cycles while the oscillator is running resets the device.

ALE/PROG:
Address Latch Enable is an output pulse for latching the low byte of the address during
access 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/16 the oscillator
frequency and may be used for external timing or clocking purpose.

Department of ECE PRIW- KHAMMAM 17


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

PSEN

Program Store Enable is the read strobe to external program memory when the AT89c51
is executing code from external program memory PSEN is activated twice each machine cycle,
except that two PSEN activations are skipped during each access to external data memory.

EA /VPP

External Access Enable (EA) must be strapped to GND in order to enable the device to
fetch code from external program memory locations starting at 0000h up to FFFFH. Note,
however, that if lock bit 1 is programmed EA will be internally latched on reset. EA should be
strapped to Vcc for internal program executions. This pin also receives the 12-volt programming
enable voltage (Vpp) during Flash programming when 12-volt programming is selected.

XTAL1

Input to the inverting oscillator amplifier and input to the internal clock operating circuit.

XTAL 2

Output from the inverting oscillator amplifier.

OPERATING DESCRIPTION

The detail description of the AT89C51 included in this description is:

• Memory Map and Registers

• Timer/Counters

• Interrupt System

Department of ECE PRIW- KHAMMAM 18


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

2.4 MEMORY MAP AND REGISTERS

Memory

The AT89C51 has separate address spaces for program and data memory. The program
and data memory can be up to 64K bytes long. The lower 4K program memory can reside on-
chip. The AT89C51 has 128 bytes of on-chip RAM.

The lower 128 bytes can be accessed either by direct addressing or by indirect
addressing. The lower 128 bytes of RAM can be divided into 3 segments as listed below

1. Register Banks 0-3: locations 00H through 1FH (32 bytes). The device after reset defaults to
register bank 0. To use the other register banks, the user must select them in software. Each
register bank contains eight 1-byte registers R0-R7. Reset initializes the stack point to location
07H, and is incremented once to start from 08H, which is the first register of the second register
bank.

2. Bit Addressable Area: 16 bytes have been assigned for this segment 20H-2FH. Each one of
the 128 bits of this segment can be directly addressed (0-7FH). Each of the 16 bytes in this
segment can also be addressed as a byte.

3. Scratch Pad Area: 30H-7FH are available to the user as data RAM. However, if the data
pointer has been initialized to this area, enough bytes should be left aside to prevent SP data
destruction.

Department of ECE PRIW- KHAMMAM 19


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

Figure 2.4 Memory Map and Registers

2.4.1 SPECIAL FUNCTION REGISTERS

The Special Function Registers (SFR's) are located in upper 128 Bytes direct addressing
area. The SFR Memory Map in shows that. Not all of the addresses are occupied. Unoccupied
addresses are not implemented on the chip. Read accesses to these addresses in general return
random data, and write accesses have no effect. User software should not write 1s to these
unimplemented locations, since they may be used in future microcontrollers to invoke new
features. In that case, the reset or inactive values of the new bits will always be 0, and their active
values will be 1.The functions of the SFR’s are outlined in the following sections.

Accumulator (ACC)

ACC is the Accumulator register. The mnemonics for Accumulator-specific instructions,


however, refer to the Accumulator simply as A.

Department of ECE PRIW- KHAMMAM 20


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

B Register (B)

The B register is used during multiply and divide operations. For other instructions it can
be treated as another scratch pad register.

Program Status Word (PSW)


The PSW register contains program status information.

Stack Pointer (SP)


The Stack Pointer Register is eight bits wide. It is incremented before data is stored
during PUSH and CALL executions. While the stack may reside anywhere in on chip RAM, the
Stack Pointer is initialized to 07H after a reset. This causes the stack to begin at location 08H.

Data Pointer (DPTR)

The Data Pointer consists of a high byte (DPH) and a low byte (DPL). Its function is to
hold a 16-bit address. It may be manipulated as a 16-bit register or as two independent 8-bit
registers.

Serial Data Buffer (SBUF)

The Serial Data Buffer is actually two separate registers, a transmit buffer and a receive
buffer register. When data is moved to SBUF, it goes to the transmit buffer, where it is held for
serial transmission. (Moving a byte to SBUF initiates the transmission.) When data is moved
from SBUF, it comes from the receive buffer.

Timer Registers

Register pairs (TH0, TL0) and (TH1, TL1) are the 16-bit Counter registers for
Timer/Counters 0 and 1, respectively.

Control Registers

Special Function Registers IP, IE, TMOD, TCON, SCON, and PCON contain control and
status bits for the interrupt system, the Timer/Counters, and the serial port.

Department of ECE PRIW- KHAMMAM 21


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

2.4.2 TIMER/COUNTERS

The IS89C51 has two 16-bit Timer/Counter registers: Timer 0 and Timer 1. All two can
be configured to operate either as Timers or event counters. As a Timer, the register is
incremented every machine cycle. Thus, the register counts machine cycles. Since a machine
cycle consists of 12 oscillator periods, the count rate is 1/12 of the oscillator frequency.

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


corresponding external input pin, T0 and T1. 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 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. There are no restrictions on the duty cycle of the external input signal, but it should
be held for at least one full machine cycle to ensure that a given level is sampled at least once
before it changes. In addition to the Timer or Counter functions, Timer 0 and Timer 1 have four
operating modes: 13-bit timer, 16-bit timer, 8-bit auto-reload, split timer.

2.4.3 TIMERS:

OSCILLATOR
FREQUENCY 12D

TLX THX TFX


TR
Figure 2.4.3 Block diagram of Timer

Department of ECE PRIW- KHAMMAM 22


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

SFR’S USED IN TIMERS

The special function registers used in timers are,

 TMOD Register
 TCON Register
 Timer(T0) & timer(T1) Registers

(i) TMOD Register:

TMOD is dedicated solely to the two timers (T0 & T1).

 The timer mode SFR is used to configure the mode of operation of each of the two
timers. Using this SFR your program may configure each timer to be a 16-bit timer, or 13
bit timer, 8-bit auto reload timer, or two separate timers. Additionally you may configure
the timers to only count when an external pin is activated or to count “events” that are
indicated on an external pin.
 It can consider as two duplicate 4-bit registers, each of which controls the action of one
of the timers.
(ii) TCON Register:

 The timer control SFR is used to configure and modify the way in which the 8051’s two
timers operate. This SFR controls whether each of the two timers is running or stopped
and contains a flag to indicate that each timer has overflowed. Additionally, some non-
timer related bits are located in TCON SFR.
 These bits are used to configure the way in which the external interrupt flags are
activated, which are set when an external interrupt occurs.

Table 2.4.3 TCON Register

Department of ECE PRIW- KHAMMAM 23


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

(iii) TIMER 0 (T0):

 TO (Timer 0 low/high, address 8A/8C h)


These two SFR’s taken together represent timer 0. Their exact behaviour depends
on how the timer is configured in the TMOD SFR; however, these timers always count
up. What is configurable is how and when they increment in value.

TH0 TL0

Table 2.4.3 Timer 0

(iv) TIMER 1 (T1):

 T1 (Timer 1 Low/High, address 8B/ 8D h)


These two SFR’s, taken together, represent timer 1. Their exact behaviour depends on how the
timer is configured in the TMOD SFR; however, these timers always count up. What is
Configurable is how and when they increment in value.

TH1 TL1

Table 2.4.3 Timer 1

The Timer or Counter function is selected by control bits C/T in the Special Function
Register TMOD. These two Timer/Counters have four operating modes, which are selected by
bit pairs (M1, M0) in TMOD. Modes 0, 1, and 2 are the same for both Timer/Counters, but Mode
3 is different.

The four modes are described in the following sections.

Mode 0:

Both Timers in Mode 0 are 8-bit Counters with a divide-by-32 pre scalar. Figure 8 shows
the Mode 0 operation as it applies to Timer 1. In this mode, the Timer register is configured as a

Department of ECE PRIW- KHAMMAM 24


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

13-bit register. As the count rolls over from all 1s to all 0s, it sets the Timer interrupt flag TF1.
The counted input is enabled to the Timer when TR1 = 1 and either GATE = 0 or INT1 = 1.
Setting GATE = 1 allows the Timer to be controlled by external input INT1, to facilitate pulse
width measurements. TR1 is a control bit in the Special Function Register TCON. Gate is in
TMOD.

The 13-bit register consists of all eight bits of TH1 and the lower five bits of TL1. The
upper three bits of TL1 are indeterminate and should be ignored. Setting the run flag (TR1) does
not clear the registers. Mode 0 operation is the same for Timer 0 as for Timer 1, except that TR0,
TF0 and INT0 replace the corresponding Timer 1 signals. There are two different GATE bits,
one for Timer 1 (TMOD.7) and one for Timer 0 (TMOD.3).

Mode 1

Mode 1 is the same as Mode 0, except that the Timer register is run with all 16 bits. The
clock is applied to the combined high and low timer registers (TL1/TH1). As clock pulses are
received, the timer counts up: 0000H, 0001H, 0002H, etc. An overflow occurs on the FFFFH-to-
0000H overflow flag. The timer continues to count. The overflow flag is the TF1 bit in TCON
that is read or written by software

Mode 2
Mode 2 configures the Timer register as an 8-bit Counter (TL1) with automatic reload, as
shown in Figure 10. Overflow from TL1 not only sets TF1, but also reloads TL1 with the
contents of TH1, which is preset by software. The reload leaves the TH1 unchanged. Mode 2
operation is the same for Timer/Counter 0.

Mode 3
Timer 1 in Mode 3 simply holds its count. The effect is the same as setting TR1 = 0.
Timer 0 in Mode 3 establishes TL0and TH0 as two separate counters. The logic for Mode 3 on
Timer 0 is shown in Figure 11. TL0 uses the Timer 0 control bits: C/T, GATE, TR0, INT0, and

Department of ECE PRIW- KHAMMAM 25


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

TF0. TH0 is locked into a timer function (counting machine cycles) and over the use of TR1 and
TF1 from Timer 1. Thus, TH0 now controls the Timer 1 interrupt.

Mode 3 is for applications requiring an extra 8-bit timer or counter. With Timer 0 in
Mode 3, the AT89C51 can appear to have three Timer/Counters. When Timer 0 is in Mode 3,
Timer 1 can be turned on and off by switching it out of and into its own Mode 3. In this case,
Timer 1 can still be used by the serial port as a baud rate generator or in any application not
requiring an interrupt.

2.4.4 INTERRUPT SYSTEM

An interrupt is an external or internal event that suspends the operation of micro


controller to inform it that a device needs its service. In interrupt method, whenever any device
needs its service, the device notifies the micro controller by sending it an interrupt signal. Upon
receiving an interrupt signal, the micro controller interrupts whatever it is doing and serves the
device. The program associated with interrupt is called as interrupt service subroutine
(ISR).Main advantage with interrupts is that the micro controller can serve many devices.

Baud Rate

The baud rate in Mode 0 is fixed as shown in the following equation. Mode 0 Baud Rate
= Oscillator Frequency /12 the baud rate in Mode 2 depends on the value of the SMOD bit in
Special Function Register PCON. If SMOD = 0 the baud rate is 1/64 of the oscillator frequency.
If SMOD = 1, the baud rate is 1/32 of the oscillator frequency.

Mode 2 Baud Rate = 2SMODx (Oscillator Frequency)/64.

In the IS89C51, the Timer 1 overflow rate determines the baud rates in Modes 1 and 3.

2.4.5 NUMBER OF INTERRUPTS IN 89C51:

There are basically five interrupts available to the user. Reset is also considered as an
interrupt. There are two interrupts for timer, two interrupts for external hardware interrupt and
one interrupt for serial communication.

Department of ECE PRIW- KHAMMAM 26


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

Memory location Interrupt name

0000H RESET
0003H External interrupt 0
000BH Timer interrupt 0
0013H External interrupt 1
001BH Timer interrupt 1
0023H Serial COM interrupt

Table 2.4.5 Memory Interrupts

Lower the vector, higher the priority. The External Interrupts INT0 and INT1 can each be
either level-activated or transition-activated, depending on bits IT0 and IT1 in Register TCON.
The flags that actually generate these interrupts are the IE0 and IE1 bits in TCON. When the
service routine is vectored, hardware clears the flag that generated an external interrupt only if
the interrupt was transition-activated. If the interrupt was level-activated, then the external
requesting source (rather than the on-chip hardware) controls the request flag.

The Timer 0 and Timer 1 Interrupts are generated by TF0and TF1, which are set by a
rollover in their respective Timer/Counter registers (except for Timer 0 in Mode 3).When a timer
interrupt is generated, the on-chip hardware clears the flag that is generated.

The Serial Port Interrupt is generated by the logical OR of RI and TI. The service routine
normally must determine whether RI or TI generated the interrupt, and the bit must be cleared in
software. All of the bits that generate interrupts can be set or cleared by software, with the same
result as though they had been set or cleared by hardware. That is, interrupts can be generated
and pending interrupts can be cancelled in software. Each of these interrupt sources can be
individually enabled or disabled by setting or clearing a bit in Special Function Register IE
(interrupt enable) at address 0A8H. There is a global enable/disable bit that is cleared to disable
all interrupts or to set the interrupts.

Department of ECE PRIW- KHAMMAM 27


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

2.4.6 IE (Interrupt enable register):

Steps in enabling an interrupt:

Bit D7 of the IE register must be set to high to allow the rest of register to take effect. If
EA=1, interrupts are enabled and will be responded to if their corresponding bits in IE are high.
If EA=0, no interrupt will be responded to even if the associated bit in the IE register is high.

Description of each bit in IE register:

D7 bit: Disables all interrupts. If EA =0, no interrupt is acknowledged, if EA=1 each interrupt
source is individually enabled or disabled by setting or clearing its enable bit.

D6 bit: Reserved.

D5 bit: Enables or disables timer 2 over flow interrupt (in 8052).

D4 bit: Enables or disables serial port interrupt.

D3 bit: Enables or disables timer 1 over flow interrupt.

D2 bit: Enables or disables external interrupt 1.

D1 bit: Enables or disables timer 0 over flow interrupt.

D0 bit: Enables or disables external interrupt 0.

Interrupt priority in 89C51:

There is one more SRF to assign priority to the interrupts which is named as interrupt
priority (IP). User has given the provision to assign priority to one interrupt. Writing one to that
particular bit in the IP register fulfils the task of assigning the priority.

Department of ECE PRIW- KHAMMAM 28


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

Description of each bit in IP register:

D7 bit: Reserved.

D6 bit: Reserved.

D5 bit: Timer 2 interrupt priority bit (in 8052).

D4 bit: Serial port interrupt priority bit.

D3 bit: Timer 1 interrupt priority bit.

D2 bit: External interrupt 1 priority bit.

D1 bit: Timer 0 interrupt priority bit.

D0 bit: External interrupt 0 priority bit.

2.4.7 Memory Organization:

The 8051 has two types of memory and these are Program Memory and Data Memory.
Program Memory (ROM) is used to permanently save the program being executed, while Data
Memory (RAM) is used for temporarily storing data and intermediate results created and used
during the operation of the microcontroller. Depending on the model in use (we are still talking
about the 8051 microcontroller family in general) at most a few Kb of ROM and 128 or 256
bytes of RAM is used. However…All 8051 microcontrollers have a 16-bit addressing bus and
are capable of addressing 64 kb memory. It is neither a mistake nor a big ambition of engineers
who were working on basic core development. It is a matter of smart memory organization
which makes these microcontrollers a real “programmers’ goody“.

Program Memory:

The first models of the 8051 microcontroller family did not have internal program
memory. It was added as an external separate chip. These models are recognizable by their label
beginning with 803 (for example 8031 or 8032). All later models have a few Kbyte ROM
embedded. Even though such an amount of memory is sufficient for writing most of the
programs, there are situations when it is necessary to use additional memory as well. A typical

Department of ECE PRIW- KHAMMAM 29


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

example is so called lookup tables. They are used in cases when equations describing some
processes are too complicated or when there is no time for solving them. In such cases all
necessary estimates and approximates are executed in advance and the final results are put in the
tables (similar to logarithmic tables).

Figure 2.4.7 Program Memory

How does the microcontroller handle external memory depends on the EA pin logic state:

EA=0 In this case, the microcontroller completely ignores internal program memory and
executes only the program stored in external memory.
EA=1 In this case, the microcontroller executes first the program from built-in ROM,
then the program stored in external memory.
In both cases, P0 and P2 are not available for use since being used for data and address
transmission. Besides, the ALE and PSEN pins are also used.

Department of ECE PRIW- KHAMMAM 30


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

Figure 2.4.7 Memory Organization

2.4.8 Data Memory

As already mentioned, Data Memory is used for temporarily storing data and
intermediate results created and used during the operation of the microcontroller. Besides, RAM
memory built in the 8051 family includes many registers such as hardware counters and timers,
input/output ports, serial data buffers etc. The previous models had 256 RAM locations, while
for the later models this number was incremented by additional 128 registers. However, the first
256 memory locations (addresses 0-FFh) are the heart of memory common to all the models
belonging to the 8051 family. Locations available to the user occupy memory space with
addresses 0-7Fh, i.e. first 128 registers. This part of RAM is divided in several blocks.

Department of ECE PRIW- KHAMMAM 31


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

The first block consists of 4 banks each including 8 registers denoted by R0-R7. Prior to
accessing any of these registers, it is necessary to select the bank containing it. The next memory
block (address 20h-2Fh) is bit- addressable, which means that each bit has its own address (0-
7Fh). Since there are 16 such registers, this block contains in total of 128 bits with separate
addresses (address of bit 0 of the 20h byte is 0, while address of bit 7 of the 2Fh byte is 7Fh).
The third group of registers occupy addresses 2Fh-7Fh, i.e. 80 locations, and does not have any
special functions or features.

2.4.9 Additional RAM:

In order to satisfy the programmers’ constant hunger for Data Memory, the
manufacturers decided to embed an additional memory block of 128 locations into the latest
versions of the 8051 microcontrollers. However, it’s not as simple as it seems to be… The
problem is that electronics performing addressing has 1 byte (8 bits) on disposal and is capable
of reaching only the first 256 locations, therefore. In order to keep already existing 8-bit
architecture and compatibility with other existing models a small trick was done.

What does it mean? It means that additional memory block shares the same addresses
with locations intended for the SFRs (80h- FFh). In order to differentiate between these two
physically separated memory spaces, different ways of addressing are used. The SFRs memory
locations are accessed by direct addressing, while additional RAM memory locations are
accessed by indirect addressing.

2.4.10 Pins Functions


There are pins along one side of the small printed board used for connection to the
microcontroller. There are total of 14 pins marked with numbers (16 in case the background light
is built in).

Department of ECE PRIW- KHAMMAM 32


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

Their function is described in the table below:

FUNCTIONS PIN NUMBER NAME LOGIC STATE DISCRIPTION


Ground 1 Vss - 0V
Power supply 2 Vdd - +5V
Contrast 3 Vee - 0 - Vdd

D0 – D7 are interpreted
Control of 0
4 RS as commands
operating 1 D0 – D7 are interpreted
as data

Write data (from


0
5 R/W controller to LCD)
1 Read data (from LCD to
controller)

0 Access to LCD disabled


6 E 1 Normal operating
Data/commands are
From 1 to 0 transferred to LCD
Data / commands 7 D0 0/1 Bit 0 LSB
8 D1 0/1 Bit 1
9 D2 0/1 Bit 2
10 D3 0/1 Bit 3
11 D4 0/1 Bit 4
12 D5 0/1 Bit 5
13 D6 0/1 Bit 6
14 D7 0/1 Bit 7 MSB

Table 2.4.10 Pins Functions

Department of ECE PRIW- KHAMMAM 33


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

2.5 LCD:

LCD stands for Liquid Crystal Display. LCD is finding wide spread use replacing LEDs
(seven segment LEDs or other multi segment LEDs) because of the following reasons:

1. The declining prices of LCDs.


2. The ability to display numbers, characters and graphics. This is in contrast to LEDs,
which are limited to numbers and a few characters.
3. Incorporation of a refreshing controller into the LCD, thereby relieving the CPU of the
task of refreshing the LCD. In contrast, the LED must be refreshed by the CPU to keep
displaying the data.
4. Ease of programming for characters and graphics.

These components are “specialized” for being used with the microcontrollers, which means
that they cannot be activated by standard IC circuits. They are used for writing different
messages on a miniature LCD.

FIGURE 2.5 LCD DISPLAY

A model described here is for its low price and great possibilities most frequently used in
practice. It is based on the HD44780 microcontroller (Hitachi) and can display messages in two
lines with 16 characters each . It displays all the alphabets, Greek letters, punctuation marks,
mathematical symbols etc. In addition, it is possible to display symbols that user makes up on its
own. Automatic shifting message on display (shift left and right), appearance of the pointer,
backlight etc. are considered as useful characteristics.

Department of ECE PRIW- KHAMMAM 34


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

2.5.1 LCD screen:

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

Figure 2.5.1 LCD screen

2.5.2 LCD Basic Commands

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

RS = 1 - Bits D0 - D7 are addresses of characters that should be displayed. Built in processor


addresses built in “map of characters” and displays corresponding symbols. Displaying position
is determined by DDRAM address. This address is either previously defined or the address of
previously transferred character is automatically incremented.

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

Department of ECE PRIW- KHAMMAM 35


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

2.5.3 List of commands which LCD recognizes are given in the table below:

Executio
Command RS RW D7 D6 D5 D4 D3 D2 D1 D0
n Time
Clear display 0 0 0 0 0 0 0 0 0 1 1.64mS
Cursor home 0 0 0 0 0 0 0 0 1 x 1.64mS
Entry mode set 0 0 0 0 0 0 0 1 I/D S 40uS
Display on/off control 0 0 0 0 0 0 1 D U B 40uS

Cursor/Display Shift 0 0 0 0 0 1 D/C R/L x x 40uS

Function set 0 0 0 0 1 DL N F x x 40uS


CGRA
M 40
Set CGRAM address 0 0 0 1
addr uS
ess
DDRA
M
Set DDRAM address 0 0 1 40uS
addres
s
DDRA
M
Read “BUSY” flag (BF) 0 1 BF -
addres
s
Write to CGRAM or
1 0 D7 D6 D5 D4 D3 D2 D1 D0 40uS
DDRAM
Read from CGRAM or
1 1 D7 D6 D5 D4 D3 D2 D1 D0 40uS
DDRAM

I/D 1 = Increment (by 1) R/L 1 = Shift right


0 = Decrement (by 1) 0 = Shift left
S 1 = Display shift on DL 1 = 8-bit interface
0 = Display shift off 0 = 4-bit interface

Department of ECE PRIW- KHAMMAM 36


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

D 1 = Display on N 1 = Display in two lines


0 = Display off 0 = Display in one line
U 1 = Cursor on F 1 = Character format 5x10 dots
0 = Cursor off 0 = Character format 5x7 dots
B 1 = Cursor blink on D/C 1 = Display shift

0 = Cursor blink off 0 = Cursor shift

Table 2.5.3 List of commands

2.5.4 LCD Connection

Depending on how many lines are used for connection to the microcontroller, there are 8-
bit and 4-bit LCD modes. The appropriate mode is determined at the beginning of the process in
a phase called “initialization”. In the first case, the data are transferred through outputs D0-D7 as
it has been already explained. In case of 4-bit LED mode, for the sake of saving valuable I/O
pins of the microcontroller, there are only 4 higher bits (D4-D7) used for communication, while
other may be left unconnected.

Consequently, each data is sent to LCD in two steps: four higher bits are sent first (that
normally would be sent through lines D4-D7), four lower bits are sent afterwards. With the help
of initialization, LCD will correctly connect and interpret each data received. Besides, with
regards to the fact that data are rarely read from LCD (data mainly are transferred from
microcontroller to LCD) one more I/O pin may be saved by simple connecting R/W pin to the
Ground. Such saving has its price. Even though message displaying will be normally performed,
it will not be possible to read from busy flag since it is not possible to read from display.

2.5.5 LCD Initialization

Once the power supply is turned on, LCD is automatically cleared. This process lasts for
approximately 15mS. After that, display is ready to operate. The mode of operating is set by
default.

Department of ECE PRIW- KHAMMAM 37


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

This means that:

1. Display is cleared

2. Mode

DL = 1 Communication through 8-bit interface

N = 0 Messages are displayed in one line

F = 0 Character font 5 x 8 dots

3. Display/Cursor on/off

D = 0 Display off

U = 0 Cursor off

B = 0 Cursor blink off

4. Character entry

ID = 1 Addresses on display are automatically incremented by 1

S = 0 Display shift off

Automatic reset is mainly performed without any problems. Mainly but not always! If for
any reason power supply voltage does not reach full value in the course of 10mS, display will
start perform completely unpredictably. If voltage supply unit can not meet this condition or if it
is needed to provide completely safe operating, the process of initialization by which a new reset
enabling display to operate normally must be applied.

Algorithm according to the initialization is being performed depends on whether


connection to the microcontroller is through 4- or 8-bit interface. All left over to be done after
that is to give basic commands and of course- to display messages.

Department of ECE PRIW- KHAMMAM 38


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

Figure 2.5.5: Procedure on 8-bit initialization.

2.6 CONTRAST CONTROL:

To have a clear view of the characters on the LCD, contrast should be adjusted. To adjust
the contrast, the voltage should be varied. For this, a preset is used which can behave like
variable

Figure 2.6 Contrast Control

voltage device. As the voltage of this preset is varied, the contrast of the LCD can be adjusted.

2.6.1 Potentiometer

Variable resistors used as potentiometers have all three terminals connected.

Department of ECE PRIW- KHAMMAM 39


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

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

Figure 2.6.1 Potentiometer

2.6.2 Presets

These are miniature versions of the standard variable resistor. They are designed to be
mounted directly onto the circuit board and adjusted only when the circuit is built. For example
to set the frequency of an alarm tone or the sensitivity of a light-sensitive circuit. A small
screwdriver or similar tool is required to adjust presets.

Presets are much cheaper than standard variable resistors so they are sometimes used in
projects where a standard variable resistor would normally be used.

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

Preset Symbol

Figure 2.6.3 Multiturnpresets

Department of ECE PRIW- KHAMMAM 40


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

2.7 LCD INTERFACING WITH THE MICROCONTROLLER:

Vcc

P2.0 4 (RS) 1
Gnd
P2.1 5 (R/W) 2

P2.2 6(EN) 3
PRESET

(CONTRAS
TCONTRO
L)
LCD

Vcc FOR
Gnd BACKLIGH
T PURPOSE
89S52 P1.0 D0

P1.1 D1

P1.2
figure 2.7 LCD Interfacing
D2 with Microcontroller

P1.3 D3

P1.4 D4

P1.5 D5 15

P1.6 D6 16

P1.7 D7

Department of ECE PRIW- KHAMMAM 41


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

2.8 IR SENSOR:

Figure 2.8 IR Sensor


The IR sensor module consists mainly of the IR Transmitter and Receiver, Opamp,
Variable Resistor (Trimmer pot), output LED in brief.

2.8.1 IR LED Transmitter

IR LED emits light, in the range of Infrared frequency. IR light is invisible to us as its
wavelength (700nm – 1mm) is much higher than the visible light range. IR LEDs have light
emitting angle of approx. 20-60 degree and range of approx. few centimetres to several feets, it
depends upon the type of IR transmitter and the manufacturer. Some transmitters have the range
in kilometres. IR LED white or transparent in colour, so it can give out amount of maximum
light.

2.8.2 Photodiode Receiver

Photodiode acts as the IR receiver as its conducts when light falls on it. Photodiode is a
semiconductor which has a P-N junction, operated in Reverse Bias, means it start conducting the
current in reverse direction when Light falls on it, and the amount of current flow is proportional
to the amount of Light. This property makes it useful for IR detection. Photodiode looks like a

Department of ECE PRIW- KHAMMAM 42


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

LED, with a black colour coating on its outer side, Black colour absorbs the highest amount
of light.

2.8.3 LM358 Opamp

LM358 is an Operational Amplifier (Op-Amp) is used as voltage comparator in the IR


sensor. the comparator will compare the threshold voltage set using the preset (pin2) and the
photodiode’s series resistor voltage (pin3).

Photodiode’s series resistor voltage drop> Threshold voltage = Opamp output is High

Photodiode’s series resistor voltage drop< Threshold voltage = Opamp output is Low

When Opamp's output is high the LED at the Opamp output terminal turns ON (Indicating the
detection of Object).

Variable Resistor

The variable resistor used here is a preset. It is used to calibrate the distance range at which
object should be detected.

2.8.4 IR SENSOR MODULE PINOUT:

figure 2.8.4 IR Sensor module pinout

Department of ECE PRIW- KHAMMAM 43


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

2.8.5 Pin Configuration:

Pin Name Description

VCC Power Supply Input

GND Power Supply Ground

OUT Active High Output

Table 2.8.5 Pin Configuration

2.9 IR Sensor Module Features

 5VDC Operating voltage

 I/O pins are 5V and 3.3V compliant

 Range: Up to 20cm

 Adjustable Sensing range

 Built-in Ambient Light Sensor

 20mA supply current

 Mounting hole

2.9.1 IR SENSOR WORKING PRINCIPLE:

An IR sensor consists of an IR LED and an IR Photodiode; together they are called as


Photo–Coupler or up to –Coupler. As said before, the Infrared Obstacle Sensor has built in IR
transmitter and IR receiver. Infrared Transmitter is a light emitting diode (LED) which emits
infrared radiations. Hence, they are called IR LED’s. Even though an IR LED looks like a
normal LED, the radiation emitted by it is invisible to the human eye.

Department of ECE PRIW- KHAMMAM 44


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

Figure 2.9.1 IR Sensor Working

Infrared receivers are also called as infrared sensors as they detect the radiation from an
IR transmitter. IR receivers come in the form of photodiodes and phototransistors. Infrared
Photodiodes are different from normal photo diodes as they detect only infrared radiation. When
the IR transmitter emits radiation, it reaches the object and some of the radiation reflects back to
the IR receiver. Based on the intensity of the reception by the IR receiver,

Department of ECE PRIW- KHAMMAM 45


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

CHAPTER 3

SYSTEM DESIGN
Designing of this system is possible when you select the specific controller to suite. For
this we selected 89S52 controller. With the help of 89S52 controller traffic control system can be
implemented successfully with the help IR technology. To the controller we connected IR
transmitter and receiver circuit. Instead of IR transmitter and receiver we can go with photo
diode and photo transmitters also. Here we are using four IR pairs for each side.

Whenever vehicles reach the junction on each side, then IR detects the vehicle by sending
signal to controller and the controller will counts the count of vehicles. And calculate the
maximum count from them and give the path to side which has maximum count by glowing
green LED and other three sides red LED shall be glow.

3.1 Hardware Design:

3.1.1 Schematic

J3

LCD
GND
VCC
P0.0
P0.1
P0.2
P0.3
P0.4
P0.5
P0.6
P0.7
gnd
vcc

RS

EN
W
3

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

CAP C5
C7 POT
VCC
U3

2 1 CAP
C4 V+ C1+ 3
C1- C6 U1
6 J3
V- 4
P2 C2+ 5 1 1 40 J2
5 CAP C2- 2 2 P1.0 VCC
9 14 11 CAP 3 3 P1.1 39 1
4 13 T1OUT T1IN 12 4 4 P1.2 P0.0/AD0 38 2
8 R1IN R1OUT 5 5 P1.3 P0.1/AD1 37 3
3 7 10 TXD 6 6 P1.4 P0.2/AD2 36 4
7 8 T2OUT T2IN 9 RXD SW1 C1 7 7 P1.5 P0.3/AD3 35 5
2 R2IN R2OUT 8 8 P1.6 P0.4/AD4 34 6
C P1.7 P0.5/AD5
6 33 7
1 P0.6/AD6 32 8
MAX232 CON8 9 P0.7/AD7
RST
CONNECTOR DB9 R4 31 CON8
R J4 EA/VPP
J7 30
CON2 1 RXD 10 ALE/PROG 29
2 TXD 11 P3.0/RXD PSEN J2
3 12 P3.1/TXD
4 13 P3.2/INT0 28 1
5 14 P3.3/INT1 P2.7/A15 27 2
1
2

6 15 P3.4/T0 P2.6/A14 26 3
7 16 P3.5/T1 P2.5/A13 25 4
8 17 P3.6/WR P2.4/A12 24 5
C3 P3.7/RD P2.3/A11 23 6
P2.2/A10 22 7
1

CON8 18 P2.1/A9 21 8
U6 XTAL2 P2.0/A8
1

CAP
t/f (4pin)
Y1 CON8
CRY STAL
3

C2
19
3

XTAL1
20
CAP GND

D1 D2 D4 D6 U5
DIODE DIODE DIODE DIODE +5V
1 2 AT89S52
GND

VIN VOUT

C8 R5
LM7805/TO 104 R
3

C9
= 1000UF/25V

Title
C <Title>
LED
D5 Size Document Number Rev
A <Doc> <Rev Code>

Date: Thursday , July 15, 2010 Sheet 1 of 1

Figure 3.1.1 Schematic diagram

Department of ECE PRIW- KHAMMAM 46


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

3.2.Schematic Description
The main aim of this power supply is to convert the 230V AC into 5V DC in order to give supply
for the TTL. This schematic explanation includes the detailed pin connections of every device with the
microcontroller. This schematic explanation includes the detailed pin connections of every device with
the microcontroller. Let us see the pin connections of each and every device with the microcontroller in
detail.

Power Supply:

In this process we are using a step down transformer, a bridge rectifier, a smoothing circuit and
the RPS. At the primary of the transformer we are giving the 230V AC supply. The secondary is
connected to the opposite terminals of the Bridge rectifier as the input. From other set of opposite
terminals we are taking the output to the rectifier.

The bridge rectifier converts the AC coming from the secondary of the transformer into pulsating
DC. The output of this rectifier is further given to the smoother circuit which is capacitor in our project.
The smoothing circuit eliminates the ripples from the pulsating DC and gives the pure DC to the RPS to
get a constant output DC voltage. The RPS regulates the voltage as per our requirement.

Microcontroller:

The microcontroller AT89S52 with Pull up resistors at Port0 and crystal oscillator of
11.0592 MHz crystal in conjunction with couple of capacitors of is placed at 18th& 19th pins of
89S51 to make it work (execute) properly.

IR Module:
The IR transmitter and receiver are input and output devices. This is connected to the port P2 of
the Microcontroller.

LCD:
The LCD data lines are connected to port 0 of the microcontroller in the schematic and
the control signals like RS, EN are connected to pin2,3 of port 1.

Department of ECE PRIW- KHAMMAM 47


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

CHAPTER 4
IMPLEMENTATION
The applications as discussed in the design are implemented and the source code related
to the current work is pasted in the appendix.

4.1 SOFTWARE

µ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.
To help you get started, several example programs (located in the \C51\Examples,
\C251\Examples, \C166\Examples, and \ARM\...\Examples) are provided.

 HELLO is a simple program that prints the string "Hello World" using the Serial
Interface.

4.2 Building an Application in µVision2:


To build (compile, assemble, and link) an application in µVision2, you must:

1. Select Project - (for example, 166\EXAMPLES\HELLO\HELLO.UV2).


2. Select Project - Rebuild all target files or Build target.
µVision2 compiles, assembles, and links the files in your project.

Department of ECE PRIW- KHAMMAM 48


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

To create a new project in µVision2, you must:

1. Select Project - New Project.


2. Select a directory and enter the name of the project file.
3. Select Project - Select Device and select an 8051, 251, or C16x/ST10 device from the
Device Database™.
4. Create source files to add to the project.
5. Select Project - Targets, Groups, Files, Add/Files, select Source Group1, and add the
source files to the project.
6. Select Project - Options and set the tool options. Note when you select the target device
from the Device Database™ all special options are set automatically. You typically only
need to configure the memory map of your target hardware. Default memory model
settings are optimal for most applications.
7. Select Project - Rebuild all target files or Build target.

4.3 Debugging an Application in µVision2


To debug an application created using µVision2, you must:

1. Select Debug - Start/Stop Debug Session.


2. Use the Step toolbar buttons to single-step through your program. You may enter G,
main in the Output Window to execute to the main C function.
3. Open the Serial Window using the Serial #1 button on the toolbar.
Debug your program using standard options like Step, Go, Break, and so on

4.4 Starting µVision2 and creating a Project

µVision2 is a standard Windows application and started by clicking on the program icon.
To create a new project file select from the µVision2 menu.

Project – New Project…. This opens a standard Windows dialog that asks you for the new
project file name. We suggest that you use a separate folder for each project. You can simply use
the icon Create New Folder in this dialog to get a new empty folder. Then select this folder and
enter the file name for the new project, i.e. Project1.

Department of ECE PRIW- KHAMMAM 49


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

4.5 Window – Files.

Now use from the menu Project – Select Device for Target and select a CPU for your
project. The Select Device dialog box shows the µVision2 device database. Just select the
microcontroller you use. We are using for our examples the Philips 80C51RD+ CPU. This
selection sets necessary tool options for the 80C51RD+ device and simplifies in this way the tool
Configuration

4.5.1 Building Projects and Creating a HEX Files

Typical, the tool settings under Options – Target are all you need to start a new
application. You may translate all source files and line the application with a click on the Build
Target toolbar icon. When you build an application with syntax errors, µVision2 will display
errors and warning messages in the Output

Window – Build page. A double click on a message line opens the source file on the
correct location in a µVision2 editor window.

Once you have successfully generated your application you can start debugging. After
you have tested your application, it is required to create an Intel HEX file to download the
software into an EPROM programmer or simulator. µVision2 creates HEX files with each build
process when Create HEX files under Options for Target – Output is enabled. You may start
your PROM programming utility after the make process when you specify the program under the
option Run User Program #1.

4.5.2 CPU Simulation

µVision2 simulates up to 16 Mbytes of memory from which areas can be mapped for
read, write, or code execution access. The µVision2 simulator traps and reports illegal memory
accesses being done.

In addition to memory mapping, the simulator also provides support for the integrated
peripherals of the various 8051 derivatives. The on-chip peripherals of the CPU you have
selected are configured from the Device

Department of ECE PRIW- KHAMMAM 50


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

4.5.3 Database selection

You have made when you create your project target. Refer to page 58 for more
Information about selecting a device. You may select and display the on-chip peripheral
components using the Debug menu. You can also change the aspects of each peripheral using the
controls in the dialog boxes.

4.5.4 Start Debugging

You start the debug mode of µVision2 with the Debug – Start/Stop Debug Session
command. Depending on the Options for Target – Debug Configuration, µVision2 will load the
application program and run the start up code µVision2 saves the editor screen layout and
restores the screen layout of the last debug session. If the program execution stops, µVision2
opens an editor window with the source text or shows CPU instructions in the disassembly
window. The next executable statement is marked with a yellow arrow. During debugging, most
editor features are still available.

For example, you can use the find command or correct program errors. Program source
text of your application is shown in the same windows. The µVision2 debug mode differs from
the edit mode in the following aspects:

_ The “Debug Menu and Debug Commands” described on page 28 are Available. The additional
debug windows are discussed in the following.

_ The project structure or tool parameters cannot be modified. All build Commands are disabled.

4.5.5 Disassembly Window

The Disassembly window shows your target program as mixed source and assembly
program or just assembly code. A trace history of previously executed instructions may be
displayed with Debug – View Trace Records. To enable the trace history, set Debug –
Enable/Disable Trace Recording. If you select the Disassembly Window as the active window
all program step commands work on CPU instruction level rather than program source lines. You
can select a text line and set or modify code breakpoints using toolbar buttons or the context
menu commands.

Department of ECE PRIW- KHAMMAM 51


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

CHAPTER 5
SYSTEM TESTING
Density based traffic control system is a system which shall be able to count the vehicles
at each side of the junction road when vehicles are reached near to that junction. After
connecting the circuit and writing the code, then test it by sensing the IR sensor dated term used
to describe an upto-electronic means of sensing something, most commonly a photo detector of
some type. The system can be tested with the use of KEIL compiler. This one we are using to
write programs for 8051 controller. After writing programs using 8051 programmer we can
dump code in to the controller. Now develop the system by using IR transmitter and receiver, we
can use photo diode and photo transistors. To test the board, First of all write a program in terms
of like first enable LCD. To activate LCD send proper commands to it and after that configure
baud rate, parity and number of bits for the serial port. After initializing all the devices connected
to the controller,

While testing keep the transmitter & receiver aligned in a straight position facing each other
about a distance more than 2 meter but not less than that. If the transmitter and receiver are not in
a aligned position data communication is not possible. Connect the output of IR receiver to the
controller port pin. If there is no intruder the output pin will show low value. If there is any
introduce it will show high value. In program monitor for high value and when you the value is
high sense a message to a number indicating that intruder detected.

Department of ECE PRIW- KHAMMAM 52


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

CHAPTER – 6

6.1 ADVANTAGES

 Avoids wastage of time due to the traffic.


 Low cost to design the circuit, maintenance the circuit is good.
 Low power consumption.
 By using this controller IC we can create many more control to the appliances.
 Light efficient light can be achieved with high intensity high power LED.
 It mainly to make the traffic management system a smart and intelligent one.
 It save the precious time of the commuters on road.
 It replace the traditional of traffic management system.
 It reduces the excess expenditure of government on traffic police.
 It also reduce the need for the construction of more reads, as traffic will be easily
managed on the existing ones itself.
 Fuel is saved to avoid 70% compared to normal timer based traffic control.
 Traffic can be cleared without any irregularities.

Department of ECE PRIW- KHAMMAM 53


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

6.2 APPLICATIONS

 Control traffic in metro Politian cities.


 Controlling signals like emergency.
 Edge detection
 First order edge detection.
 Robot operator.

6.3 Future scope

This project can be enhanced in such away as to control automatically the signals
depending on the traffic density on the roads using sensors like IR detector/receiver module
extended with automatic turn off when no vehicles are running on any side of the road which
helps in power consumption saving

Department of ECE PRIW- KHAMMAM 54


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

CONCLUSION

The controller we used having the following features like 8 bit 8051 architecture in a tiny
40 pin DIP package,128B RAM and 4kB on-chip Flash Program Memory. For low end
applications this controller is very easy to use and at the same time IR also widely accepted
protocol for mobile communication. By using IR technology and 8051 architecture based
microcontroller we implemented electronic based traffic density control system.

Department of ECE PRIW- KHAMMAM 55


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

REFERENCES

1. Vidhya, K., and A. BazilaBanu. "Density based traffic signal system." International
Journal of Innovative Research in Science, Engineering and Technology 3.3 (2014):
2218-2222.
2. Hussian, R., Sharma, S., Sharma, V., & Sharma, S. (2013). WSN applications:
Automated intelligent traffic control system using sensors. Int. J. Soft Comput. Eng, 3(3),
77-81.
3. https://www.electronicshub.org/density-based-traffic-signal-system-using-
microcontroller/
4. https://www.scribd.com/doc/37669227/Density-Based-Traffic-Light-Control-System
5. https://www.researchgate.net/publication/318470659_Traffic_Density_Based_Light_Con
trol_System

Department of ECE PRIW- KHAMMAM 56


TRAFFIC CONTROL SYSTEM BASED ON THE TRAFFICDENSITY

Department of ECE PRIW- KHAMMAM 57

Vous aimerez peut-être aussi