unsigned char counter;
sbit red_nb=P2^0;
......
void main()
{
TMOD=
TH0
TL0
ET0
TR0
while(1) //根据楼主所给,有4种状态
{
state1;
state2;
state3;
state4;
}
}
void timer0() interrupt 1 //定时器0
{
TH0=0x3c;
TL0=0xb0;
counter++;
}
void state1() //控制南北红灯亮,东西绿灯亮,30s
{
unsigned char temp = 30;
red_nb=1;
.....
green_dx=1;
while(1)
{
if( counter>19){counter=0;temp--} //每次counter=20,即1s,temp自减
if(temp) break; //当temp为0时,即30秒,退出状态1,进入状态2
}
}
没经过测试,完全是5分诱惑不大。。