此代码仅提供了代码思路,具体移植应用可以私信博主。
key.c:
#include "stm32f10x.h"
#include "key.h"
#include "led.h"
#include "sys.h"
#include "delay.h"
u16 keyz=0;
void KEY_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
u8 keyscan(void)
{
uint8_t LIE,HANG,k,i=0;
GPIO_Write(GPIOC, 0xF0);
if((GPIO_ReadInputData(GPIOC)&0xF0)!=0xF0)
{
delay_ms(40);