一.先建立bsp_key.h bsp_key.c bsp_led.c bsp_led.h放在user文件夹里
led头文件
#ifndef BSP_LED_H
#define BSP_LED_H
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"//需要的头文件
#define LED_PIN_1 GPIO_Pin_1
#define LED_Port_1 GPIOC
#define LED_CLK_1 RCC_AHB1Periph_GPIOC
extern void LED_GPIO_Config(void);//extern定义的函数可以在所有工程C文件里面的调用
extern void beep_GPIO_Config(void);
#endif
#include "bsp_led.h"
//1打开时钟
//2确定引脚号
//3输入还是输出
//4输出的模式
//5上拉还是下拉
//6输出速度
void LED_GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStruct;//定义一个结构体类型的数据
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);//开启时钟为使能
GPIO_InitStruct.GPIO_Pin=GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4;//初始化几个就或几个脚
//void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct);//函数原型
GPIO_InitStruct.GPIO_Mode=GPIO_Mode_OUT;//选择模式为输出
GPIO_InitStruct.GPIO_OType= GPIO_OType_PP;//输出模式为推挽
GPIO_InitStruct.GPIO_PuPd= GPIO_PuP