C文件
#include "key.h"
void KEY_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;//初始化结构体
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);//配置时钟,还没学会
GPIO_InitStructure.GPIO_Pin = KEY1 | KEY2;//配置端口
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //配置工作模式
// GPIO_InitStructure.GPIO.Speed = GPIO_Speed_50MHz //配置端口运行速度
GPIO_Init(KEYPORT,&GPIO_InitStructure);
}
H文件
#ifndef __KEY_H
#define __KEY_H
#include "sys.h"
//#define KEY1 PAin(0)// PA0
//#define KEY2 PAin(1)// PA1
#define KEYPORT GPIOA//定义按键接口组
#define KEY1 GPIO_Pin_0//定义按键接口
#define KEY2 GPIO_Pin_1//定义按键接口
void KEY_Init(void);
#endif