16鍵計算器 c51實現(xiàn) 作者: 時間:2016-11-29 來源:網(wǎng)絡(luò) 加入技術(shù)交流群 掃碼加入和技術(shù)大咖面對面交流海量資料庫查詢 收藏 void disp_LED() interrupt 1{TL0=0x0; //延時2.5mS的定時器初始值TH0=0xf7;if (disp_buffer[0]==5) disp_buffer[0]=1;display(disp_buffer[disp_buffer[0]],disp_buffer[0]);disp_buffer[0]++;}void get_keypad_code() interrupt 2{unsigned char i,key;EA=0;for (i=0;i<=3;i++){key=read_key(light[i]); //讀鍵碼if (key!=0xff) delay(10); //延時5-10ms,去抖動if (read_key(light[i])!=key) key=0xff; //讀鍵碼比較if (key!=0xff){key_buffer[0]=1; //緩沖區(qū)滿key_buffer[1]=key; //鍵碼} }EA=1;}unsigned char read_key(unsigned char scan){P1=scan; //掃描switch(P1) //返回掃描碼->鍵碼{case 0x77:return(0x7);case 0xb7:return(0x8);case 0xd7:return(0x9);case 0xe7:return(0xd);case 0x7b:return(0x4);case 0xbb:return(0x5);case 0xdb:return(0x6);case 0xeb:return(0xc);case 0x7d:return(0x1);case 0xbd:return(0x2);case 0xdd:return(0x3);case 0xed:return(0xb);case 0x7e:return(0xf);case 0xbe:return(0x0);case 0xde:return(0xe);case 0xee:return(0xa);default: return(0xff);}}unsigned char display(unsigned char disp_key,unsigned char n) //disp_key 顯示字符,n 燈位{if ((n<=4)&&(n>=1)) LED_light=light[n-1];else LED_light=0xff;if ((disp_key>=0)&&(disp_key<=16)) LED_seg=seg[disp_key];else LED_seg=0x00;return light[n-1];}void delay(unsigned int k) //延時k*1ms{unsigned int i,j;for (j=0;j<=k;j++)for(i=0;i<=1085;i++);} 上一頁 1 2 下一頁
評論