?? scankey.c
字號:
#include <REG52.H>
void delay_ms(unsigned int ms);
unsigned char ScanKey(void)
{
unsigned char uc_Temp_1,uc_Temp_2,key;
P1=0xff; //P1口置高電平,準備輸入
P1=0x0f; //P1口高4位作為輸出,輸出0,低四位作為輸入
if((P1&0x0f) != 0x0f) //如果按鍵有反應
{
delay_ms(5); //延時去抖
P1=0x0f;
if((P1&0x0f) != 0x0f) //如果為真,則確實有按鍵按下
{
uc_Temp_1=P1; //把這時P1口狀態保存在一個變量中
P1=0xf0; //把P1口高四位置輸入,低四位作為輸出,注意:這就是'線翻轉' (即輸入輸出翻轉)的本質所在
uc_Temp_2=P1; //把這時P1口狀態保存在一個變量中
key=(uc_Temp_1|uc_Temp_2);
while(P1!=0xf0);
switch (key)
{
case 0xE7: return (0);
case 0xEE: return (1);
case 0xDE: return (2);
case 0xBE: return (3);
case 0xED: return (4);
case 0xDD: return (5);
case 0xBD: return (6);
case 0xEB: return (7);
case 0xDB: return (8);
case 0xBB: return (9);
default: return key;
}
}
}
return (0xff);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -