|
|
/* |
|
|
* @Author: your name |
|
|
* @Date: 2022-04-17 21:03:46 |
|
|
* @LastEditTime: 2022-04-19 17:45:57 |
|
|
* @LastEditors: lishengyin |
|
|
* @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE |
|
|
* @FilePath: \undefinede:\项目\兼职项目\MotorPid\stm32\HARDWARE\KEY\key.c |
|
|
*/ |
|
|
#include "stm32f10x.h" |
|
|
#include "key.h" |
|
|
#include "sys.h" |
|
|
#include "delay.h" |
|
|
////////////////////////////////////////////////////////////////////////////////// |
|
|
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><EFBFBD>ѧϰʹ<EFBFBD>ã<EFBFBD>δ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>κ<EFBFBD><EFBFBD><EFBFBD>; |
|
|
//ALIENTEK<EFBFBD><EFBFBD>ӢSTM32<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> |
|
|
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> |
|
|
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭ<EFBFBD><EFBFBD>@ALIENTEK |
|
|
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̳:www.openedv.com |
|
|
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:2012/9/3 |
|
|
//<EFBFBD>汾<EFBFBD><EFBFBD>V1.0 |
|
|
//<EFBFBD><EFBFBD>Ȩ<EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ؾ<EFBFBD><EFBFBD><EFBFBD> |
|
|
//Copyright(C) <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿƼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˾ 2009-2019 |
|
|
//All rights reserved |
|
|
////////////////////////////////////////////////////////////////////////////////// |
|
|
|
|
|
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> |
|
|
void KEY_Init(void) //IO<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD> |
|
|
{ |
|
|
GPIO_InitTypeDef GPIO_InitStructure; |
|
|
|
|
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOC,ENABLE);//ʹ<EFBFBD><EFBFBD>PORTA,PORTEʱ<EFBFBD><EFBFBD> |
|
|
|
|
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_13 | GPIO_Pin_12;//KEY0-KEY1 |
|
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //<EFBFBD><EFBFBD><EFBFBD>ó<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> |
|
|
GPIO_Init(GPIOC, &GPIO_InitStructure);//<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>GPIOE4,3 |
|
|
|
|
|
//<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD> WK_UP-->GPIOA.0 <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> |
|
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; |
|
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; //PA0<EFBFBD><EFBFBD><EFBFBD>ó<EFBFBD><EFBFBD><EFBFBD><EFBFBD>룬Ĭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> |
|
|
GPIO_Init(GPIOA, &GPIO_InitStructure);//<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>GPIOA.0 |
|
|
|
|
|
} |
|
|
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> |
|
|
//<EFBFBD><EFBFBD><EFBFBD>ذ<EFBFBD><EFBFBD><EFBFBD>ֵ |
|
|
//mode:0,<EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>;1,֧<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>; |
|
|
//0<EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD>κΰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> |
|
|
//1<EFBFBD><EFBFBD>KEY0<EFBFBD><EFBFBD><EFBFBD><EFBFBD> |
|
|
//2<EFBFBD><EFBFBD>KEY1<EFBFBD><EFBFBD><EFBFBD><EFBFBD> |
|
|
//3<EFBFBD><EFBFBD>KEY3<EFBFBD><EFBFBD><EFBFBD><EFBFBD> WK_UP |
|
|
//ע<EFBFBD><EFBFBD>˺<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD>,KEY0>KEY1>KEY_UP!! |
|
|
u8 KEY_Scan(u8 mode) |
|
|
{ |
|
|
static u8 key_up=1;//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɿ<EFBFBD><EFBFBD><EFBFBD>־ |
|
|
if(mode)key_up=1; //֧<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> |
|
|
if(key_up&&(KEY0==0||KEY1==0 || KEY2==0 ||WK_UP==1)) |
|
|
{ |
|
|
delay_ms(10);//ȥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> |
|
|
key_up=0; |
|
|
if(KEY0==0)return KEY0_PRES; |
|
|
else if(KEY1==0)return KEY1_PRES; |
|
|
else if(WK_UP==1)return WKUP_PRES; |
|
|
else if(KEY2 == 0) return KEY2_PRES; |
|
|
}else if(KEY0==1&&KEY1==1&&WK_UP==0&&KEY2==1)key_up=1; |
|
|
return 0;// <EFBFBD>ް<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> |
|
|
}
|
|
|
|