proteus交通灯

时间:2018-12-31 05:31:12
【文件属性】:

文件名称:proteus交通灯

文件大小:56KB

文件格式:RAR

更新时间:2018-12-31 05:31:12

proteus 交通灯 c51

#include #define uchar unsigned char #define uint unsigned int unsigned char code ledChar[]= { 0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, //CA数码管编码 0x80, 0x90, 0x88, 0x83, 0xC6, 0xA1, 0x86, 0x8E }; unsigned char ledBuff[2]= { 0xFF, 0xFF //初始化数码管 }; uint count=0; uint x=0; uint time1=15; uint time2=20; Ledshow() { if(x == 0) { if(time1 >=0) { P1 = 0x0c; } } if(x == 1) { if(time1>=0) { P1 = 0x0a; } } if(x == 2) { if(time1>=5) { P1 = 0x21; } if (time1<5) { P1=0x11; } } } /* if(x == 3) { if(time1>=5) { P1 = 0x0A; } }*/ void delay(uint x) { uchar i; while(x--) for(i=0;i<120;i++); } void display() { ledBuff[0]=ledChar[time1/10]; ledBuff[1]=ledChar[time1]; P2=0x01; P0=ledBuff[0]; delay(1); P2=0x02; P0=ledBuff[1]; delay(1); ledBuff[0]=ledChar[time2/10]; ledBuff[1]=ledChar[time2]; P2=0x04; P0=ledBuff[0]; delay(1); P2=0x08; P0=ledBuff[1]; delay(1); Ledshow(); } void main() { TMOD=0x01; TH0=0x3C; TL0=0xb0; TR0=1; EA=1; ET0=1; while(1) { display(); } } void in_TR0() interrupt 1 { TH0=0x3c; //重新赋初值 TL0=0xb0; count++; if (count==20) //我们定义的是1ms中断,要一秒变化一次,让count加到1000 { count=0; //到1000后重新赋初值 time1--; time2--; if(x == 0 && time1 == 0) { time1=5; x = 1; } if(x == 1 && time1 == 0) { time1=20; time2=15; x = 2; } if(x == 2 && time1 ==5) { time2=5; x = 2; } if(x == 2 && time1 ==0) { time1=15; time2=20; x = 0; } } }


【文件预览】:
交通灯
----Traffic_light.plg(8KB)
----NTB.DSN(125KB)
----Last Loaded NTB.DBK(128KB)
----STARTUP.LST(11KB)
----Text1.c(2KB)
----Traffic_light_Uv2.Bak(0B)
----Traffic_light.lnp(51B)
----Traffic_light.Uv2(2KB)
----Traffic_light(5KB)
----Traffic_light.Opt(1KB)
----Traffic_light.hex(2KB)
----STARTUP.A51(5KB)
----Traffic_light.M51(9KB)
----Text1.OBJ(6KB)
----Text1.LST(6KB)
----STARTUP.OBJ(749B)
----NTB.PWI(1KB)

网友评论

  • 感谢,如果是汇编就更好了