Tuesday, July 23, 2013

Traffic light project in 8051 C programming

#include<reg51.h>
sbit R1=P1^0;
sbit Y1=P1^1;
sbit G1=P1^2;
sbit R2=P1^3;
sbit Y2=P1^4;
sbit G2=P1^5;
sbit R3=P2^0;
sbit Y3=P2^1;
sbit G3=P2^2;
sbit R4=P2^3;
sbit Y4=P2^4;
sbit G4=P2^5;


void msdelay(unsigned int t)
{
int i,j;
int k=100*t;
for(i=0;i<k;i++)
for(j=0;j<1275;j++);
}

void clear()
{
R1=0;
R2=0;
R3=0;
R4=0;
Y1=0;
Y2=0;
Y3=0;
Y4=0;
G1=0;
G2=0;
G3=0;
G4=0;



void phase1()
{
R1=1;
R2=1;
G3=1;
R4=1;
msdelay(25);
Y3=1;
Y1=1;
msdelay(5);
}

void phase2()
{
G1=1;
R2=1;
R3=1;
R4=1;
msdelay(25);
Y2=1;
Y1=1;
Y4=1;
msdelay(5);
}

void phase3()
{
R1=1;
G2=1;
R3=1;
G4=1;
msdelay(25);
Y2=1;
Y4=1;
msdelay(5);
}

void phase4()
{
R1=1;
G2=1;
R3=1;
R4=1;
msdelay(25);
Y1=1;
Y2=1;
Y3=1;
msdelay(5);
}

void phase5()
{
G1=1;
R2=1;
G3=1;
R4=1;
msdelay(25);
Y1=1;
Y3=1;
Y4=1;
msdelay(5);
}

void phase6()
{
R1=1;
R2=1;
R3=1;
G4=1;
msdelay(25);
Y3=1;
Y4=1;
msdelay(5);
}


void main()
{
P1=0x00;
P2=0x00;
while(1)
  {
 phase1();
 clear();
 phase2();
 clear();
 phase3();
 clear();
 phase4();
 clear();
 phase5();
 clear();
 phase6();
 clear();
  } 

}

One can download Proteus and Keil files through this link

11 comments:

  1. I downloaded Proteus from that link and its work!!! thanks

    ReplyDelete
  2. Hello
    Is it possible to enable the phases by means of switches for each.
    Can you help me for that. Its an assignment for devoloping sensor based.

    ReplyDelete
  3. Hello
    Is it possible to enable the phases by means of switches for each.
    Can you help me for that. Its an assignment for devoloping sensor based.

    ReplyDelete
  4. Hi, do you have anymore examples on 8051 other than this and temperature control? Thank you

    ReplyDelete