0% found this document useful (0 votes)
451 views53 pages

Design and Implementation An 8051 MCU Based Traffic Light Controller

This document provides an overview of a project to design and implement a traffic light controller using an 8051 microcontroller. It discusses the aims and objectives of controlling vehicle traffic in a safe and effective manner. The project consists of a power supply unit, microcontroller unit, and display unit using LEDs to represent the different light signals. The microcontroller is responsible for implementing the traffic light sequence and assigning the appropriate state to each display at the correct time based on a programmed control sequence. It discusses the basic building blocks, principle of operation, and scope of the thesis which will analyze the design, results, and improvements that can be made to the traffic light controller system.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
451 views53 pages

Design and Implementation An 8051 MCU Based Traffic Light Controller

This document provides an overview of a project to design and implement a traffic light controller using an 8051 microcontroller. It discusses the aims and objectives of controlling vehicle traffic in a safe and effective manner. The project consists of a power supply unit, microcontroller unit, and display unit using LEDs to represent the different light signals. The microcontroller is responsible for implementing the traffic light sequence and assigning the appropriate state to each display at the correct time based on a programmed control sequence. It discusses the basic building blocks, principle of operation, and scope of the thesis which will analyze the design, results, and improvements that can be made to the traffic light controller system.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 53

CHAPTER ONE

1.1 INTRODUCTION

Traffic lights make vehicle traffic control much easier, and more effective. Human reliability

is very small, compared to that of most automated systems for reasons that can’t be avoided.

It is therefore paramount to have the safest possible means of controlling vehicle traffic,

considering the fact that failure could result to loss of life and more.

There are two main colors in traffic lights. They are the red light and the green light. The

(amber), which could mean have different things depending on the manner in which it comes.

In most countries, the sequence is red (stop), green (go), amber (prepare to stop). In the UK,

New Zealand and Canada, amber officially means 'stop' (unless it would cause an accident to

do so) but in practice, is treated as 'prepare to stop'. In the UK, Hong Kong, Macau, Pakistan,

Germany, Hungary, Czech Republic, Poland, Denmark, Iceland and Israel, among others, the

sequence includes red and amber together before green, which helps draw attention to the

impending change to green, to allow drivers to prepare to move off. (In many of these

jurisdictions, such as the UK, it is customary for drivers to select neutral and/or use the

handbrake at red lights; the additional phase gives the driver time to select first gear or

release the handbrake before the light turns green). The single flashing amber signal is used

in the UK, Ireland and Australia at Pelican crossings.

In some instances, traffic may turn right after stopping on a red (left in left-driving countries;

right in right-driving countries), providing they give way to the pedestrians and other

vehicles. In some cases which generally disallow this, a sign next to the traffic light indicates

that it is allowed at a particular intersection. Conversely, jurisdictions which generally allow

this might forbid it at a particular intersection with a "no turn on red" sign, or might put a

1
green arrow to indicate specifically when a right turn is allowed without having to yield to

