0% found this document useful (0 votes)
55 views

Traffic Light

This document defines the variables and logic to control a 4-way traffic light system using an 8051 microcontroller. It declares bits to control the individual red, yellow, and green LEDs for each of the 4 directions. The main loop sequentially turns on the green, then yellow, then red light for each direction, with delays between transitions, to continuously cycle through the 4-way signal.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views

Traffic Light

This document defines the variables and logic to control a 4-way traffic light system using an 8051 microcontroller. It declares bits to control the individual red, yellow, and green LEDs for each of the 4 directions. The main loop sequentially turns on the green, then yellow, then red light for each direction, with delays between transitions, to continuously cycle through the 4-way signal.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include<reg51.

h> // calling the header file


sbit red1=P1^2; //variable Declaration we are now defining 12 bits of port
P1 and P2
sbit yellow1=P1^1; // for the purpose of accessing each LED of four ways
namely red yellow
sbit green1= P1^0; // and green.
sbit red2=P1^3;
sbit yellow2=P1^4;
sbit green2= P1^5;
sbit red3=P2^0;
sbit yellow3=P2^1;
sbit green3= P2^2;
sbit red4=P2^3;
sbit yellow4=P2^4;
sbit green4= P2^5;

void main(void)
{

unsigned int i; // declare an integer i and put the value to zero


red1=yellow1=green1=0; // initially put all variable values to zero
red2=yellow2=green2=0;
red3=yellow3=green3=0;
red4=yellow4=green4=0;
while(1) // for infinite loop or continuous operation

{
red1=1; //Initially we start with IVth signal put red light as 1 for
remaining three directions
red2=1;
red3=1;
green4=1; //put the value of green light of traffic signal four as
1
yellow4=0;
red4=0;
{
for(i=0;i<=60000;i++); // the loop will executed for 60000 times to generate
delay.
for(i=0;i<=60000;i++); // repeat the loop because we can not go beyond 65536
by defining unsigned int
}
green4=0; //now put green4 as 0
yellow4=1; // yellow4 willbe now 1
{
for(i=0;i<=40000;i++); //put value of red4 as 1
for(i=0;i<=40000;i++); // Delay of 40000 is created
}
yellow4=0; // now put value of yellow 4 as 0
red4=1; // now put value of red4 as 1
red3=0; // put value of red3 as 0
green3=1;
{
for(i=0;i<=60000;i++); // Delay of 60000 is created
for(i=0;i<=60000;i++); // Delay of 60000 is created
}
green3=0; // put green3 OFF
yellow3=1; //Yellow 3 ON
{
for(i=0;i<=40000;i++); // Delay of 40000 is created
for(i=0;i<=40000;i++);
}
yellow3=0; // put yellow 3 OFF
red3=1;
red1=0; // put red 3 On
green1=1; // put green1 ON
{
for(i=0;i<=60000;i++); // Delay of 60000 is created
for(i=0;i<=60000;i++);
}
green1=0; //put green 1 OFF
yellow1=1; // put yellow 1 ON
{
for(i=0;i<=40000;i++);
for(i=0;i<=40000;i++); //Delay of 40000 is created
}
yellow1=0; // PUT Yellow1 OFF, red 1 ON, Red 2 OFF, Green 2 ON
red1=1;
red2=0;
green2=1;
{
for(i=0;i<=60000;i++); //Delay of 60000 is created
for(i=0;i<=60000;i++);
}
green2=0; //put green 2 OFF Yellow 2 ON
yellow2=1;
{
for(i=0;i<=40000;i++); // Delay of 40000 is created
for(i=0;i<=40000;i++);
}
yellow2=0; // put yellow2 OFF red2 ON
red2=1;

}
}

You might also like