/* * @Author: your name * @Date: 2022-04-17 21:03:46 * @LastEditTime: 2022-04-19 23:32:17 * @LastEditors: Please set LastEditors * @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" ////////////////////////////////////////////////////////////////////////////////// //������ֻ��ѧϰʹ�ã�δ���������ɣ��������������κ���; //ALIENTEK��ӢSTM32������ //������������ //����ԭ��@ALIENTEK //������̳:www.openedv.com //�޸�����:2012/9/3 //�汾��V1.0 //��Ȩ���У�����ؾ��� //Copyright(C) �������������ӿƼ����޹�˾ 2009-2019 //All rights reserved ////////////////////////////////////////////////////////////////////////////////// //������ʼ������ void KEY_Init(void) //IO��ʼ�� { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOB,ENABLE);//ʹ��PORTA,PORTEʱ�� GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //���ó��������� GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15; GPIO_Init(GPIOC, &GPIO_InitStructure); } //������������ //���ذ���ֵ //mode:0,��֧��������;1,֧��������; //0��û���κΰ������� //1��KEY0���� //2��KEY1���� //3��KEY3���� WK_UP //ע��˺�������Ӧ���ȼ�,KEY0>KEY1>KEY_UP!! u8 KEY_Scan(u8 mode) { static u8 key_up=1;//�������ɿ���־ if(mode)key_up=1; //֧������ if(key_up&&(KEY0==0 || KEY1==0 || KEY2==0 ||WK_UP==0)) { delay_ms(10);//ȥ���� key_up=0; if(KEY0==0)return KEY0_PRES; else if(KEY1==0)return KEY1_PRES; else if(WK_UP==0)return WKUP_PRES; else if(KEY2 == 0)return KEY2_PRES; }else if(KEY0==1&&KEY1==1&&WK_UP==1&&KEY2==1)key_up=1; return 0;// �ް������� }