forked from qiaosiyi/key-board
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
109 lines (94 loc) · 1.93 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include "sys.h"
#include "delay.h"
#include "led.h"
#include "key.h"
#include "wakeup.h"
#include "adc.h"
#include "wkup.h"
#include "usart.h"
#include "usart3.h"
#define OPENBLT 1
u8 KeyDown(void)
{
if(COL0 | COL1 | COL2 | COL3 | COL4 | COL5 | COL6 | COL7 )//判断是否有键按下
{
// u3_printf("KeyDown.\r\n");
return 1;//keydown
}
else {
return 0;
}
}
void ScanKeyBoard(void){
if(KeyDown())
{
delay_ms(10);
if(KeyDown())
{
u3_printf("KeyDown.\r\n");
send_key();
//u3_printf("\r\n\r\n");
}
else
{
// u3_printf("nothing\r\n");
}
}
}
int main(void){
u8 key=0;
u32 waittime=0;
u16 adcx=0;
u32 times=0;
u8 keymap_pre[128];
u8 keymap_now[128];
u8 * resault;
u8 byte[7] = {0,0,0,0,0,0,0};
float temp=0.0;
delay_init();
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
uart_init(9600);
usart3_init(115200);
LED_Init();
WKUP_Init();
WAKEUP_BLT_Init();
KEY_Init();
Adc_Init();
//low_power();
LED0=1;
if(OPENBLT){
WAKEUP=1;//蓝牙开启
}else{
WAKEUP=0;//不开启蓝牙
}
setrow0_0();
setrow16_1();
while(1){
if(KeyDown() && WAKEUP == 1){
waittime = 0;//将等待时间清零
}else if(KeyDown() && WAKEUP == 0){//如果有按键按下,而且蓝牙待机
waittime = 0;//将等待时间清零
if(OPENBLT){
WAKEUP=1;//蓝牙开启
}else{
WAKEUP=0;//不开启蓝牙
}
delay_ms(20);//等待蓝牙启动成功
}else if(!KeyDown()){//如果没有按键被按下,等待时间加1个单位,1个单位按10ms计算
if(WAKEUP==1){//如果蓝牙开机,才开始算等待时间
waittime++;
}
}
if(waittime%100==1){
u3_printf("runing..\r\n");
u3_printf("t=%d\r\n",waittime);
}
if(waittime>=60000){//X10ms进入休眠,如果进入休眠比蓝牙待机时间早,则蓝牙同时也会被待机
u3_printf("Enter standby..\r\n");
Sys_Enter_Standby();
}
send_key();
delay_ms(10);
//u3_printf("times:%d\r\n", times);
}
}