资源描述
程序#include#define uint unsigned int#define uchar unsigned charsbit DX_R=P10; /东西方向红黄绿灯sbit DX_Y=P11;sbit DX_G=P12;sbit NB_R=P13; /南北方向sbit NB_Y=P14;sbit NB_G=P15;uchar code du_code=0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F; / 09(共阳数码管)uchar num;uchar S20=20, S15=15, S5=5;bit flag=0;void delayms(uint x) /延时程序uint y;for(;x0;x-)for(y=110;y0;y-);void initial() /定期器50msTMOD=0x01;TH0=(65536-50000)/256;TL0=(65536-50000)%256;EA=1;ET0=1;TR0=1;void state1()while(S20) /东西方向红灯亮25秒。南北绿灯两20秒NB_R=1;NB_Y=1;NB_G=0;DX_R=0;DX_Y=1;DX_G=1;if(flag=1)flag=0;S20-; P2=0x01; /南北数码管个位P0=du_codeS20/10;delayms(2);P2=0x02; /南北数码管十位P0=du_codeS20%10; delayms(2);P2=0x04; /东西P0=du_code(S20+5)/10;delayms(2);P2=0x08;P0=du_code(S20+5)%10; delayms(2);S20=20;void state2() /东西红灯闪烁,南北黄灯亮while(S5)NB_R=1;DX_R=0;NB_G=1;DX_Y=1;DX_G=1;if(flag=1)NB_Y=NB_Y;flag=0;S5-;P2=0x01;P0=du_codeS5/10;delayms(2);P2=0x02;P0=du_codeS5%10; delayms(2);P2=0x04;P0=du_codeS5/10;delayms(2);P2=0x08;P0=du_codeS5%10; delayms(2);S5=5;void state3()while(S15)NB_R=0;NB_Y=1;NB_G=1;DX_R=1;DX_Y=1;DX_G=0;if(flag=1)flag=0; S15-; P2=0x01;P0=du_code(S15+5)/10;delayms(2);P2=0x02;P0=du_code(S15+5)%10;delayms(2);P2=0x04;P0=du_codeS15/10;delayms(2);P2=0x08;P0=du_codeS15%10; delayms(2);S15=12;void state4()while(S5)NB_Y=1;NB_G=1;DX_R=1;NB_R=0;DX_G=1;if(flag=1)DX_Y=DX_Y; flag=0; S5-;P2=0x01;P0=du_codeS5/10;delayms(2);P2=0x02;P0=du_codeS5%10; delayms(2);P2=0x04;P0=du_codeS5/10;delayms(2);P2=0x08;P0=du_codeS5%10;delayms(2); S5=5;void main()initial(); while(1) state1(); state2(); state3(); state4(); void timer0() interrupt 1TH0=(65536-50000)/256;TL0=(65536-50000)%256; num+;if(num=20)/20*50MS=1S num=0;flag=1;
展开阅读全文