📄 key_ht_isr.c
字号:
/*
*********************************************************************************************************
* Embedded Systems Building Blocks
* Filename : KEY_HT_ISR.C
* Programmer : LuHaijun
*
* This program can not use alone,it must copy to main file
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#include "INCLUDES.H"
//sbit ZLG7289_pinINT=P1^6; //键盘中断请求信号,低电屏(负边沿)有效
/*
*********************************************************************************************************
* GLOBAL VARIABLES
*********************************************************************************************************
*/
extern INT8U KeyBuf[KEY_BUF_SIZE]; /* Keyboard buffer */
extern INT8U KeyBufInIx; /* Index into key buf where next scan code will be inserted*/
extern INT8U KeyBufOutIx; /* Index into key buf where next scan code will be removed */
extern INT8U KeyDownTmr; /* Counts how long key has been pressed */
extern INT8U KeyNRead; /* Number of keys read from the keyboard */
extern INT8U KeyScanState; /* Current state of key scanning function */
extern INT8U KeyRptStartDlyCtr; //累加延时时间
extern INT8U KeyRptDlyCtr;
extern INT8U ccode;
/*
*********************************************************************************************************
* LOCAL FUNCTION PROTOTYPES
*********************************************************************************************************
*/
#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
extern OS_CPU_SR cpu_sr;
#endif
void KeyScanISR () //按键扫描函数
{
switch (KeyScanState) {
case KEY_STATE_UP: /* See if need to look for a key pressed */
if(ZLG7289_pinINT==0){ //判断按键是否按下
KeyScanState = KEY_STATE_DEBOUNCE; /* Next call we will have debounced the key */
}
break;
case KEY_STATE_DEBOUNCE: /* Key pressed, get scan code and buffer */
if (ZLG7289_pinINT==0) { //看按键是否仍在压下状态
ccode =ZLG7289_Key(); //读出按键值
if (KeyNRead < KEY_BUF_SIZE) { //如果按键缓冲区没满
KeyNRead++;
KeyBuf[KeyBufInIx++] = ccode;
if (KeyBufInIx >= KEY_BUF_SIZE) { //如果指针到头则返回
KeyBufInIx = 0;
}
} /* Input scan code in buffer */
KeyRptStartDlyCtr = KEY_RPT_START_DLY; //启动累加延时
KeyScanState = KEY_STATE_RPT_START_DLY;
} else {
//KeySelRow(KEY_ALL_ROWS); /* Select all row */
KeyScanState = KEY_STATE_UP; //返回到按键检测状态
}
break;
case KEY_STATE_RPT_START_DLY:
if (ZLG7289_pinINT==0) { //如果按键仍被按下
if (KeyRptStartDlyCtr > 0) { //延时时间递减
KeyRptStartDlyCtr--; /* Yes, decrement counter to start of rpt */
if (KeyRptStartDlyCtr == 0) { //如果延时时间减到0
ccode =ZLG7289_Key(); //读出按键值
if (KeyNRead < KEY_BUF_SIZE) {
KeyNRead++;
KeyBuf[KeyBufInIx++] = ccode;
if (KeyBufInIx >= KEY_BUF_SIZE) {
KeyBufInIx = 0;
}
} /* Input scan code in buffer */
KeyRptDlyCtr = KEY_RPT_DLY; //置处理每个按键的间隔时间
KeyScanState = KEY_STATE_RPT_DLY; //进入连续处理状态
}
}
} else {
KeyScanState = KEY_STATE_DEBOUNCE; //跳回判断按键是否还被压下状态
}
break;
case KEY_STATE_RPT_DLY:
if (ZLG7289_pinINT==0) { //判断按键是否仍然被按下
if (KeyRptDlyCtr > 0) { //按键延时处理
KeyRptDlyCtr--; /* Yes, dec. wait time to next key repeat */
if (KeyRptDlyCtr == 0) { /* See if it's time to repeat key */
ccode =ZLG7289_Key(); //读出按键值
if (KeyNRead < KEY_BUF_SIZE) { //判断缓冲区是否满
KeyNRead++;
KeyBuf[KeyBufInIx++] = ccode;
if (KeyBufInIx >= KEY_BUF_SIZE) {
KeyBufInIx = 0;
}
} /* Input scan code in buffer */
KeyRptDlyCtr = KEY_RPT_DLY; //重新付值按键延时时间
}
}
} else {
KeyScanState = KEY_STATE_DEBOUNCE; //跳回判断按键是否还被压下状态
}
break;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -