12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- #include "GPIO_KEY.h"
- #include "app_def.h"
- #include "bsp.h"
- signed char KEY[1]={-1}; //-1表示未按下,0表示按住,1表示短按,2表示长按
- static U08 s_u8keyCnt =0;
- extern unsigned int LocalTime;
- static VU16 s_vu16KeyTaskTmr = {0};
- int GPIO_KEY_init(void)
- {
-
- GPIO_InitTypeDef GPIO_InitStructure;
- //打开相应GPIO口的时钟
- KEY0_RccOpen();
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
- GPIO_InitStructure.GPIO_Pin = KEY0_LINE;
- GPIO_Init(KEY0_Port,&GPIO_InitStructure);
-
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
- GPIO_Init(GPIOC,&GPIO_InitStructure);
-
- KEY[0]=-1;
-
- return 1;
- }
- void KeyTaskTmr(void)
- {
- if(s_vu16KeyTaskTmr!=0xffff) s_vu16KeyTaskTmr++;
-
- }
- void GPIO_KEY_Tick(void)
- {
- BOOL port = FALSE;
- port = GPIO_ReadInputDataBit(KEY0_Port,KEY0_LINE);
- if (port) { //no press
- s_u8keyCnt ++;
- if (s_u8keyCnt > 200) {
- s_u8keyCnt =0;
- KEY[0]= -1;
- s_vu16KeyTaskTmr =0;
- }
- } else {
- s_u8keyCnt =0;
- if (s_vu16KeyTaskTmr > OS_TIMER_100MS) {
- if ( KEY[0] != 0x01) {
- SYS_Reset();
- Mcu_Reset(1);
- }
- KEY[0]= 1 ;
-
- }
- }
-
- }
|