欢迎来到天天文库
浏览记录
ID:13433078
大小:2.55 MB
页数:9页
时间:2018-07-22
《51单片机抢答器源程序》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、/**********************************************程序名:8路抢答器.c作者:风雪子郁时间:2012/8/22邮箱:fxziyu@qq.com地址:四川信息职业技术学院(雪峰校区)**********************************************/#include#includesbitsjjia=P1^0;sbitsjjian=P1^1;sbitkaishi=P1^2;sbitfuwei=P1^3;sbitsoud=P1^4;
2、sbitled_r=P1^5;sbitled_y=P1^6;sbitled_ce=P3^3;sbitkey_ce=P3^4;unsignedcharnum[]={'0','1','2','3','4','5','6','7','8','9'},num2;unsignedcharmodel,time,temp;voidinit()//初始化函数{TMOD=0x01;TH0=(65536-50000)/256;TL0=(65536-50000)%256;ET0=1;TR0=0;EA=1;P1=0x0f;led_ce=1;key_ce=1;m
3、odel=0;time=30;}voiddelay(unsignedchari)//延时{unsignedcharj,k;while(i--)for(j=100;j>0;j--)for(k=100;k>0;k--);}voidstar()//启动{lcd_xml(0x80);lcd_xsj("welcome");delay(100);lcd_xml(0xc0);lcd_xsj("===>>");delay(30);lcd_xml(0xc0);lcd_xsj("=======>>");delay(30);lcd_xml(0xc0);lcd
4、_xsj("=========>>");delay(30);lcd_xml(0xc0);lcd_xsj("===========>>");delay(30);lcd_xml(0xc0);lcd_xsj("==============>>");delay(30);lcd_xml(0xc0);lcd_xsj("8WayResponder");delay(80);}voidled_num()//刷新倒计时{lcd_xml(0x80);lcd_xsj("Countdown:");lcd_xml(0x8d);lcd_xsj2(num[time/1
5、0]);lcd_xml(0x8e);lcd_xsj2(num[time%10]);}voidreset()//复位{TR0=0;P1=0x0f;led_ce=1;key_ce=1;led_r=0;led_y=0;P2=0xff;model=0;time=30;led_num();lcd_xml(0xc0);lcd_xsj("Notstarted");}voidNot_started(){if(sjjia==0){delay(10);if(sjjia==0){time++;if(time==100)time=0;led_num();}}i
6、f(sjjian==0){delay(10);if(sjjian==0){time--;if(time==0)time=99;led_num();}}if(kaishi==0){delay(10);if(kaishi==0){model=1;TR0=1;lcd_xml(0xc0);lcd_xsj("StartResponder");soud=1;delay(10);soud=0;}}}voidanjian(){led_ce=1;key_ce=0;if(P2!=0xff){delay(5);if(P2!=0xff){temp=~P2;mo
7、del=3;led_r=1;soud=1;delay(10);soud=0;switch(temp){case0x01:num2=1;break;case0x02:num2=2;break;case0x04:num2=3;break;case0x08:num2=4;break;case0x10:num2=5;break;case0x20:num2=6;break;case0x40:num2=7;break;case0x80:num2=8;break;}lcd_xml(0xc0);lcd_xsj("Competitor:");lcd_xm
8、l(0xce);lcd_xsj2(num[num2]);led_ce=0;key_ce=1;time=60;P2=temp;}}}voidfinish(){if(!time){led_y=1;lcd_xml
此文档下载收益归作者所有