#include "stm32f0xx.h" // Device header
#include "Delay.h"
#include "BEE.h"
#include "Key.h"
#include "main.h"
uint8_t KZFH=0;
void Key_Init()
{
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA,ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB,ENABLE);
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_StructInit(&GPIO_InitStruct);
GPIO_InitStruct.GPIO_Mode=GPIO_Mode_IN;
//GPIO_InitStruct.GPIO_OType=GPIO_OType_PP;
GPIO_InitStruct.GPIO_Pin=GPIO_Pin_1|GPIO_Pin_0;
GPIO_InitStruct.GPIO_PuPd= GPIO_PuPd_UP;
GPIO_InitStruct.GPIO_Speed= GPIO_Speed_Level_3;//50
GPIO_Init(GPIOB,&GPIO_InitStruct);
GPIO_InitStruct.GPIO_Mode=GPIO_Mode_IN;
//GPIO_InitStruct.GPIO_OType=GPIO_OType_PP;
GPIO_InitStruct.GPIO_Pin=GPIO_Pin_7|GPIO_Pin_6;
GPIO_InitStruct.GPIO_PuPd= GPIO_PuPd_UP;
GPIO_InitStruct.GPIO_Speed= GPIO_Speed_Level_3;//50
GPIO_Init(GPIOA,&GPIO_InitStruct);
}
//返回按键变量
uint8_t Key_Z(void)
{
uint8_t KeyNum=0;
if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_1)==0)
{
Delay_ms(10);
KeyNum=1;
}
if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_0)==0)
{
Delay_ms(10);
KeyNum=2;
}
if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_6)==0)
{
Delay_ms(10);
KeyNum=3;
}
if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_7)==0)
{
Delay_ms(10);
KeyNum=4;
}
return KeyNum;
}
uint8_t Key_GetNum(void)
{
uint8_t KZ,KeyNum=0;
KZ=Key_Z();//接收按键按下的值
if(KZ!=0)
{
KZFH=KZ;//检测到按键按下
}
else if(KZFH!=0)//检测到按键松开并且按下过
{
Delay_ms(10);
return KZFH;
}
return 0;
}