使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_