您好,欢迎访问三七文档
当前位置:首页 > 电子/通信 > 综合/其它 > 51单片机四路抢答器程序
#includereg52.hsbitkey1=P3^0;sbitkey2=P3^1;sbitkey3=P3^2;sbitkey4=P3^3;sbitkey5=P3^7;sbitBEEP=P2^0;unsignedchartemp;unsignedcharpulse_number1=9;unsignedcharcodeTAB[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};voiddelay_100ms(unsignedintt){unsignedchari,j,k;for(i=t;i0;i--){for(j=200;j0;j--);{for(k=248;k0;k--);}}}voidbeep(){BEEP=1;delay_100ms(100);BEEP=0;}voidT0_int()interrupt1{staticunsignedcharcount;unsignedchara=1;count++;TH0=(65536-50000)/256;TL0=(65536-50000)%256;if(count==20){count=0;P0=TAB[pulse_number1--];beep();if(pulse_number1==0){P0=TAB[0];TR0=0;while(a){beep();if(!key5)a=0;}}}}voidmain(){bitflag;temp=0x00;P2=temp;P0=0x3f;TMOD=0x01;TH0=(65536-50000)/256;TL0=(65536-50000)%256;ET0=1;EA=1;TR0=1;while(!flag){if(!key1){P0=0x06;beep();flag=1;TR0=0;}elseif(!key2){P0=0x5b;beep();flag=1;TR0=0;}elseif(!key3){P0=0X4f;beep();flag=1;TR0=0;}elseif(!key4){P0=0x66;beep();flag=1;TR0=0;}}while(flag);}
本文标题:51单片机四路抢答器程序
链接地址:https://www.777doc.com/doc-5892091 .html