更新底层

This commit is contained in:
sunbeam 2024-05-25 16:57:28 +08:00
parent d63083247c
commit ddb91811b2
4 changed files with 283 additions and 69 deletions

View File

@ -772,7 +772,7 @@ void CurrentDetecte(void)
current2 = getAdval(ADCH_RLY2); current2 = getAdval(ADCH_RLY2);
if (current1 > 100U && OC1flag == 0) if (current1 > 80U && OC1flag == 0)
{ {
OC_Count1++; OC_Count1++;
if (OC_Count1 >= 100) if (OC_Count1 >= 100)
@ -786,7 +786,7 @@ void CurrentDetecte(void)
OC_Count1 = 0; OC_Count1 = 0;
} }
if (current2 > 100U && OC2flag == 0) if (current2 > 80U && OC2flag == 0)
{ {
OC_Count2++; OC_Count2++;
if (OC_Count2 >= 100) if (OC_Count2 >= 100)
@ -818,7 +818,7 @@ void HallDetecte(void)
uint8_t i,hallstate; uint8_t i,hallstate;
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
{ {
hallstate = GetIOState(SIGID_HALL1 + i); hallstate = GetSigState(SIGID_HALL_KB + i);
if (hallstate != HallLastState[i]) if (hallstate != HallLastState[i])
{ {
HallDelay[i]++; HallDelay[i]++;

View File

@ -4,30 +4,60 @@
#include "iodefine.h" #include "iodefine.h"
typedef enum
{
IOID_P120 = 1,
IOID_P41,
IOID_P40,
IOID_RESET,
IOID_P124,
IOID_P123,
IOID_P137,
IOID_P122,
IOID_P121,
IOID_REGC,
IOID_VSS,
IOID_VDD,
IOID_P60,
IOID_P61,
IOID_P62,
IOID_P63,
IOID_P00,
IOID_P140,
IOID_P130,
IOID_P73,
IOID_P72,
IOID_P71,
IOID_P70,
IOID_P32,
IOID_P30,
IOID_P17,
IOID_P16,
IOID_P15,
IOID_P31,
IOID_P14,
IOID_P13,
IOID_P12,
IOID_P11,
IOID_P10,
IOID_P33,
IOID_P34,
IOID_P80,
IOID_P81,
IOID_P82,
IOID_P83,
IOID_P84,
IOID_P85,
IOID_P86,
IOID_P87,
IOID_P90,
IOID_P91,
IOID_P92,
IOID_P125,
}IOID_type;
#define KEYID_KBXQ 0
#define KEYID_KBXH 1
#define KEYID_HGXQ 2
#define KEYID_HGXH 3
#define KEYID_ZDUP 4
#define KEYID_ZDDOWN 5
#define KEYID_TTUP 6
#define KEYID_TTDOWN 7
#define KEYID_TP 8
#define KEYID_FW 9
#define KEYID_SET 10
#define KEYID_M1 11
#define KEYID_M2 12
#define KEYID_M3 13
#define SIGID_HALL1 14
#define SIGID_HALL2 15
#define SIGID_HALL3 16
#define SIGID_HALL4 17
#define IN_HALL1 P6_bit.no0 #define IN_HALL1 P6_bit.no0
#define IN_HALL2 P6_bit.no1 #define IN_HALL2 P6_bit.no1

View File

@ -57,13 +57,13 @@ uint8_t getKeyReleaseFlag(uint8_t id)
extern unsigned char keybyte1,keybyte2,keybyte3; extern unsigned char keybyte1,keybyte2,keybyte3;
void KeyScan(void) void KeyScan(void)//1ms
{ {
uint8_t i,key,key_nopress; uint8_t i,key,key_nopress;
key_nopress = 0; key_nopress = 0;
for (i = 0; i < KEY_NUM; i++) for (i = 0; i < KEY_NUM; i++)
{ {
key = GetIOState(i); key = GetSigState(i);
if (key == KEY_PRESSED && keystate[i] == KEY_NOPRESSED) if (key == KEY_PRESSED && keystate[i] == KEY_NOPRESSED)
{ {
keydelay[i]++; keydelay[i]++;
@ -94,51 +94,47 @@ void KeyScan(void)
} }
uint8_t GetIOState(uint8_t keyno) uint8_t GetSigState(uint8_t keyno)
{ {
uint16_t keyad; uint16_t keyad;
switch (keyno) switch (keyno)
{ {
case KEYID_KBXQ: case SIGID_KEY_KB_F:
return IN_KEY_KBXQ; return (getIOstate(IOID_P92)==0)?1:0;
case KEYID_KBXH: case SIGID_KEY_KB_R:
return IN_KEY_KBXH; return (getIOstate(IOID_P82)==0)?1:0;
case KEYID_HGXQ: case SIGID_KEY_HG_F:
return IN_KEY_HGXQ; return (getIOstate(IOID_P91)==0)?1:0;
case KEYID_HGXH: case SIGID_KEY_HG_R:
return IN_KEY_HGXH; return (getIOstate(IOID_P83)==0)?1:0;
case KEYID_ZDUP: case SIGID_KEY_ZD_UP:
return IN_KEY_ZDUP; return (getIOstate(IOID_P87)==0)?1:0;
case KEYID_ZDDOWN: case SIGID_KEY_ZD_DOWN:
return IN_KEY_ZDDOWN; return (getIOstate(IOID_P84)==0)?1:0;
case KEYID_TTUP: case SIGID_KEY_TT_UP:
return IN_KEY_TTUP; return (getIOstate(IOID_P86)==0)?1:0;
case KEYID_TTDOWN: case SIGID_KEY_TT_DOWN:
return IN_KEY_TTDOWN; return (getIOstate(IOID_P85)==0)?1:0;
case KEYID_TP: case SIGID_KEY_FW:
return IN_KEY_TP; return (getIOstate(IOID_P120)==0)?1:0;
case KEYID_FW: case SIGID_KEY_TP:
return IN_KEY_FW; return (getIOstate(IOID_P125)==0)?1:0;
case KEYID_SET: case SIGID_KEY_JY_SET
keyad = getAdval(ADCH_JYKEY); return (getAdval(ADCH_JYKEY)<=100)?1:0;
return keyad<20?1:0; case SIGID_KEY_JY_1:
case KEYID_M1: return (getAdval(ADCH_JYKEY)<=300&&getAdval(ADCH_JYKEY)>=200)?1:0;//246
keyad = getAdval(ADCH_JYKEY); case SIGID_KEY_JY_2:
return (keyad>200 && keyad<250)?1:0; return (getAdval(ADCH_JYKEY)<=560&&getAdval(ADCH_JYKEY)>=460)?1:0;//512
case KEYID_M2: case SIGID_KEY_JY_3:
keyad = getAdval(ADCH_JYKEY); return (getAdval(ADCH_JYKEY)<=820&&getAdval(ADCH_JYKEY)>=720)?1:0;//771
return (keyad>450 && keyad<550)?1:0; case SIGID_HALL_KB:
case KEYID_M3: return getIOstate(IOID_P60);
keyad = getAdval(ADCH_JYKEY); case SIGID_HALL_HG:
return (keyad>700 && keyad<800)?1:0; return getIOstate(IOID_P61);
case SIGID_HALL1: case SIGID_HALL_ZD:
return IN_HALL1; return getIOstate(IOID_P62);
case SIGID_HALL2: case SIGID_HALL_TT:
return IN_HALL2; return getIOstate(IOID_P63);
case SIGID_HALL3:
return IN_HALL3;
case SIGID_HALL4:
return IN_HALL4;
default: default:
return 0; return 0;
} }
@ -251,3 +247,151 @@ uint16_t getAdval(uint8_t ch)
uint8_t getIOstate(IOID_type ioid)
{
switch (ioid)
{
case IOID_P120:
return P12_bit.no0;
case IOID_P41:
return P4_bit.no1;
case IOID_P40:
return P4_bit.no0;
case IOID_P124:
return P12_bit.no4;
case IOID_P123:
return P12_bit.no3;
case IOID_P137:
return P13_bit.no7;
case IOID_P122:
return P12_bit.no2;
case IOID_P121:
return P12_bit.no1;
case IOID_P60:
return P6_bit.no0;
case IOID_P61:
return P6_bit.no1;
case IOID_P62:
return P6_bit.no2;
case IOID_P63:
return P6_bit.no3;
case IOID_P00:
return P0_bit.no0;
case IOID_P140:
return P14_bit.no0;
case IOID_P130:
return P13_bit.no0;
case IOID_P73:
return P7_bit.no3;
case IOID_P72:
return P7_bit.no2;
case IOID_P71:
return P7_bit.no1;
case IOID_P70:
return P7_bit.no0;
case IOID_P32:
return P3_bit.no2;
case IOID_P30:
return P3_bit.no0;
case IOID_P17:
return P1_bit.no7;
case IOID_P16:
return P1_bit.no6;
case IOID_P15:
return P1_bit.no5;
case IOID_P31:
return P3_bit.no1;
case IOID_P14:
return P1_bit.no4;
case IOID_P13:
return P1_bit.no3;
case IOID_P12:
return P1_bit.no2;
case IOID_P11:
return P1_bit.no1;
case IOID_P10:
return P1_bit.no0;
case IOID_P33:
return P3_bit.no3;
case IOID_P34:
return P3_bit.no4;
case IOID_P80:
return P8_bit.no0;
case IOID_P81:
return P8_bit.no1;
case IOID_P82:
return P8_bit.no2;
case IOID_P83:
return P8_bit.no3;
case IOID_P84:
return P8_bit.no4;
case IOID_P85:
return P8_bit.no5;
case IOID_P86:
return P8_bit.no6;
case IOID_P87:
return P8_bit.no7;
case IOID_P90:
return P9_bit.no0;
case IOID_P91:
return P9_bit.no1;
case IOID_P92:
return P9_bit.no2;
case IOID_P125:
return P12_bit.no5;
case IOID_RESET:
case IOID_REGC:
case IOID_VSS:
case IOID_VDD:
default:
return 0;
}
}

View File

@ -8,8 +8,48 @@
#define KEY_PRESSED 1 #define KEY_PRESSED 1
#define KEY_NOPRESSED 0 #define KEY_NOPRESSED 0
typedef enum
{
KEYID_KB_F,
KEYID_KB_R,
KEYID_HG_F,
KEYID_HG_R,
KEYID_ZD_UP,
KEYID_ZD_DOWN,
KEYID_TT_UP,
KEYID_TT_DOWN,
KEYID_FW,
KEYID_TP,
KEYID_JY_SET,
KEYID_JY_1,
KEYID_JY_2,
KEYID_JY_3,
KEY_NUM,
}KEYID_type;
typedef enum
{
SIGID_KEY_KB_F,
SIGID_KEY_KB_R,
SIGID_KEY_HG_F,
SIGID_KEY_HG_R,
SIGID_KEY_ZD_UP,
SIGID_KEY_ZD_DOWN,
SIGID_KEY_TT_UP,
SIGID_KEY_TT_DOWN,
SIGID_KEY_FW,
SIGID_KEY_TP,
SIGID_KEY_JY_SET,
SIGID_KEY_JY_1,
SIGID_KEY_JY_2,
SIGID_KEY_JY_3,
SIGID_HALL_KB,
SIGID_HALL_HG,
SIGID_HALL_ZD,
SIGID_HALL_TT,
SIG_NUM,
}SIGID_type;
#define KEY_NUM 14
#define ACT_NOACT 0 #define ACT_NOACT 0
#define ACT_XQ 1 #define ACT_XQ 1
@ -24,7 +64,7 @@ void ClearKeyState(void);
uint8_t GetKeyState(uint8_t keyno); uint8_t GetKeyState(uint8_t keyno);
uint8_t getKeyReleaseFlag(uint8_t id); uint8_t getKeyReleaseFlag(uint8_t id);
uint8_t getKeyPressFlag(uint8_t id); uint8_t getKeyPressFlag(uint8_t id);
uint8_t GetIOState(uint8_t keyno); uint8_t GetSigState(uint8_t keyno);