#include
#define uchar unsigned char
#define uint unsigned int
uchar b=5,c;
unsigned char code a[]=;
sbit sg=P1^0;
sbit sy=P1^1;
sbit sr=P1^2;
sbit hg=P1^3;
sbit hy=P1^4;
sbit hr=P1^5;
sbit ge=P1^6;
sbit shi=P1^7;
uint num1,num2,num3;
void delay(unsigned int z1)
{
unsigned int a1,b1;
for(a1=z1;a1>0;a1--)
for(b1=12500;b1>0;b1--);
}
void main()
{
P2=0;
P1=0;
shi=1;
P2=a[8];
shi=0;
ge=1;
P2=a[4];
ge=0;
TMOD=0X11;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
EA=1;
ET0=1;
ET1=1;
TR0=1;
TR1=1;
while(1)
{
switch(num2) //红绿灯
{
case(0): //10s内s绿灯亮
sr=0;
hg=0;
sg=1;
hr=1;
break;
case(1): //5S:竖黄横红
sg=0;
sy=1;
delay(5);
sy=0;
delay(5);
break;
case(2): //10s:竖红横绿
sg=0;
sr=1;
sy=0;
hg=1;
hr=0;
break;
case(3): //5S:竖红横黄
hg=0;
hy=1;
delay(5);
hy=0;
delay(5);
break;
}
}
}
void timer0() interrupt 1 //定时器0
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
num1++;
if(num1==200)
num2=1;
if(num1==300)
num2=2;
if(num1==500)
num2=3;
if(num1==600)
{
num1=0;
num2=0;
}
}
void timer1() interrupt 3 //定时器1
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
num3++;
if(num3>=20) //数码管显示
{
num3=0;
c++;
ge=1;
P2=a[b++];
ge=0;
if(b>=10)
b=0;
if(b==1)
{
P2=a[9];
shi=1;
shi=0;
}
if(c>=15)
{
c=0;
shi=1;
P2=a[8];
shi=0;
ge=1;
P2=a[4];
ge=0;
b=5;
}
}
}