程序#include "
STM32f10x.h"
#include "key.h"
#include "delay.h"
#include "sys.h"
void KEY_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11|GPIO_Pin_12;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOD, &GPIO_InitStructure);
}
u8 KEY_Scan(u8 mode)
{
sta
tic u8 key_up=1;
if(mode)key_up=1;
if(key_up&&(key1==0||key2==0))
{
delay_ms(10);
key_up=0;
if(key1==0)return KEY1;
else return KEY2;
}
else if(key1==0==key2==0)key_up=1;
return 0;
}
一周热门 更多>