pedestrians (this is usually when traffic from the perpendicular street is making a left turn

onto one's street and thus no pedestrians are allowed in the intersection anyway). Some

jurisdictions allow turning on red in the opposite direction (left in right-driving countries;

right in left-driving countries) from a one-way road onto another one-way road; some of

these even allow these turns from a two-way road onto a one-way road. Also differing is

whether a red arrow prohibits turns; some jurisdictions require a "no turn on red" sign in

these cases.

1.2 PROJECT AIMS AND OBJECTIVES

The aim of this project is to design and implement a traffic light controller that utilizes the

8051 Microcontroller to implement the control sequence. It doesn’t have special features like

giving priority to sirens or congested lanes. The project is realized by the use of a flash

memory 8051 microcontroller.

1.3 PROJECT OVERVIEW

This traffic light controller consists of relatively few units out together. This is solely as a

result of the versatile nature of the microcontroller. The units involved in the realization of

this project include:

 A rectified power supply unit, stepping down the voltage from the mains to 12v and

converting it to 5v DC; the voltage level required for the implementation of this

project.

2
 The microcontroller unit, which functions as the back bone of the project. It is

responsible for timing and implementation of the required sequence.

 The display unit, which is made up of a collection of LEDs (light emitting diodes),

four LEDs representing each light display unit. Five light display units are required

for each display module and one display module is used for each side of the cross

junction.

1.4 PRINCIPLE OF OPERATION

The principle behind the operation of this traffic light controller is centered on the operation

of the microcontroller. The unique and broad range of application of the microcontroller

makes it suitable for the execution of the traffic light control sequence and assignment of

required states to each display at the appropriate time. The microcontroller sends the required

states (high or low) to the various LEDs at the required time, and it implements a delay for as

long as the present states are required. It then sends the next states expected after the time

required for the present states to be active has elapsed and it again implements the delay

required. The microcontroller does all these through a program that is written into it.

1.5 SCOPE OF THESIS

This thesis is made up of five chapters.

Chapter one gives an introduction to the concept of traffic lights, giving a little idea of the

general expectations of a traffic light control and an overview of the variations of different

3
rules applied to designing the control sequence. It also states the aims of the project and gives

a hint of the main project itself.

Chapter two is a literature review of the operation principle of the various units and

components used in implementing the traffic light controller. It focuses mainly on the

microcontroller, which is the brain of the entire system.

Chapter three gives details of the design process and the methods by which the project was

implemented. It shows calculations involved in determining the components that were used,

and the factors that were considered. It also contains tables showing the sequence execution.

Chapter four contains the results that were obtained from each unit of the implemented traffic

light controller. It discusses the results, compares them to the expected theoretical results and

attempts to explain the reasons for any difference that may exist between the expected

theoretical results and the actual practical results obtained.

Chapter five presents the summary of the thesis, suggesting improvements that can be done

and recommending methods or modifications that can reduce or eliminate the limitations this

traffic light controller has.

4
CHAPTER TWO

THEORETICAL BACKGROUND

2.1 INTRODUCTION

In this part of this thesis, an attempt to describe the various blocks and units used implement

the traffic light controller is made. This is to enhance understanding of the operation of the

thesis, considering the fact that the entire traffic light controller is based on the various single

units, used in its implementation.

2.2 BASIC BUIDING BLOCKS OF THE TRAFFIC LIGHT CONTROLLER

The traffic light controller upon which this thesis is based is based constitutes of three

building blocks, namely:

 Power Supply Unit

 Microcontroller Unit

 Display Unit

Each unit performs a unique role in the implementation of the system. The individual units

work together, and they are linked to one another as described in the block diagram below.

5
POWER SUPPLY

MICROCONTROLLER
DISPLAY

Fig. 2.2: Block Diagram of a Traffic Light Controller

The Power Supply unit is connected directly to the other units of the system. This is simply

because each unit requires electrical signals to operate. The microcontroller is connected to

the display as shown in the figure. It basically sends the information required to be displayed.

The microcontroller here doesn’t power the display, because it makes use of negative logic to

send the required information to be displayed.

The theory of operation and function of each unit will be discussed in this chapter of the

thesis.

2.3 POWER SUPPLY UNIT

The power supply unit as the name implies is the part of the system that delivers the power

required for the operation of the entire system. A power supply is typical in every system. In

6
most electronics, relatively low voltages are required. This makes it impossible to use the ac

mains coming from a power grid to supply required excitation. As a result, is necessary to

provide a means of stepping down the voltage from the mains and this is conveniently done

by a transformer. In direct current (dc) systems (systems that make use of dc sources) it is

further required that the stepped down voltage is converted into a dc source. This conversion

is done a rectifier. The rectified signal is then filtered to make it as close as it can be to an

ideal dc voltage signal. A regulator is used to achieve a fixed output voltage.

The figure below shows a block diagram of a general Power Supply.

TRANSFORMER RECTIFIER FILTER REGULATOR

Ac mains Load Load

Fig. 2.3: Block Diagram of a Basic Power Supply

As shown in fig. 2.3, a basic Power Supply unit is made up of four main sections, namely:

 The Transformer

 The Rectifier

 The Filter section

 The Regulator

The requirements and mode of operation of each of the blocks will be discussed.

7
2.3.1 THE TRANSFORMER

The transformer steps down or steps up ac voltage. In other words, it either increases or

decreases the magnitude of ac voltage. This implies that it does not change the nature of the

signal. A transformer has two windings, the primary and the secondary windings. The

primary winding is the coil that is connected to the source, while the secondary winding

gives the output, which is either greater than the input (for a step up transformer) or less than

the input (for a step down transformer). The factor responsible for the degree of step up or

step down, and determination of whether a transformer is stepping up or stepping down

voltage, is the ratio of the number turns of primary winding to that of the secondary winding.

The transformer is a step down transformer if this ratio is greater than one, and a step up

transformer if otherwise.

In electronic circuits, step down transformers are more common, and the source primarily

used is the ac mains, which is 220/240v in Nigeria. This voltage is stepped down to a level

suitable for the circuit it is to be used in. The expression relating the ratio of the output

voltage to the input voltage is as below.

𝑁𝑠 𝑉𝑠
=
𝑁𝑝 𝑉𝑝

Vs=output voltage

Vp=input voltage

Ns=Number of turns on secondary winding

Np=Number of turns on primary winding

8
2.3.2 THE RECTIFIER

The rectifier is a circuit made up of four diodes. The function of this section of the Power

Supply is to convert ac voltage into dc voltage. This is done by a network of diodes

connected as shown in the circuit in fig. 2.3.2a. The circuit takes in ac voltage and gives a

rectified dc voltage as shown in fig. 2.3.2b. The rectified signal has ripples which have to be

removed in order to get a desired dc signal. This removal is done by a filter, which is a

capacitor or a network of capacitors.

Fig. 2.3.2a: Rectifier Section

Rectifier

Input waveform Output waveform

Fig. 2.3.2b: Rectification

9
2.3.3 THE FILTER SECTION

This section corrects the output waveform from the rectifier. It smoothens the signal and

makes it suitable for the circuit. A capacitor or a network of capacitors connected in parallel

can implement this. The selection of the smoothening capacitor depends on a number of

factors.

2.3.4 THE REGULATOR

The regulator brings down the voltage from the capacitor to a certain fixed value. This means

that regardless of the voltage input to the regulator from the filtering section, the output of

the entire Power Supply, which comes from the regulator is at a fixed value.

2.4 THE DISPLAY

A display is an output device, used to transmit results from circuit or device in a particular

format. For the purpose of this traffic light controller, the display used is a network of light

emitting diodes. Therefore in this part of the thesis, the light emitting diode commonly

known as the LED is going to be discussed.

2.4.1 LIGHT EMITTING DIODES (LEDs)

The light emitting diode is similar to the normal power diode, except for the fact that it emits

visible light. LEDs just like regular diodes conduct only when the anode is positively biased

10
with respect to the cathode. It produces light when it is forward biased, and the intensity of

the light depends on the design of the diode and the supply voltage. They are generally low

power consuming semiconductor devices.

Several LEDs can be connected together to increase the total intensity of the light they

produce. This finds application in many areas, such as 7 segment displays, moving message

displays and a lot of other lucrative appliances. For the purpose of this project, the LEDs are

connected in parallel to increase the intensity of each display unit. This is quite common,

because of the relative low power consumption of LEDs and the ease of understanding and

maintenance of systems built upon this device.

The specification of the LEDs used for the cause of this project is as shown below.

Table 2.4.1: LED Characteristics

Symbol Parameter Condition Min Typical Max Units

Vf Forward Voltage Vcc=Min, Ii=-12mA 2.0 V

Vr Reverse Voltage Vcc=Min,Ioh=MAX 5.0 V

If Max DC Forward Vcc=Min,Iol=MAX, 35 mA

Current

Pd Max Power Dissipation Vcc=Max, Vi=5.5V 105 mW

Typical Viewing Angle Vcc =Max, Vi=2.4V 90 Degrees

11
The design is based on these characteristics. The current powering the LEDs is supplied by

resistors which are connected to the anodes of the LEDs. The value of the resistor determines

the intensity of the light emitted.

2.5 THE MICROCONTROLLER

Microcontrollers’ producers have been struggling for a long time for attracting more and

more choosy customers. Every couple of days a new chip with a higher operating frequency,

more memory and more high-quality A/D converters comes on the market.

Nevertheless, by analyzing their structure it is concluded that most of them have the same (or

at least very similar) architecture known in the product catalogs as “8051 compatible”. What

is all this about?

The whole story began in the far 80s when Intel launched its series of the microcontrollers

labeled with MCS 051. Although, several circuits belonging to this series had quite modest

features in comparison to the new ones, they took over the world very fast and became a

standard for what nowadays is meant by a word microcontroller.

The reason for success and such a big popularity is a skillfully chosen configuration which

satisfies needs of a great number of the users allowing at the same time stable expanding

(refers to the new types of the microcontrollers). Besides, since a great deal of software has

been developed in the meantime, it simply was not profitable to change anything in the

microcontroller’s basic core. That is the reason for having a great number of various

microcontrollers which actually are solely upgraded versions of the 8051 family. What is it

12
what makes this microcontroller so special and universal so that almost all the world

producers manufacture it today under different name?

Fig. 2.5: 8051 Internal Architecture

As shown on the previous picture, the 8051 microcontroller has nothing impressive at first

sight:

 4 Kb program memory is not much at all.

 128Kb RAM (including SFRs as well) satisfies basic needs, but it is not imposing

amount.

 4 ports having in total of 32 input/output lines are mostly enough to make connection to

peripheral environment and are not luxury at all.

As it is shown on the previous picture, the 8051 microcontroller have nothing impressive at

first sight:

13
The whole configuration is obviously envisaged as such to satisfy the needs of most

programmers who work on development of automation devices. One of advantages of this

microcontroller is that nothing is missing and nothing is too much. In other words, it is

created exactly in accordance to the average user‘s taste and needs. The other advantage is

the way RAM is organized, the way Central Processor Unit (CPU) operates and ports which

maximally use all recourses and enable further upgrading.

2.5.1 8051 Microcontroller's pins

Pins 1-8: (Port 1: P1.0 – P1.7) each of these pins can be configured as input or output.

Pin 9: (Reset) RS Logical one on this pin stops microcontroller’s operating and erases the
contents of most registers. By applying logical zero to this pin, the program starts execution
from the beginning. In other words, a positive voltage pulse on this pin resets the
microcontroller.

Pins10-17: (Port 3: P3.0 – P3.7) Similar to port 1, each of these pins can serve as universal
input or output. Besides, all of them have alternative functions as follows:

Pin 10: (P3.0) RXD Serial asynchronous communication input or Serial synchronous
communication output.

Pin 11: (P3.1) TXD Serial asynchronous communication output or Serial synchronous
communication clock output.

Pin 12: (P3.2) INT0 Interrupt 0 input

Pin 13: (P3.3) INT1 Interrupt 1 input

Pin 14: (P3.4) T0 Counter 0 clock input

Pin 15: (P3.5) T1 Counter 1 clock input

14
Pin 16: (P3.6) WR Signal for writing to external (additional) RAM

Pin 17: (P3.7) RD Signal for reading from external RAM

Pin 18, 19: (X2, X1) Internal oscillator input and output. A quartz crystal which determines
operating frequency is usually connected to these pins. Instead of quartz crystal, the
miniature ceramics resonators can be also used for frequency stabilization.

Pin 20: (GND) Ground

Pin 21-28: (Port 2: P2.0 – P2.7) If there is no intention to use external memory then these
port pins are configured as universal inputs/outputs. In case external memory is used then
the higher address byte, i.e. addresses A8-A15 will appear on this port. It is important to
know that even memory with capacity of 64Kb is not used (i.e. note all bits on port are used
for memory addressing) the rest of bits are not available as inputs or outputs.

Pin 29: (PSEN) If external ROM is used for storing program then it has a logic-0 value every
time the microcontroller reads a byte from memory.

Pin 30: (ALE) Prior to each reading from external memory, the microcontroller will set the
lower address byte (A0-A7) on P0 and immediately after that activates the output ALE.
Upon receiving signal from the ALE pin, the external register (74HCT373 or 74HCT375 circuit
is usually embedded) memorizes the state of P0 and uses it as an address for memory chip.
In the second part of the microcontroller’s machine cycle, a signal on this pin stops being
emitted and P0 is used now for data transmission (Data Bus). In this way, by means of only
one additional (and cheap) integrated circuit, data multiplexing from the port is performed.
This port at the same time used for data and address transmission.

Pin 31: (EA) By applying logic zero to this pin, P2 and P3 are used for data and address
transmission with no regard to whether there is internal memory or not. That means that
even there is a program written to the microcontroller, it will not be executed, the program
written to external ROM will be used instead. Otherwise, by applying logic one to the EA

15
pin, the microcontroller will use both memories, first internal and afterwards external (if it
exists), up to end of address space.

Pin 32-39: (Port 0: P0.0 – P0.7) Similar to port 2, if external memory is not used, these pins
can be used as universal inputs or outputs. Otherwise, P0 is configured as address output
(A0-A7) when the ALE pin is at high level (1) and as data output (Data Bus), when logic zero
(0) is applied to the ALE pin.

Pin 40: (VCC) Power supply +5V

2.5.2 Input/ Output Ports (I/O Ports)

All 8051 microcontrollers have 4 I/O ports, each consisting of 8 bits which can be configured

as inputs or outputs. This means that the user has on disposal in total of 32 input/output lines

connecting the microcontroller to peripheral devices.

A logic state on a pin determines whether it is configured as input or output: 0=output,

1=input. If a pin on the microcontroller needs to be configured as output, then a logic zero (0)

should be applied to the appropriate bit on I/O port. In this way, a voltage level on the

appropriate pin will be 0.

Similar to that, if a pin needs to be configured as input, then a logic one (1) should be applied

to the appropriate port. In this way, as a side effect a voltage level on the appropriate pin will

be 5V (as it is case with any TTL input). This may sound a bit confusing but everything

becomes clear after studying a simplified electronic circuit connected to one I/O pin.

16
Input/output(I/O)pin

This is a simplified overview of what is connected to a pin inside the microcontroller. It

concerns all pins except those included in P0 which do not have embedded pull up resistor.

Port 0

It is specific to this port to have a double purpose. If external memory is used then the lower

address byte (addresses A0-A7) is applied on it. Otherwise, all bits on this port are

configured as inputs or outputs.

Another characteristic is expressed when it is configured as output. Namely, unlike other

ports consisting of pins with embedded pull-up resistor ( connected by its end to 5 V power

supply ), this resistor is left out here. This, apparently little change has its consequences:

If any pin on this port is configured as input then it performs as if it “floats”. Such input has

unlimited input resistance and has no voltage coming from “inside”

When the pin is configured as output, it performs as “open drain”, meaning that by writing 0

to some port’s bit, the appropriate pin will be connected to ground (0V). By writing 1, the

external output will keep on “floating”. In order to apply 1 (5V) on this output, an external

pull-up resistor must be embedded.

Port 1

This is a true I/O port, because there are no role assigning as it is the case with P0. Since it

has embedded pull-up resistors it is completely compatible with TTL circuits.

17
Port 2

Similar to P0, when using external memory, lines on this port occupy addresses intended for

external memory chip. This time it is the higher address byte with addresses A8-A15. When

there is no additional memory, this port can be used as universal input-output port similar by

its features to the port 1.

Port 3

Even though all pins on this port can be used as universal I/O port, they also have an

alternative function. Since each of these functions use inputs, then the appropriate pins have

to be configured like that. In other words, prior to using some of reserve port functions, a

logical one (1) must be written to the appropriate bit in the P3 register. From hardware’s

perspective, this port is also similar to P0, with the difference that its outputs have a pull-up

resistor embedded. The port has pins that are used for other purposes

Current limitations on pins

When configured as outputs ( logic zero (0) ), single port pins can "receive" current of 10mA.

If all 8 bits on a port are active, total current must be limited to 15mA (port P0: 26mA). If all

ports (32 bits) are active, total maximal current must be limited to 71mA.

18
When configured as inputs (logic 1), embedded pull-up resistor provides very weak current,

but strong enough to activate up to 4 TTL inputs from LS series.

2.5.3 8051 Microcontroller Memory Organization

The microcontroller memory is divided into Program Memory and Data Memory. Program

Memory (ROM) is used for permanent saving program being executed, while Data Memory

(RAM) is used for temporarily storing and keeping intermediate results and variables.

Depending on the model in use ( still referring to the whole 8051 microcontroller family) at

most a few Kb of ROM and 128 or 256 bytes of RAM can be used.

All 8051 microcontrollers have 16-bit addressing bus and can address 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 very clever memory organization which makes these

controllers a real “programmers’ tidbit“.

Program Memory

The oldest models of the 8051 microcontroller family did not have internal program memory

. It was added from outside as a separate chip. These models are recognizable by their label

beginning with 803 (for ex. 8031 or 8032). All later models have a few Kbytes ROM

embedded, Even though it is enough for writing most of the programs, there are situations

when additional memory is necessary. A typical example of it is the use of so called lookup

tables. They are used in cases when something is too complicated or when there is no time

19
for solving equations describing some process. The example of it can be totally exotic (an

estimate of self-guided rockets’ meeting point) or totally common( measuring of temperature

using non-linear thermo element or asynchronous motor speed control). In those cases all

needed estimates and approximates are executed in advance and the final results are put in

the tables (similar to logarithmic tables).

20
Fig. 2.5.3a : 8051 Memory Organization

EA=0 In this case, internal program memory is completely ignored, only a program stored in

external memory is to be executed.

EA=1 In this case, a program from built in ROM is to be executed first (to the last location).

Afterwards, the execution is continued by reading additional memory.

in both cases, P0 and P2 are not available to the user because they are used for data nd

address transmission. Besides, the pins ALE and PSEN are used too.

21
Data Memory

As already mentioned, Data Memory is used for temporarily storing and keeping data and

intermediate results created and used during microcontroller’s operating. Besides, this

microcontroller family includes many other registers such as: hardware counters and timers,

input/output ports, serial data buffers etc. The previous versions have the total memory size

of 256 locations, while for later models this number is incremented by additional 128

available registers. In both cases, these first 256 memory locations (addresses 0-FFh) are the

base of the memory common to all types of the 8051 microcontrollers. Locations available to

the user occupy memory space with addresses from 0 to 7Fh. First 128 registers and this part

of RAM is divided in several blocks.

The first block consists of 4 banks each including 8 registers designated as R0 to R7. Prior to

access them, a bank containing that register must be selected. Next memory block ( in the

range of 20h to 2Fh) is bit- addressable, which means that each bit being there has its own

address from 0 to 7Fh. Since there are 16 such registers, this block contains in total of 128

bits with separate addresses (The 0th bit of the 20h byte has the bit address 0 and the 7th bit

of th 2Fh byte has the bit address 7Fh). The third group of registers occupy addresses 2Fh-

7Fh (in total of 80 locations) and does not have any special purpose or feature.

Additional Memory Block of Data Memory

In order to satisfy the programmers’ permanent hunger for Data Memory, producers have

embedded an additional memory block of 128 locations into the latest versions of the 8051

22
microcontrollers. Naturally, it’s not so simple…The problem is that electronics performing

addressing has 1 byte (8 bits) on disposal and due to that it can reach only the first 256

locations. In order to keep already existing 8-bit architecture and compatibility with other

existing models a little trick has been used.

Using trick in this case means that additional memory block shares the same addresses with

existing locations intended for the SFRs (80h- FFh). In order to differentiate between these

two physically separated memory spaces, different ways of addressing are used. A direct

addressing is used for all locations in the SFRs, while the locations from additional RAM are

accessible using indirect addressing.

23
Fig. 2.5.3b: 8051 memory bank

24
2.5.4 SFRs (Special Function Registers)

SFRs are a kind of control table used for running and monitoring microcontroller’s operating.

Each of these registers, even each bit they include, has its name, address in the scope of

RAM and clearly defined purpose ( for example: timer control, interrupt, serial connection

etc.). Even though there are 128 free memory locations intended for their storage, the basic

core, shared by all types of 8051 controllers, has only 21 such registers. Rests of locations are

intentionally left free in order to enable the producers to further improved models keeping at

the same time compatibility with the previous versions. It also enables the use of programs

written a long time ago for the microcontrollers which are out of production now.

A Register (Accumulator)

Fig. 2.5.3c: Accumulator Register

This is a general-purpose register which serves for storing intermediate results during

operating. A number (an operand) should be added to the accumulator prior to execute an

instruction upon it. Once an arithmetical operation is preformed by the ALU, the result is

placed into the accumulator. If a data should be transferred from one register to another, it

must go through accumulator. For such universal purpose, this is the most commonly used

25
register that none microcontroller can be imagined without (more than a half 8051

microcontroller's instructions used use the accumulator in some way).

B Register

B register is used during multiply and divide operations which can be performed only upon

numbers stored in the A and B registers. All other instructions in the program can use this

register as a spare accumulator (A).

Fig. 2.5.3d: Register B

26
Registers (R0-R7)

Fig. 3.5.3e: RAM Configuration

This is a common name for the total 8 general purpose registers (R0, R1, R2 ...R7). Even

they are not true SFRs, they deserve to be discussed here because of their purpose. The bank

is active when the R registers it includes are in use. Similar to the accumulator, they are used

for temporary storing variables and intermediate results. Which of the banks will be active

depends on two bits included in the PSW Register. These registers are stored in four banks in

the scope of RAM.

The following example best illustrates the useful purpose of these registers. Suppose that

mathematical operations on numbers previously stored in the R registers should be

performed: (R1+R2) - (R3+R4). Obviously, a register for temporary storing results of

addition is needed. Everything is quite simple and the program is as follows :

27
MOV A,R3; Means: move number from R3 into accumulator

ADD A, R4; Means: add number from R4 to accumulator (result remains in

accumulator)

MOV R5, A; Means: temporarily moves the result from accumulator into R5

MOV A, R1; Means: move number from R1 into accumulator

ADD A, R2; Means: add number from R2 to accumulator

SUBB A, R5; Means: subtract number from R5 ( there are R3+R4 )

PSW Register (Program Status Word)

This is one of the most important SFRs. The Program Status Word (PSW) contains several

status bits that reflect the current state of the CPU. This register contains: Carry bit, Auxiliary

Carry, two register bank select bits, Overflow flag, parity bit, and user-definable status flag.

The ALU automatically changes some of register’s bits, which is usually used in regulation

of the program performing.

P - Parity bit. If a number in accumulator is even then this bit will be automatically set (1),

otherwise it will be cleared (0). It is mainly used during data transmission and receiving via

serial communication.

- Bit 1. This bit is intended for the future versions of the microcontrollers, so it is not

supposed to be here.

OV Overflow occurs when the result of arithmetical operation is greater than 255 (deci mal),

so that it can not be stored in one register. In that case, this bit will be set (1). If there is no

overflow, this bit will be cleared (0).

28
RS0, RS1 - Register bank select bits. These two bits are used to select one of the four

register banks in RAM. By writing zeroes and ones to these bits, a group of registers R0-R7

is stored in one of four banks in RAM.

Space in
RS1 RS2
RAM

Bank0
0 0
00h-07h

Bank1
0 1
08h-0Fh

Bank2
1 0
10h-17h

Bank3
1 1
18h-1Fh

F0 - Flag 0. This is a general-purpose bit available to the user.

AC - Auxiliary Carry Flag is used for BCD operations only.

CY - Carry Flag is the (ninth) auxiliary bit used for all arithmetical operations and shift

instructions.

DPTR Register (Data Pointer)

These registers are not true ones because they do not physically exist. They consist of two

separate registers: DPH (Data Pointer High) and (Data Pointer Low). Their 16 bits are used

29
for external memory addressing. They may be handled as a 16-bit register or as two

independent 8-bit registers. Besides, the DPTR Register is usually used for storing data and

intermediate results which have nothing to do with memory locations.

SP Register (Stack Pointer)

A value of the Stack Pointer ensures that the Stack Pointer will point to valid RAM and

permits Stack availability. By starting each subprogram, the value in the Stack Pointer is

incremented by 1. In the same manner, by ending subprogram, this value is decremented by

1. After any reset, the value 7 is written to the Stack Pointer, which means that the space of

RAM reserved for the Stack starts from this location. If another value is written to this

register then the entire Stack is moved to a new location in the memory.

P0, P1, P2, P3 - Input/output Registers

In case that external memory and serial communication system are not in use then, 4 ports

with in total of 32 input-output lines are available to the user for connection to peripheral

environment. Each bit inside these ports corresponds to the appropriate pin on the

microcontroller. This means that logic state written to these ports appears as a voltage on the

pin ( 0 or 5 V). Naturally, while reading, the opposite occurs – voltage on some input pins is

reflected in the appropriate port bit.

The state of a port bit, besides being reflected in the pin, determines at the same time whether

it will be configured as input or output. If a bit is cleared (0), the pin will be configured as

output. In the same manner, if a bit is set to 1 the pin will be configured as input. After reset,

30
as well as when turning the microcontroller on, all bits on these ports are set to one (1). This

means that the appropriate pins will be configured as inputs.

31
CHAPTER THREE

DESIGN AND IMPLEMENTATION

3.1 INTRODUCTION

This chapter gives details on the considerations made and the factors responsible for the

specific components used in the implementation of the traffic light controller. The traffic

light controller in this project is based on a busy cross-junction, having at least three lanes on

each side (NORTH, EAST, SOUTH and WEST). The system assumes that there are

tributary routes before the junction on each side, and encourages motorists turning to the left

or right to use those routes instead of waiting to get to the junction before turning. This is in

an attempt to reduce congestion at junction, where traffic is heaviest, because it takes a

vehicle more time to turn either right or left, than it takes it to move straight across the

junction.

The system also gives time slots for pedestrians to cross the road from whichever side they

are standing, stopping all vehicles moving along the path they are crossing for the allocated

time period.

3.2 THE SEQUENCE

Fig. 3.2 is a representation of the ‘GO’ states implemented in the traffic light controller. It

shows the transitions in states where vehicle traffic on the four sides are allowed to move.

32
Source: Traffic Advisory Leaflet 1/05, February 2004

Fig. 3.2 Vehicle Traffic ‘GO’ States

In the first stage, all vehicles coming from the south side intending to move in any direction

are allowed to proceed. The same is done in the 4th, 5th and 8th states, for vehicles coming

from the north, west, and east sides respectively. In states two and three, vehicles crossing

from the north to the south and those crossing from the south to the north, are given the

signal to proceed. All vehicles turning to the left or right side from the north or south side are

not allowed to move. This gives a chance for pedestrians on either the south or north side of

the junction, to cross over to the other side. Likewise in states 6 and 7, the vehicles crossing

form east to west or vise versa, are allowed to move on, giving a chance or pedestrians

crossing from the east to the west or vice versa, to over to the other side of the road.

33
34
Table 3.2: Complete Traffic Light Sequence

STATE 1 TRANS 1 STATE 2 TRANS 2 STATE 3 TRANS 3 STATE 4 TRANS 4 STATE 5 TRANS 5 STATE 6 TRANS 6 STATE 7 TRANS 7 STATE 8 TRANS 8

RED 1 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1

NORTH YELLOW 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0

SIDE GREEN 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0

L TURN 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0

R TURN 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0

RED 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0

EAST YELLOW 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1

SIDE GREEN 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0

L TURN 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0

R TURN 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0

RED 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 0

SOUTH YELLOW 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1

SIDE GRREEN 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0

L TURN 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

R TURN 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

RED 1 1 1 1 1 1 1 0 0 0 0 0 0 0 1 1

WEST YELLOW 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0

SIDE GREEN 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0

L TURN 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0

R TURN 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0

35
Table 3.2 shows the status of each display in the system throughout the cycle. It also gives

information of the status on the displays during the transition states, where the amber light

gives signals for vehicles to get ready to either stop, or move.

There are a total of five display displays on each side. A ‘1’ on any display in any state or

transition period (TRANS) reveals that the display is ON. While a ‘0’ indicates that the

display is OFF. The main states last for 30seconds, while the transition states last for

5seconds.

3.3 DISPLAY

The design that was carried out for the display section was mainly in connection to the

current limiting resistors used to drive the display units in the section. Each display has four

LEDs, and it is typical that an LED has a current limiting resistor of 330Ω. The displays used

in the traffic light controller, each had a total of four LEDs, and is represented in fig. 3.3.

Fig. 3.3 : LED Display Circuit

36
The current coming into the circuit is spited to the four LEDs. Since it is typical that a 330 Ω

resistor is used in supplying current to one LED, it is ideal that a resistor of 1320 Ω (330

Ωx4) is used to power such a display. However due to the unavailability of this resistor

value, a 1000 Ω resistor is used. This will pull a current of

5
𝐼= = 5𝑚𝐴 . . . 3.3.1
1000

There are a total of 20 displays, hence the total current drawn by the display section is

5𝑚𝐴 × 20 = 100𝑚𝐴 . . . 3.3.2

This has to be considered in the design of the power supply.

3.4 POWER SUPPLY

All stages in this project use +5v. The power supply stage is a linear power supply type and

involves a step down transformer, a bridge rectifier, filter capacitor, and voltage regulator to

give the voltage level. The power supply circuit diagram is shown below.

37
Figure 3.4 Power Supply

Transformer

The transformer needed is a 220/12V; 1A step-down will be more than sufficient to supply

the current required to various components. However, it is still used so that here is a wide

margin of safety.

Rectifying and Smoothing Section

The rectifying section uses 4 diodes, each having the ability of handling 25V and 1A. The

diodes used were all IN 4004. The diodes are connected to implement a full wave bridge

rectifier. A smoothing capacitor is needed to reduce the ac component to a considerable level.

The choice of the filter capacitor is dependent on the output current. Given that

2.4×𝐼𝑑𝑐
Vr(rms) = . . . 3.4a
𝐶𝑓

Where Vr(rms) = Rectified D.C ripple voltage

Idc = Load current (mA)

38
Cf = Filter capacitor (F)

Vr(rms) = 𝑉𝑝𝑒𝑎𝑘 × √3 . . . 3.4b

= 12𝑉 × √3

= 20.78V

For a ripple factor of 5%

5
𝑉𝑟(𝑟𝑚𝑠) = × 20.78
100

= 1.04V

Therefore,

2.4×𝐼𝑑𝑐
𝐶𝑓 = . . . 3.4c
𝑉𝑟(𝑟𝑚𝑠)

For a load current of 500mA and a ripple factor of 5%,

2.4 × 0.1
𝐶𝑓 =
1.04

= 720µF

As a result of the unavailability of this value, a 1000 µF capacitor was used.

39
Voltage Regulator

The microcontroller and LEDs in this project need a voltage of 5V. The voltage regulator that

was used in this project has a current rating of 1A and a minimum input voltage of 7.3V. this

made it suitable for this purpose.

3.5 THE MICROCONTROLLER

The microcontroller that was selected for the purpose of this project was the 89C51

microcontroller, which is a flash memory 8051 microcontroller. It has four input/output

ports, and only two ports are required for the project.

The crystal used to generate the clock was a 4MHz crystal. This was used instead of the more

popular 12MHz crystal, because the loop required to achieve the 30second delay becomes a

lot more complex if a 12MHz crystal is used.

40
CHAPTER FOUR

RESULTS AND DISCUSSION

4.1 TESTS AND RESULTS

Tests were carried out at the various sections of the traffic light controller. The digital meter

was the main instrument used in carrying out the tests. The sections that gave testable tesults

were the power supply and display sections.

4.2 POWER SUPPLY SECTION

In this section, voltages were taken at different points, and the results were as follows:

I. Transformer output 12VAC

II. Filter output 12.5VDC

III. Regulator output 5.05VDC

The main result here is the output voltage at the regulator, which is the voltage level supplied

to the rest of the system. The calculated voltage level at the output of the power supply

(which corresponds to the voltage level at the regulator) was 5V. However, from the readings

obtained, it was 0.05 volts greater. This is acceptable, considering the fact that the deviation

was by only 1%, and the microcontroller has a tolerance of over 10%. This makes the power

supply useful, and therefore it can still be used for the purpose of this project.

41
4.3 DISPLAY SECTION

In the display section, the voltages across the resistors supplying the driving current to the

displays were measured. The output across the resistors were not too far from the calculated

values,

42
CHAPTER FIVE

SUMMARY AND CONCLUSION

5.1 CONCLUSION

The circuit was designed within the operating limits of the components used. The results

obtained form the various sections constituting the traffic light controller showed some

integrity in the design. The traffic sequence was executed as proposed and designed, meaning

that the system was realized. There was however a little deviation in the results obtained

from some of the sections, indicating that the design was not perfect. A little modification

may solve that problem, making the system of generally acceptable standard.

5.2 RECOMMENDATIONS

The system designed has several draw backs. It is a very simple traffic light controller, with

no special features. Considering the fact that a microcontroller is used in the implementation

of the project, it is possible to include a whole lot of additional features into the system. The

lines connecting the microcontroller to the display units can be multiplexed, so that one port

is used to realize the system, increasing the number of ports available for the implementation

of other features. Features that can be added to the implemented system may include an

emergency sequence, which gives priority to ambulances and fire fighting vehicles whenever

it senses sirens corresponding to their frequencies. It could also include another sequence for

43
hours when traffic is less intense. All these can be done with the aid of a few additional

components.

44
REFERENCES

Paul, H. and Winfield, H. (1995), “The Art of Electronics”; Second edition, Cambridge

University Press, London.

Robert, L. B. and Louis N. (1996), “Electronic Devices and Circuit Theory”; Sixth edition, New

Delhi, Asoke, K. G. and Jay P. P.

Theraja, B. L. and Theraja A. K. (1997), “A Textbook of Electrical Technology”; S. Chand and

Company Ltd, New Delhi.

Scott I. M.,(1995), “The 8051 Microcontroller”; Second Edition,. R . Donneley and Sons

Company. Englewood Cliffs, NJ 07632, R

Calcutt D. and Parchizadeh H, (1994), “8051 Microconrollers. An Applications Based

Introduction”;Krips BV, Netherlands

45
APPENDIX A

Fig. 6.1: Main Circuit Diagram

46
APPENDIX B

Fig. 6.2 : Power Supply Circuit

47
APPENDIX C

Source code

HUNDRED EQU 100

THUNDRED EQU 200

MOV TMOD,#01H

MOV 80H,#00H

MOV 90H,#00H

JMP START

START: MOV P1,#01110111b

MOV P0,#11000111b

CALL DELAY1

MOV P1,#10110111b

MOV P0,#11010111b

CALL DELAY2

MOV P1,#11010111b

48
CALL DELAY1

CALL DELAY2

CALL DELAY1

MOV P0,#10110111b

CALL DELAY2

MOV P1,#11000111b

MOV P0,#01110111b

CALL DELAY1

MOV P1,#10110111b

MOV P0,#01111011b

CALL DELAY2

MOV P1,#01110111b

MOV P0,#01111100b

CALL DELAY1

MOV P1,#01111011b

MOV P0,#01111101b

CALL DELAY2

49
MOV P1,#01111101b

CALL DELAY1

CALL DELAY2

CALL DELAY1

MOV P0,#01111011b

CALL DELAY2

MOV P1,#01111100b

MOV P0,#01110111b

CALL DELAY1

MOV P1,#01111011b

MOV P0,#10110111b

CALL DELAY2

LJMP START

DELAY1: MOV R7,#THUNDRED

REPEAT1: MOV TH0,#3CH

50
MOV TL0,#0B0H

SETB TR0

WAIT1: JNB TF0,WAIT1

CLR TF0

CLR TR0

DJNZ R7,REPEAT1

RET

DELAY2: MOV R6,#HUNDRED

REPEAT2: MOV TH0,#0BEH

MOV TL0,#0E5H

SETB TR0

WAIT2: JNB TF0,WAIT2

CLR TF0

CLR TR0

DJNZ R6,REPEAT2

RET

51
APPENDIX D

(a)

(b)

52
(c)

Fig. 6.3:Traffic Light Controller Prototype

53

You might also like