|
#include <reg52.h>
#define uchar unsigned char
#define unit unsigned int
sbit light_R1=P2^0;
sbit light_G1=P2^1;
sbit light_Y1=P2^2;
sbit light_R2=P2^3;
sbit light_G2=P2^4;
sbit light_Y2=P2^5;
sbit D1=P1^0;
sbit D2=P1^1;
uchar code tab[10]={~0x3f,~0x06,~0x5b,~0x4f,~0x66,~0x6d,~0x7d,~0x7f,~0x6f};
uchar T,shi,ge,s,k,kk;
void main(void)
{uchar time1=60;
T=0;k=0;
kk=0;
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
IT0=1;
EX0=1;
IT1=1;
EX1=1;
shi=3;
ge=0;
while(1)
{
if(k==1)
{D1=0;
D2=0;
light_G1=1;
light_G2=1;
light_R1=1;
light_R2=1;
light_Y1=0;
light_Y2=0;
while(k)
{
if(kk==1)
{
time1=60;
light_Y1=1;
light_Y2=1;
kk=0;
k=0;
}
}
}
if(time1==60)
{
light_G1=0;
light_R2=0;
light_Y2=1;
light_R1=1;
}
D1=1;
D2=0;
P0=tab[shi];
s=50;
while(s--);
P0=0xff;
D1=0;
D2=1;
P0=tab[ge];
s=50;
while(s--);
P0=0xff;D2=0;
if(T==20)
{
T=0;
time1--;
if(time1>30)
{
shi=(time1-30)/10;
ge=(time1-30)%10;
}
else
{
shi=time1/10;
ge=time1%10;
}
if((time1-30)==3)
{
light_G1=1;
light_Y1=0;
light_R2=0;
}
else if(time1==30)
{
light_Y1=1;
light_R1=0;
light_R2=1;
light_G2=0;
}
else if(time1==3)
{
light_G2=1;
light_Y2=0;
light_R1=0;
}
else if(time1==0)
{
time1=60;
shi=3;
ge=0;
}
}
}
}
void timer0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
T++;
}
void interrupt_0() interrupt 0
{
k=1;
}
void interrupt_1() interrupt 2
{
kk=1;
}
|
|