The figure below shows the intersection of a main highway wi
Solution
Source Code
C Program to Traffic Light using 8051
#include <reg51.h>
sbit RED1 = P1^0;
sbit YELLOW1 = P1^1;
sbit GREEN1 = P1^2;
sbit RED2 = P3^2;
sbit YELLOW2 = P3^3;
sbit GREEN2 = P3^4;
sbit RED3 = P3^5;
sbit YELLOW3 = P3^6;
sbit GREEN3 = P3^7;
sbit RED4 = P1^3;
sbit YELLOW4 = P1^4;
sbit GREEN4 = P1^;5
void Delay (void)
{
unsigned int i, j;
for (i=0; i<300; i++)
for (j=0; j<700; j++);
}
void Super Delay ( )
{
unsigned int i ;
for (i=0 ; i<30; i++)
Delay( );
}
void main ( )
{
PD = 0;
while (1)
{
R1 = 0; G1 = 1; Y1 = 0; / Understand RED1 is written as R1 and so on through my program.
R2 = 1; G2 = 0; Y2 = 0;
R3 = 1; G3 = 0; Y3 = 0;
r4 = 1; G4 = 0; Y4 = 0;
SuperDelay () ;
G1 = 0; Y1 = 1;
Delay ( ) ;
R1 = 1; G1 = 0; Y1 = 0;
R2 = 0; G2 = 1; Y2 = 0;
R3 = 1; G3 = 0; Y3 = 0;
r4 = 1; G4 = 0; Y4 = 0;
SuperDelay ( ) ;
G2 = 0; Y2 = 1;
Delay ( ) ;
R1 = 1; G1 = 0; Y1 = 0;
R2 = 1; G2 = 0; Y2 = 0;
R3 = 0; G3 = 1; Y3 = 0;
r4 = 1; G4 = 0; Y4 = 0;
SuperDelay ( ) ;
G3 = 0; Y3 = 1;
Delay();
R1 = 1; G1 = 0; Y1 = 0;
R2 = 1; G2 = 0; Y2 = 0;
R3 = 1; G3 = 0; Y3 = 0;
r4 = 0; G4 = 1; Y4 = 0;
SuperDelay ( ) ;
G4 = 0; Y4 = 1;
Delay ( ) ;
}
}

