📄 keyproc.c
字号:
#include "chip.h"
#include "pcf8574.h"
#include "i2c.h"
#include "key.h"
const unsigned char KEY_ROW[]={KEY_ROW1,KEY_ROW2,KEY_ROW3}; //scan status code
const unsigned char KEY_VALUE[][2]={
{0xD8,'1'},{0xD4,'2'},{0xCC,'3'},
{0xB8,'4'},{0xB4,'5'},{0xAC,'6'},
{0x78,'7'},{0x74,'8'},{0x6C,'9'}};
void InitKeyPort(void)
{
P1SEL &=~BIT4; //P1.4 input direction
P1DIR &=~BIT4;
P1IES |=BIT4; //P1.4 falling edge interrupt
P1IE |=BIT4; //enable P1.4 interrupt(external interrupt 4)
}
void KeyDebounce(unsigned int i)
{
while(i--);
}
unsigned char KeyProcess(void)
{
unsigned char Key,i,keycnt;
for(i=0;i<3;i++)
{
I2CWrByte(I2CWR_ADDR,KEY_ROW[i]); //writting row code to identify the location pressed key
I2CRdByte(I2CRD_ADDR,&Key); //read into the location code in row
KeyDebounce(KEY_DEBOUNCE_TIME>>1); //debounce
if((Key & NO_KEY)!=NO_KEY) //key has pressed
{
KeyDebounce(KEY_DEBOUNCE_TIME); //debounce
I2CRdByte(I2CRD_ADDR,&Key); //read into the location code in row
if((Key & NO_KEY)!=NO_KEY) //if has key
{
Key &=MASK_LED;
for(keycnt=0;keycnt<9;keycnt++) //conversion scan value to character
{
if(Key==KEY_VALUE[keycnt][0]){ Key=KEY_VALUE[keycnt][1];keycnt=10;} //lookup tabe
}
I2CWrByte(I2CWR_ADDR,KEY_INIT_LED1 );//restoration key status and LED dead
return Key; //return key value
}
else //no key
{
I2CWrByte(I2CWR_ADDR,KEY_INIT_LED1); //restoration key status and LED lighting
return NO_KEY; //return null value of key
}
}
}
I2CWrByte(I2CWR_ADDR,KEY_INIT_LED1); //restoration key status and LED lighting
return NO_KEY; //return null value of key
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -