|
基于51單片機(jī)的LCD1602顯示矩陣按鍵源程序(分享設(shè)計(jì))
單片機(jī)源程序如下:
- /*******************************************************
- *效果:燒錄如果顯示不正常,重新上電即可。按下矩陣鍵盤(pán)顯示對(duì)應(yīng)按鍵號(hào)
- *
- *
- *
- *********************************************************/
- #include<reg51.h>
- #include"lcd.h"
- #define GPIO_KEY P1
- unsigned char KeyValue;
- //用來(lái)存放讀取到的鍵值
- unsigned char KeyState;
- //用來(lái)存放按鍵狀態(tài)
- unsigned char PuZh[]=" Pechin Science ";
- unsigned char dat[]="0123456789ABCDEF";
- void Delay10ms(); //延時(shí)50us
- void KeyDown(); //檢測(cè)按鍵函數(shù)
-
- /*******************************************************************************
- * 函 數(shù) 名 : main
- * 函數(shù)功能 : 主函數(shù)
- * 輸 入 : 無(wú)
- * 輸 出 : 無(wú)
- *******************************************************************************/
- void main(void)
- {
- unsigned char i;
- LcdInit();
- KeyState=0;
- for(i=0;i<16;i++)
- {
- // LcdWriteCom(0x80);
- LcdWriteData(PuZh[i]);
- }
- while(1)
- {
- KeyDown();
- if(KeyState)
- {
- KeyState=0;
- LcdWriteCom(0x80+0x40);
- LcdWriteData(dat[KeyValue]);
- }
- }
- }
- /*******************************************************************************
- * 函 數(shù) 名 : KeyDown
- * 函數(shù)功能 : 檢測(cè)有按鍵按下并讀取鍵值
- * 輸 入 : 無(wú)
- * 輸 出 : 無(wú)
- *******************************************************************************/
- void KeyDown(void)
- {
- char a;
- GPIO_KEY=0x0f;
- if(GPIO_KEY!=0x0f)
- {
- Delay10ms();
- if(GPIO_KEY!=0x0f)
- {
- KeyState=1;
- //測(cè)試列
- GPIO_KEY=0X0F;
- // Delay10ms();
- switch(GPIO_KEY)
- {
- case(0X07): KeyValue=0;break;
- case(0X0b): KeyValue=1;break;
- case(0X0d): KeyValue=2;break;
- case(0X0e): KeyValue=3;break;
- // default: KeyValue=17; //檢測(cè)出錯(cuò)回復(fù)17意思是把數(shù)碼管全滅掉。
- }
- //測(cè)試行
- GPIO_KEY=0XF0;
- Delay10ms();
- switch(GPIO_KEY)
- {
- case(0X70): KeyValue=KeyValue;break;
- case(0Xb0): KeyValue=KeyValue+4;break;
- case(0Xd0): KeyValue=KeyValue+8;break;
- case(0Xe0): KeyValue=KeyValue+12;break;
- // default: KeyValue=17;
- }
- while((a<50)&&(GPIO_KEY!=0xf0)) //檢測(cè)按鍵松手檢測(cè)
- {
- Delay10ms();
- a++;
- }
- a=0;
- }
- }
- }
- ……………………
- …………限于本文篇幅 余下代碼請(qǐng)從51黑下載附件…………
復(fù)制代碼
所有資料51hei提供下載:
LCD1602顯示矩陣按鍵鍵值.zip
(11.73 KB, 下載次數(shù): 92)
2018-4-15 21:33 上傳
點(diǎn)擊文件名下載附件
基于51單片機(jī)的LCD1602顯示 下載積分: 黑幣 -5
|
評(píng)分
-
查看全部評(píng)分
|