From c15e017ccfe24532e132536a60035233ba0e3802 Mon Sep 17 00:00:00 2001 From: "mr.zhangsan" Date: Mon, 22 Apr 2024 20:39:26 +0800 Subject: [PATCH] =?UTF-8?q?=E9=AB=98=E9=98=BB=E8=BE=93=E5=85=A5=E8=AF=BB?= =?UTF-8?q?=E5=8F=96=E6=8C=89=E9=94=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/.vscode/settings.json | 4 +- source/app/main.c | 16 +++- source/app/main.h | 1 + source/bsp/bsp_config_delay.c | 9 +- source/bsp/bsp_key.c | 155 ++++++++++++++++++++++++++++++++++ source/bsp/bsp_key.h | 11 +++ 6 files changed, 188 insertions(+), 8 deletions(-) create mode 100644 source/bsp/bsp_key.c create mode 100644 source/bsp/bsp_key.h diff --git a/source/.vscode/settings.json b/source/.vscode/settings.json index 9d58645..42f38f6 100644 --- a/source/.vscode/settings.json +++ b/source/.vscode/settings.json @@ -4,6 +4,8 @@ "bsp_config.h": "c", "stc_macro.h": "c", "type.h": "c", - "main.h": "c" + "main.h": "c", + "bsp_config_delay.h": "c", + "bsp_key.h": "c" } } \ No newline at end of file diff --git a/source/app/main.c b/source/app/main.c index 3a9171f..6d2a251 100644 --- a/source/app/main.c +++ b/source/app/main.c @@ -83,6 +83,7 @@ void L0_main_init(void) { //Lc_delay_ms(200); L0_board_config(); + bsp_key_init(); L0_uart0_buf_init();//串口初始化 EA = 1; //Lc_delay_ms(100); @@ -119,21 +120,30 @@ void main(void) delayInMs(500); } #endif - + U8 key = 0; //初始化 L0_main_init(); //验证加密信息 //L3_encrypt_handler(); //主循环 + // L0_board_config(); + // bsp_key_init(); while(1) { if(1 == s_nos_tick.t1s_heatbeart) { s_nos_tick.t1s_heatbeart = 0; LED0 ^= 1; - // L0_uart0_uc('.'); + // KR1 ^= 1; + // KC1 ^= 1; + L0_uart0_uc('.'); // L0_uart0_sendArray("v2.7",4); - L0_uartN_sendstr(0,"v2.8111"); + // L0_uartN_sendstr(0,"v2.8111"); + } + + key = bsp_key_scan(); + if(key != BSP_KEY_NUM_MAX){ + L0_uart0_uchex(key); } //L1_ADS1213_main(); diff --git a/source/app/main.h b/source/app/main.h index fc8742d..7d7fc02 100644 --- a/source/app/main.h +++ b/source/app/main.h @@ -42,6 +42,7 @@ #include "../bsp/bsp_config.h" #include "../bsp/bsp_config_delay.h" +#include "../bsp/bsp_key.h" #include "../bsp/chipid.h" #include "../bsp/cs1232.h" #include "../bsp/rs485.h" diff --git a/source/bsp/bsp_config_delay.c b/source/bsp/bsp_config_delay.c index 1f7ca2c..64a11a3 100644 --- a/source/bsp/bsp_config_delay.c +++ b/source/bsp/bsp_config_delay.c @@ -1,9 +1,10 @@ #include "bsp_config_delay.h" -#if (TYPE_MCU == TYPE_MCU_STC_8H - || TYPE_MCU == TYPE_MCU_STC_8G - || TYPE_MCU == TYPE_MCU_STC_8A - || TYPE_MCU == TYPE_MCU_STC_8F) +#if ((TYPE_MCU == TYPE_MCU_STC_8H) \ + || (TYPE_MCU == TYPE_MCU_STC_8G) \ + || (TYPE_MCU == TYPE_MCU_STC_8A) \ + || (TYPE_MCU == TYPE_MCU_STC_8F)) \ + #if (D_sys_MainFre == MainFre_22M) void Delay100us() //@22.1184MHz diff --git a/source/bsp/bsp_key.c b/source/bsp/bsp_key.c new file mode 100644 index 0000000..9f7e8a7 --- /dev/null +++ b/source/bsp/bsp_key.c @@ -0,0 +1,155 @@ +#include "bsp_key.h" +#include "bsp_config_delay.h" + +U8 bsp_key_init(void) +{ + D_stdIO_P3(BITN6); + D_stdIO_P1(BITN7); + D_stdIO_P0(BITN6); + D_stdIO_P4(BITN3); + D_HighR_P1(BITN0); + D_HighR_P0(BITN7); + D_HighR_P1(BITN3); + D_HighR_P2(BITN0); + + KR1 = KR2 = KR3 = KR4 = 1; + KC1 = KC2 = KC3 = KC4 = 1; + + return 0; +} + +void scan_row(U8 r) +{ + KR1 = 0; + KR2 = 0; + KR3 = 0; + KR4 = 0; + switch(r){ + case 1: + KR1 = 1;break; + case 2: + KR2 = 1;break; + case 3: + KR3 = 1;break; + case 4: + KR4 = 1;break; + default: + break; + } +} + +U8 scan_col(U8 c) +{ + if(c == 1) + { + if(KC1 == 1) + { + delayInMs(10); + if(KC1 == 1) + { + while(KC1 == 1); + return 1; + } + } + } + else if(c == 2){ + if(KC2 == 1) + { + delayInMs(10); + if(KC2 == 1) + { + while(KC2 == 1); + return 1; + } + } + } + else if(c == 3){ + if(KC3 == 1) + { + delayInMs(10); + if(KC3 == 1) + { + while(KC3 == 1); + return 1; + } + } + } + else if(c == 4){ + if(KC4 == 1) + { + delayInMs(10); + if(KC4 == 1) + { + while(KC4 == 1); + return 1; + } + } + } + return 0; +} + +U8 bsp_key_scan(void) +{ + U8 key = BSP_KEY_NUM_MAX; + //扫描第1行 + scan_row(1); + if(scan_col(1) > 0){ + return 0; + } + if(scan_col(2) > 0){ + return 1; + } + if(scan_col(3) > 0){ + return 2; + } + if(scan_col(4) > 0){ + return 3; + } + + // //扫描第2行 + // scan_row(2); + // if(scan_col(1) > 0){ + // key = 4; + // } + // if(scan_col(2) > 0){ + // key = 5; + // } + // if(scan_col(3) > 0){ + // key = 6; + // } + // if(scan_col(4) > 0){ + // key = 7; + // } + + // //扫描第3行 + // scan_row(3); + // if(scan_col(1) > 0){ + // key = 8; + // } + // if(scan_col(2) > 0){ + // key = 9; + // } + // if(scan_col(3) > 0){ + // key = 10; + // } + // if(scan_col(4) > 0){ + // key = 11; + // } + + // //扫描第4行 + // scan_row(4); + // if(scan_col(1) > 0){ + // key = 12; + // } + // if(scan_col(2) > 0){ + // key = 13; + // } + // if(scan_col(KC3) > 0){ + // key = 14; + // } + // if(scan_col(KC4) > 0){ + // key = 15; + // } + + return key; +} \ No newline at end of file diff --git a/source/bsp/bsp_key.h b/source/bsp/bsp_key.h new file mode 100644 index 0000000..c3d0f6b --- /dev/null +++ b/source/bsp/bsp_key.h @@ -0,0 +1,11 @@ +#ifndef _BSP_KEY_H +#define _BSP_KEY_H + +#include "bsp_config.h" + +#define BSP_KEY_NUM_MAX 99 + +extern U8 bsp_key_init(void); +extern U8 bsp_key_scan(void); + +#endif \ No newline at end of file