发布网友 发布时间:2023-07-15 09:27
共1个回答
热心网友 时间:2024-12-13 10:53
void main()
{
P3 = 0;
P1 = 0;
P2 = 0xff;
initTimer();
TR0=1;
ET0=1;
EA=1;
while(1)
{
switch(state)
{
// 状态跳转
case 0:
if(ct == 0)
{
P3=0;P1=0;P2=0xff;
ct = 10;
state = 1;
}
break;
case 1:
if(ct == 0)
{
P3=0;P1=0;P2=0xff;
ct = 2;
state = 2;
}
break;
case 2:
if(ct == 0)
{
P3=0;P1=0;P2=0xff;
ct = 2;
state = 3;
}
break;
case 3:
if(ct == 0)
{
P3=0;P1=0;P2=0xff;
ct = 10;
state = 4;
}
break;
case 4:
if(ct == 0)
{
P3=0;P1=0;P2=0xff;
ct = 2;
state = 5;
}
break;
case 5:
if(ct == 0)
{
P3=0;P1=0;P2=0xff;
ct = 2;
state = 0;
}
break;
default:break;
}
// 执行
switch(state)
{
case 0:
//东西绿灯,南北红灯,倒计时30秒;
E_G = 1;W_G = 1;S_R = 1;N_R = 1;
break;
case 1:
//数码管倒计时10秒;
E_G = 1;W_G = 1;S_R = 1;N_R = 1;
display(ct,0);
display(ct,2);
display(ct+2,1);
display(ct+2,3);
break;
case 2:
//东西黄灯,倒计时2秒;
E_Y = 1;W_Y = 1;S_R = 1;N_R = 1;
display(ct,1);
display(ct,3);
break;
case 3:
//南北绿灯,东西红灯,倒计时30秒;
E_R = 1;W_R = 1;S_G = 1;N_G = 1;
break;
case 4:
//数码管倒计时10秒;
E_R = 1;W_R = 1;S_G = 1;N_G = 1;
display(ct,1);
display(ct,3);
display(ct+2,0);
display(ct+2,2);
break;
case 5:
//南北黄灯,倒计时2秒;
E_R = 1;W_R = 1;S_Y = 1;N_Y = 1;
display(ct,0);
display(ct,2);
break;
default:break;
}
}
}