Circuits on Matrixboard |
Soldering part |
Traffic Light Program( C ):
#include<reg51.h>
sbit R1=P1^2;
sbit Y1=P1^1;
sbit G1=P1^0;
sbit R2=P1^3;
sbit Y2=P1^4;
sbit G2=P1^5;
sbit R3=P2^2;
sbit Y3=P2^3;
sbit G3=P2^4;
sbit R4=P2^7;
sbit Y4=P2^6;
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();
}
}
0 comments: