使STM32单片机LED交替闪烁
创建一个main.c
编入:
#include "stm32f10x.h"
#include "led.h"
#include "delay.h"
int main(void)
{
LED_Init();
Delay_Init();
while(1)
{
GPIO_ResetBits(GPIOB,GPIO_Pin_5);
GPIO_SetBits(GPIOE,GPIO_Pin_5);
DelayMs(500);
GPIO_SetBits(GPIOB,GPIO_Pin_5);
GPIO_ResetBits(GPIOE,GPIO_Pin_5);
DelayMs(500);
}
}
创建一个led.c
编入:
#include "stm32f10x.h"
#include "led.h"
void LED_Init(void)
{
GPIO_InitTypeDef GPIO_Inistatructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOE,ENABLE);
GPIO_Inistatructure.GPIO_Pin=GPIO_Pin_5;
GPIO_Inistatructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_Inistatructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOB,&GPIO_Inistatructure);
GPIO_Inistatructure.GPIO_Pin=GPIO_Pin_5;
GPIO_Inistatructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_Inistatructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOE,&GPIO_Inistatructure);
}
创建一个led.h
编入:
#ifndef _LED_H_
#define _LED_H_
void LED_Init(void);
#endif
可能出现的error及解决方案:
1.#2532-D: support for trigraphs is disabled:
此错误是魔术棒里面C/C++里面的 GNUextensions设置勾选上了。取消此勾选,警告就消失了。
2.last line of file ends without:
只要在main函数的“}”后加回车键,此警告信息即可消除。