初级会员

- 积分
- 54
- 金钱
- 54
- 注册时间
- 2016-10-16
- 在线时间
- 8 小时
|

楼主 |
发表于 2017-3-2 19:59:03
|
显示全部楼层
头文件
#ifndef __KEY_H
#define __KEY_H
#include "sys.h"
#define KEY0 PCin(5)
#define KEY1 PAin(15)
#define WK_UP PAin(0)
#define ChangeLED0 1;
#define ChangeLED1 2;
#define Flipboth 3;
void Key_Init(void);
u8 KEY_Scan(void);
#endif
源文件
#include "key.h"
#include "delay.h"
void Key_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOC,ENABLE);//使能PORTA,PORTC时钟
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);//关闭jtag,使能SWD,可以用SWD模式调试
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;//PA15
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //设置成上拉输入
GPIO_Init(GPIOA, &GPIO_InitStructure);//初始化GPIOA15
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;//PC5
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //设置成上拉输入
GPIO_Init(GPIOC, &GPIO_InitStructure);//初始化GPIOC5
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;//PA0
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; //PA0设置成输入,默认下拉
GPIO_Init(GPIOA, &GPIO_InitStructure);//初始化GPIOA.0
}
u8 KEY_Scan(void)
{
if (KEY0==0) return ChangeLED0;
else if (KEY1==0) return ChangeLED1;
else if (WK_UP==0) return Flipboth;
else return 0;
} |
|