DAY1 2022年12月6日
基于原点STM32最小开发板
仿真器使用DAP仿真器
目的:点亮自带的两盏小灯LED0和LED1,并且形成闪烁效果
(原点的开发板自带的两盏小灯分别连接PB5和PE5)
——————————————————————————————————————
LED函数代码:
#include "sys.h"
#include "stm32f10x.h"
#include "delay.h"
void LED_Init(void) //初始化单片机状态
{
GPIO_InitTypeDef GPIO_InitStructure; //初始化GPIO结构体
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOE , ENABLE); // 初始化GPIOB和GPIOE端口
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //设置为推挽输出
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; //设置PB5,PE5端口激活
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //设置速度为50MHz
GPIO_Init(GPIOB ,&GPIO_InitStructure);
GPIO_Init(GPIOE ,&GPIO_InitStructure);
GPIO_SetBits(GPIOB, GPIO_Pin_5);
GPIO_SetBits(GPIOE, GPIO_Pin_5); //设置PB5,PE5初始化为高电平
}
void LED_0(void) //LED0的闪烁
{
GPIO_SetBits(GPIOB,GPIO_Pin_5);
delay_ms(30000);
GPIO_ResetBits(GPIOB,GPIO_Pin_5);
delay_ms(30000);
}
void LED_1(void) //LED1的闪烁
{
GPIO_ResetBits(GPIOE,GPIO_Pin_5);
delay_ms(300);
GPIO_SetBits(GPIOE,GPIO_Pin_5);
delay_ms(300);
}
主函数代码:
#include "stm32f10x.h"
#include "LED.h"
#include "delay.h"
#include "sys.h"
int main(void)
{
delay_init(); //调用delay函数
LED_Init(); //调用LED_Init函数
while(1) //无限循环
{
LED_0();
LED_1();
}
}
新手入门,如有问题,请多多指正,也欢迎各位大神提出优化意见。