3.traffic Light Interfacing
3.traffic Light Interfacing
(CS)
Electronics Practical Manual
Traffic Light Controller Using 8051 microcontroller
Procedure:
1) Connect 12V DC power adaptor to the 8051 Target board.
2) Start Keil IDE and follow the steps mention in the “Steps to use of Keil
IDE software”.
3) Set the Mode_Sel slide switch in the “8051 section” on “Pgm” mode.
4) Compile the written program, if there are no errors connect the PC to the
programmer placed on the 8051 Target board; by using USB cable.
5) Follow the procedure mention in the “Steps to use of WLPRO software”.
Upload the program.
6) Make necessary connections as shown in the circuit diagram.
7) Set the Mode_Sel slide switch in the “8051 section” on “Run” mode.
8) Observe the output.
Algorithm:
1. Initialization:
Define pin configurations for controlling traffic lights (north, south, west,
east).
Set up a delay function to introduce timing.
(Turn ON only on North and Turn ON only Red for remaining direction)
(Turn ON only Green on South and Turn ON only Red for remaining
direction)
(Turn ON only Green on West and Turn ON only Red for remaining
direction)
(Turn ON only Green on East and Turn ON only Red for remaining direction)
Program:
#include<reg51.h>
sbit rn=P3^0;
sbit yn=P3^1;
sbit rs=P3^2;
sbit ys=P3^3;
sbit rw=P3^4;
sbit yw=P3^5;
sbit re=P3^6;
sbit ye=P3^7;
sbit gn=P2^0;
sbit gs=P2^1;
sbit gw=P2^2;
sbit ge=P2^3;
void delay()
{
long int i;
for(i=0;i<=50000;i++); //3 sec
}
void main()
{
while (1)
{
//north
rn=1;rs=0;rw=0; re=0;
gn=0;gs=1;gw=1;ge=1;
yn=1;ys=1;yw=1;ye=1;
delay();delay();delay();delay();delay(); //15 sec
//south
rn=0;rs=1;rw=0; re=0;
gn=1;gs=0;gw=1;ge=1;
yn=1;ys=1;yw=1;ye=1;
delay();delay();delay();delay();delay(); //15 sec
//west
rn=0;rs=0;rw=1; re=0;
gn=1;gs=1;gw=0;ge=1;
yn=1;ys=1;yw=1;ye=1;
delay();delay();delay();delay();delay(); //15 sec
//east
rn=0;rs=0;rw=0; re=1;
gn=1;gs=1;gw=1;ge=0;
yn=1;ys=1;yw=1;ye=1;
delay();delay();delay();delay();delay(); //15 sec
}
}