#include "global.h"
#include "key.h"
#include "menu.h"
char key;
unsigned char nkey;
char keycol;
char keyrow;
char keytimer;
char flagkeydown;
char flagkeyvalid;
char flagkeyunprocessed; //当前按键有Flag
unsigned char keyline[] = {0xFE, 0xFD, 0xFB, 0xF7, 0xEF};
#define keyscanline P2OUT
#define keyNotPressed() (P2IN & 0xe0) == 0xE0
#define getkeycol() (P2IN & 0xe0)
void InitKey(){ //按键处理初期化
P2SEL = 0x00;
P2DIR = 0x1F;
P2OUT = 0xFF;
P2REN = 0x00; //拉功能禁止
P2DS = 0x00;
P2IE = 0x00; //中断禁止
keytimer = 0;
}
unsigned char keyscan(){
unsigned char keytemp = 0xFF;
if(keyNotPressed()){
keytimer ++;
if(keytimer > 4)
keytimer = 0;
keyscanline = keyline[keytimer];
return 0xFF;
}
switch(getkeycol()){
case 0x60:
keytemp = 2;
break;
case 0xA0:
keytemp = 1;
break;
case 0xC0:
keytemp = 0;
break;
}
keytemp += keytimer * 3;
switch(keytemp){
case 0:
return KEY_1; //
case 1:
return KEY_4; //
case 2:
return KEY_7; //
case 3:
return KEY_2; //
case 4:
return KEY_5; //
case 5:
return KEY_8; //
case 6:
return KEY_3; //
case 7:
return KEY_6; //
case 8:
return KEY_9; //
case 9:
return KEY_UP; //
case 10:
return KEY_0; //
case 11:
return KEY_DOWN; //
case 12:
return KEY_BACK; //
case 13:
return KEY_CLEAR; //
case 14:
return KEY_OK; //
default:
break;
}
return 0xFF; //return 0xFF有什么用?
}
void Get_key(){ //获得键值
unsigned char keytemp;
keytemp = keyscan();
if(keytemp >= 0x0F){ //如果当前键值在0x0F以上
nkey = 0xFF; //前回键值
flagkeydown = 0;
flagkeyvalid = 0;
flagkeyunprocessed = 0; //当前按键有Flag CLR
return;
}
if(keytemp != nkey){
flagkeydown = 1;
nkey = keytemp;
return;
}
if(flagkeyvalid == 0){
key = nkey;
if(key != KEY_BACK){
back_menuflag = 0;
}
flagkeyvalid = 1;
flagkeyunprocessed = 1; //当前按键有Flag SET
}
}
连接图是这样的。完全看不懂程序到底什么意思。这应该属于独立按键吧,是用来模拟成3*4的矩形按键码?
|