欢迎来到天天文库
浏览记录
ID:44185419
大小:18.01 KB
页数:4页
时间:2019-10-19
《单片机红绿灯C语言程序》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、#include#definedxP1#definewxP0unsignedchardig_wx[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};unsignedchardig_dx[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E,0xb0};sbitrr2=P3^0;sbitrg2=P3^1;//第二个人行道intcount;intt=26,time
2、1=10,time2=13;inti;voidinit();voidtimer0();voiddisplay();voiddelay(void);voidmain(){init();while(1){while(i){P2=0;rr2=0;rg2=0;}//保持全亮timer0();display();if((t<=26)&&(t>16)){P2=0XCD;rr2=1;rg2=0;}if((t<=16)&&(t>13)){if(time1==0)time1=3;P2=0XD5;}if((t<=13)&&(t>3)){if(t
3、ime1==0)time1=13;if(time2==0)time2=10;P2=0X7A;rr2=0;rg2=1;}if(t<=3){if(time2==0)time2=3;P2=0XBA;if(t==0){t=26;time1=10;time2=13;}}}}voiddelay(){intt=500;while(t--);}voidinit(){TMOD=0X01;TH0=(65536-50000)/256;TL0=(65536-50000)%256;TR0=1;EA=1;EX0=1;IT0=1;}voidtimer0(
4、){if(TF0==1){TF0=0;TH0=(65536-50000)/256;TL0=(65536-50000)%256;count++;if(count==20){count=0;t--;time1--;time2--;}}}voiddisplay(){wx=dig_wx[0];dx=~dig_dx[time1/10];delay();wx=dig_wx[1];dx=~dig_dx[time1%10];delay();wx=dig_wx[2];dx=~dig_dx[16];delay();wx=dig_wx[3];dx
5、=~dig_dx[time2/10];delay();wx=dig_wx[4];dx=~dig_dx[time2%10];delay();}voidint0()interrupt0{delay();if(INT0==0){P2=0;rg2=0;rr2=0;TR0=~TR0;i=~i;}delay();while(!INT0);//消抖}
此文档下载收益归作者所有