您好,欢迎访问三七文档
8人表决器程序#includeREGX51.HsbitTLED=P3^0;sbitclear_key=P2^0;sbitbell=P3^1;sbitLCD_E=P2^7;sbitLCD_RW=P2^6;sbitLCD_RS=P2^5;sfrLCD_DOUT=0X80;sfrkey_interface=0x90;bitclick,obsc_flag,bell_flag,Updata_flag,key_flag,ring_flag;bitclear_flag;unsignedcharIrq_times,time,bell_time,updata_time;unsignedcharobscure;unsignedcharvote_result;unsignedchardisplay_buf[33];unsignedcharcodeTest_string[]={Thisisvotemachineprogram#};voidtimes1()interrupt3using2{TH1=0X3C;TL1=0XA8;if(bell_flag&&bell_time2){bell=0;bell_time++;}else{if(!ring_flag)bell=1;bell_time=0;bell_flag=0;}if(++updata_time3){Updata_flag=~Updata_flag;updata_time=0;}if(++Irq_times==10){click=~click;}elseif(Irq_times==20){Irq_times=0;click=~click;time++;}}voiddelay(unsignedchartimes){while(--times);}unsignedcharRead_lcd_cr(void){unsignedcharbyte;LCD_RS=0;LCD_RW=1;LCD_E=1;delay(4);byte=LCD_DOUT;LCD_E=0;return(byte);}voidWrite_lcd_cr(unsignedcharthedata){LCD_DOUT=thedata;LCD_RS=0;LCD_RW=0;LCD_E=1;delay(4);LCD_E=0;}voidWrite_lcd_dr(unsignedcharthedata){LCD_DOUT=thedata;LCD_RS=1;LCD_RW=0;LCD_E=1;delay(4);LCD_E=0;}voidTest_LCDBF(void){unsignedchartemp;do{temp=Read_lcd_cr();}while(temp&0x80);}voidLCD_INIT(void){Write_lcd_cr(0x38);Test_LCDBF();Write_lcd_cr(0x06);Test_LCDBF();Write_lcd_cr(0x0f);Test_LCDBF();Write_lcd_cr(0x01);Test_LCDBF();}voidLCD_display(unsignedchar*string,unsignedcharposition){Write_lcd_cr(position);Test_LCDBF();while(*string!='#'){if(position==0x90){Write_lcd_cr(0xC0);Test_LCDBF();}Write_lcd_dr(*string++);Test_LCDBF();position++;}}unsignedcharkeyscan(void){unsignedcharsccode,recode,i,j;key_interface=0xf0;if((key_interface&0xf0)!=0xf0){for(i=40;i0;i--)for(j=255;j0;j--);if((key_interface&0xf0)!=0xf0){sccode=0xfe;while((sccode&0x10)!=0){key_interface=sccode;if((key_interface&0xf0)!=0xf0){recode=(key_interface&0xf0)|0x0f;return((~sccode)+(~recode));}elsesccode=(sccode1)|0x01;}}}return(0);}voidUpdata_lcd_buf(void){unsignedchari;display_buf[0]='0';display_buf[1]='x';display_buf[2]=vote_result/16+48;display_buf[3]=vote_result%16+48;if(clear_flag){clear_flag=0;for(i=0;i=31;i++){display_buf[i]='';}}else{for(i=4;i=31;i++){display_buf[i]='';}}display_buf[32]='#';}voidkey_deal(void){unsignedcharkey_assignments;key_assignments=keyscan();if(key_assignments!=0){bell_flag=1;ring_flag=0;vote_result=key_assignments;}}voidmain(void){unsignedchari,j;TMOD=0x10;EA=1;TR1=1;ET1=1;LCD_E=0;LCD_INIT();LCD_display(Test_string,0x80);while(1){TLED=click;if(!clear_key){for(i=20;i0;i--)for(j=255;j0;j--);if(!clear_key){clear_flag=1;}while(!clear_key);}key_deal();if(Updata_flag){Updata_lcd_buf();LCD_display(display_buf,0x80);}}}
本文标题:8人表决器程序
链接地址:https://www.777doc.com/doc-2892567 .html