uchar keystr[] = {1, 1, 1, 1}, backup[] = {1, 1, 1, 1};
void KeyScan() { //键盘扫描
static uchar keybuf[4] = {0XFF, 0XFF, 0XFF, 0XFF};
uchar i;
keybuf[0] = (keybuf[0] << 1) | KEY1;
keybuf[1] = (keybuf[1] << 1) | KEY2;
keybuf[2] = (keybuf[2] << 1) | KEY3;
keybuf[3] = (keybuf[3] << 1) | KEY4;
for (i = 0; i < 4; i++) {
if (keybuf[i] == 0X00)
keystr[i] = 0;
else if (keybuf[i] == 0XFF)
keystr[i] = 1;
}
}
void KeyDriver() { //键盘驱动
uchar i;
for (i = 0; i < 4; i++) {
if (keystr[i] != backup[i]) {
if (keystr[i] == 0)
KeyAction(i);//这里适当修改程序可以实现组合按键的效果
}
backup[i] = keystr[i];
}
}
|