STM32学习日志

本文介绍了使用STM32F10x控制LED实现单个LED的亮灭闪烁,通过延时函数如Delay_ms()、Delay_s()和Delay_us()来控制亮灭周期。随后扩展到流水灯的制作方法,展示了GPIO配置和多LED的控制技巧。
摘要由CSDN通过智能技术生成

上节说到实现led亮灭,那么如何实现闪烁?
没错,一亮一灭其实就是亮一段时间+灭一段时间,其中一段时间是如何达成?这里需要延时函数Delay();

延时函数Delay()

Delay_ms:毫秒级;Delay_ms(500):延时500ms
Delay_s:秒级;Delay_s(5):延时5秒
Delay_us:微秒级;Delay_us(500):延时500微秒

依然是正极接面包板正极,负极接PA口
#include “stm32f10x.h” // Device header
#include “Delay.h”

int main(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);

GPIO_InitTypeDef GPIO_InitStructure;
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);
while(1)
{
	GPIO_ResetBits(GPIOA,GPIO_Pin_8);
	Delay_ms(200);
	GPIO_SetBits(GPIOA,GPIO_Pin_8);
	Delay_ms(200);
	

}

}
现象:led闪烁

#include “stm32f10x.h” // Device header
#include “Delay.h”

int main(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);

GPIO_InitTypeDef GPIO_InitStructure;
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);
while(1)
{
	GPIO_WriteBit(GPIOA,GPIO_Pin_8,Bit_SET);
	Delay_ms(200);
    GPIO_WriteBit(GPIOA,GPIO_Pin_8,Bit_RESET);
	Delay_ms(200);
	

}

}

现象:led闪烁

那么,现在实现了单个led闪烁,流水灯怎么做?没错,多个led闪烁!

  • 7
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值