交通灯控制演示器程序
交通灯控制演示器程序 ypedef unsigned char uchar; typedef unsigned int uint; //东西方向车行交通灯控制 sbit EWG=P1^0; sbit EWY=P1^1; sbit EWR=P1^2; //373片选 sbit d1=P1^4; sbit d2=P1^5; //数码管共阳端片选 sbit EW1=P1^6; // sbit EW2=P1^7; // sbit SN1=P3^0; // sbit SN2=P3^1; // //人行道交通灯控制 sbit SNGP=P3^2; sbit EWGP=P3^3; sbit key=P3^4; // 南北方向车行交通灯控制 sbit SNG=P3^5; sbit SNY=P3^6; sbit SNR=P3^7; //共阳数码管1~9 uchar code table1[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90}; uchar code table2[]={0xfe,0xfd,0xfb,0xf7}; uchar code table3[]={0xff,0xdb,0xbd,0x00,0x00,0xbd,0xdb,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff}; uchar code table4[]={0xe7,0xc3,0xa5,0xe7,0xe7,0xa5,0xc3,0xe7,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff}; uchar code table5[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}; uint m,tm,shi,ge,flag1,flag2,flag3,flag4,flag5,i; uchar time1=36,time2=4,time3=36,time4=4,second=0,msecond=0; //函数声明 uint keyscan(); void display(uchar,uchar,uchar); void init(); void delay_ms(uint z) //1ms延时函数 { uint x,y; for(x=z;x>0;x--) for(y=110;y>0;y--); } //初始化函数 void init() { flag1=1; flag2=0; flag3=0; flag4=0; TMOD |=0x01;//定时器设置 10ms in 12M crystal TH0=0xd8; TL0=0xf0; EA=1; ET0=1; } void main() 南北方向车行交通灯控制 sbit SNG=P3^5; sbit SNY=P3^6; sbit SNR=P3^7; //共阳数码管1~9 uchar code table1[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90}; uchar code table2[]={0xfe,0xfd,0xfb,0xf7}; uchar code table3[]={0xff,0xdb,0xbd,0x00,0x00,0xbd,0xdb,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff}; uchar code table4[]={0xe7,0xc3,0xa5,0xe7,0xe7,0xa5,0xc3,0xe7,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff}; uchar code table5[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}; uint m,tm,shi,ge,flag1,flag2,flag3,flag4,flag5,i; uchar time1=36,time2=4,time3=36,time4=4,second=0,msecond=0; //函数声明 uint keyscan(); void display(uchar,uchar,uchar); void init(); void delay_ms(uint z) //1ms延时函数 { uint x,y; for(x=z;x>0;x--) for(y=110;y>0;y--); } //初始化函数 void init() { flag1=1; flag2=0; flag3=0; flag4=0; TMOD |=0x01;//定时器设置 10ms in 12M crystal TH0=0xd8; TL0=0xf0; EA=1; ET0=1; } void main()