把stm32 初始化led灯的程序记录一下,回头可以直接使用,不用每次都找了
//led.c PA.7口
#include "led.h"
void LED_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* 使能GPIOA时钟 */
/*使用的是STM32F030系列,时钟可能不一样,改一下即可*/
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
/* 配置LED相应引脚PA7*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_SetBits(GPIOA, GPIO_Pin_7); //灯灭
}
//led.h
#ifndef __LED_H
#define __LED_H
#include "stm32f0xx.h"
#define LED_OFF GPIO_SetBits(GPIOA,GPIO_Pin_7)//灯灭
#define LED_ON GPIO_ResetBits(GPIOA,GPIO_Pin_7)//灯亮
#define LED_TURN GPIO_WriteBit(GPIOA, GPIO_Pin_7, (BitAction)((1- GPIO_ReadOutputDataBit(GPIOA, GPIO_Pin_7))))//使灯翻转
void LED_Init(void);
#endif