stm32 - 跑马灯实验(库函数版本)

本次实验基于Mini开发板

跑马灯实验(库函数版本)模板:https://www.jianguoyun.com/p/DRwECloQgb_rBxiVuIcC

led.h

#ifndef __LED_H
#define __LED_H

void LED_Init(void);



#endif

led.c

#include "led.h"
#include "stm32f10x.h"

void LED_Init(void)
{
	GPIO_InitTypeDef GPIO_InitStructure;
	//RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOE,ENABLE);
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,ENABLE);  // GPIOD
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);  // GPIOA
	
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_Init(GPIOD,&GPIO_InitStructure);
	GPIO_SetBits(GPIOD,GPIO_Pin_2);
	
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_Init(GPIOA,&GPIO_InitStructure);
	GPIO_SetBits(GPIOA,GPIO_Pin_8);
	
	
	

}


main.c

#include "stm32f10x.h"
#include "led.h"
#include "delay.h"

int main(void)
{
	delay_init();//初始化延迟函数
	LED_Init();//初始化IO口
	
	
	
	while(1){
		GPIO_SetBits(GPIOD,GPIO_Pin_2);		
		GPIO_SetBits(GPIOA,GPIO_Pin_8);	
		delay_ms(500);//延迟500ms
		

		GPIO_ResetBits(GPIOD,GPIO_Pin_2);		
		GPIO_ResetBits(GPIOA,GPIO_Pin_8);		
		delay_ms(500);//延迟500ms
	}
	
	
}

posted @ 2019-10-23 13:14  cloudguest  阅读(515)  评论(0编辑  收藏  举报