32固件库编程点亮led灯:
在已经建好工程的基础上,进行建立文件,包括bsp文件,是关于led。
(一)main()
#include"stm32f10x.h"
#include"bsp_led.h"
void Delay(uint32_t count)
{
for(;count!=0; count--);
}
int main(void)
{
LED_GPIO_Config();
while(1)
{
LED_G(OFF);
Delay(0xfffff);
LED_G(ON);
Delay(0xfffff);
}
}
(二)bsp_led.c()
#include"bsp_led.h"
void LED_GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
RCC_APB2PeriphClockCmd(LED_G_GPIO_CLK , ENABLE);
GPIO_InitStruct.GPIO_Pin = LED_G_GPIO_PIN ;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(LED_G_GPIO_PORT, &GPIO_InitStruct);
}
(三)bsp_led.h
#ifndef _BSP_LED_H
#define _BSP_LED_H
#include"stm32f10x.h"
void LED_GPIO_Config(void);
#define LED_G_GPIO_PIN GPIO_Pin_0
#define LED_G_GPIO_PORT GPIOB
#define LED_G_GPIO_CLK RCC_APB2Periph_GPIOB
#define ON 1
#define OFF 0
#define LED_G(a) if(a) GPIO_ResetBits(LED_G_GPIO_PORT, LED_G_GPIO_PIN);else GPIO_SetBits(LED_G_GPIO_PORT, LED_G_GPIO_PIN);
#endif