#include "hwCtrl.h" #include "r_cg_port.h" #include "iodefine.h" #include "PINdef.h" #include "r_cg_adc.h" static uint8_t keystate[KEY_NUM] = {0}; static uint8_t keyPressFlag[KEY_NUM] = {0}; static uint8_t keyReleaseFlag[KEY_NUM] = {0}; static uint16_t keydelay[KEY_NUM] = {0}; uint16_t g_adval[12]; #define KEY_DELAY_TIMES 20 //20Ms #define KEY_LONG_TIMES 500 //500Ms void ClearKeyState(void) { uint8_t i; for (i = 0; i < KEY_NUM; i++) { keystate[i] = 0; keyPressFlag[i] = 0; keyReleaseFlag[i] = 0; } } void setKeyPressFlag(uint8_t id) { id--; if (id < KEY_NUM) { keyPressFlag[id] = KEY_PRESSED; } } void setKeyReleaseFlag(uint8_t id) { id--; if (id < KEY_NUM) { keyReleaseFlag[id] = KEY_PRESSED; } } uint8_t getKeyPressFlag(uint8_t id) { uint8_t retVal = KEY_NOPRESSED; id--; if (id < KEY_NUM) { retVal = keyPressFlag[id]; keyPressFlag[id] = KEY_NOPRESSED; } return retVal; } uint8_t getKeyReleaseFlag(uint8_t id) { uint8_t retVal = KEY_NOPRESSED; id--; if (id < KEY_NUM) { retVal = keyReleaseFlag[id]; keyReleaseFlag[id] = KEY_NOPRESSED; } return retVal; } void KeyScan(void)//1ms { uint8_t i,key; for (i = 0; i < KEY_NUM; i++) { key = GetIOState(i+1); if (key == KEY_PRESSED) { keydelay[i]++; if (keydelay[i] >= KEY_DELAY_TIMES) { keystate[i] = KEY_PRESSED; } } else if(key == KEY_NOPRESSED) { if(keydelay[i] > 5)keydelay[i] = 5; if (keydelay[i] > 0) { keydelay[i]--; } else { keystate[i] = KEY_NOPRESSED; } } } } uint8_t GetIOState(uint8_t keyno) { switch (keyno) { //KEY case KEYID_LB : return KEY_LB==0?1:0; case KEYID_ZZ : return KEY_ZZ==0?1:0; case KEYID_YZ : return KEY_YZ==0?1:0; case KEYID_ZXFW: return KEY_ZXFW==0?1:0; case KEYID_JS : return KEY_JS==0?1:0; case KEYID_YJ : return KEY_YJ==0?1:0; case KEYID_CC : return KEY_CC==0?1:0; case KEYID_DD : return KEY_DD==0?1:0; case KEYID_DFS : return KEY_DFS==0?1:0; case KEYID_DFJ : return KEY_DFJ==0?1:0; case KEYID_MS : return KEY_MS==0?1:0; case KEYID_YBFH: return KEY_YBFH==0?1:0; case KEYID_YBS : return KEY_YBS==0?1:0; case KEYID_YBX : return KEY_YBX==0?1:0; case KEYID_QD : return KEY_QD==0?1:0; case KEYID_XH : return KEY_XH==0?1:0; case KEYID_WBJR: return KEY_WBJR==0?1:0; case KEYID_ZYJR: return KEY_ZYJR==0?1:0; case KEYID_YD : return KEY_YD==0?1:0; case KEYID_TCS : return KEY_TCS==0?1:0; default: return 0; } } uint8_t GetKeyState(uint8_t keyno) { if (keyno > 0 && keyno <= KEY_NUM) { return keystate[keyno-1]; } return KEY_NOPRESSED; } uint16_t getAdval(uint8_t ch) { if (ch < 1) { return g_adval[ch]; } return 0; } void ad_handle(void) { //uint8_t adch=0; //adch = ADS - 2; R_ADC_Get_Result(&g_adval[0]);//adch /* adch++; if (adch > 6) { adch = 0; } ADS = adch + 2; */ } /*****************diagnostic******************/