当前位置:网站首页>STM32 uses time delay to realize breathing lamp register version
STM32 uses time delay to realize breathing lamp register version
2022-06-24 19:23:00 【Me-Space】
stm32 Use time delay to realize breathing lamp ( register )
The experiment uses STM32F103C8T6 Realization , Programming with registers .
Breathing lights : The brightness of the light is constantly changing from light to dark under control , And then change from dark to light , It feels like people are breathing .
In general use PWM Pulse realization , The principle is to change the time of high level ( Duty cycle ), So as to achieve the effect of breathing lamp . Here the delay is used to simulate PWM pulse .
PWM The principle is shown in the figure below :
The hardware description is shown in the figure below :
Implementation code
1. Macro definition
#define LED1_ON GPIOA->ODR |= (1 << 0); //LED Light on
#define LED1_OFF GPIOA->ODR &= ~(1 << 0);//LED The light goes out
2.GPIO Mouth initialization
void Led_Init(void)
{
// Turn on the clock
RCC->APB2ENR |= (1 << 2);
// Zero clearing
GPIOA->CRL &= ~(0XF << 0);
// General push-pull output
GPIOA->CRL |= (0X3 << 0);
//LED The lamp is off by default
GPIOA->ODR &= ~(0XFF << 0);
}
3. Breathing lamp implementation code
void Breathe _Led(void)
{
int i = 0;
int num = 5000;// Cycle time
// From dark to light
for(i = 0; i < num; i++)
{
LED1_ON;
delay_us(i);// High level time Microsecond delay function
LED1_OFF;
delay_us(num - i);// Low level time
}
// Change from light to dark
for(i = num; i > 0; i--)
{
LED1_ON;
delay_us(i);// High level time
LED1_OFF;
delay_us(num - i);// Low level time
}
}
4. The main function
int main(void)
{
Led_Init();//LED Lamp initialization
while (1)
{
Breathe_Led();// Breathing lights
}
}
If there is anything wrong, please point it out .
边栏推荐
- 试驾 Citus 11.0 beta(官方博客)
- subject may not be empty [subject-empty]
- 对国产数据库厂商提几个关于SQL引擎的小需求
- PingCAP 入选 2022 Gartner 云数据库“客户之声”,获评“卓越表现者”最高分
- Xiaobai, let me ask you guys, is MySQL binlog extracted by CDC in strict order
- [computer talk club] Lecture 3: how to raise key issues?
- Volcano成Spark默认batch调度器
- 优维低代码:构件渲染子构件
- SaltStack State状态文件配置实例
- IBPS开源表单设计器有什么功能?
猜你喜欢

Do you have all the basic embedded knowledge points that novices often ignore?

Zadig + 洞态 IAST:让安全溶于持续交付

How to use R package ggtreeextra to draw evolution tree

Intel and Microsoft give full play to the potential energy of edge cloud collaboration to promote the large-scale deployment of AI

High dimension low code: component rendering sub component

Volcano becomes spark default batch scheduler

Interpreting harmonyos application and service ecology

Tkde2022: Dialogue recommendation system based on knowledge enhanced sampling
![[leetcode] rotation series (array, matrix, linked list, function, string)](/img/9e/079311df16fa8e28708f4e050e531f.png)
[leetcode] rotation series (array, matrix, linked list, function, string)

Volcano成Spark默认batch调度器
随机推荐
特尔携手微软发挥边云协同势能,推动AI规模化部署
Why useevent is not good enough
The script implements the automated deployment of raid0
Understanding openstack network
The sharp sword of API management -- eolink
Volcano becomes spark default batch scheduler
How to deal with the problem that the Flink CDC reads MySQL in full and always reports this error
Apifox与其他接口开发工具的博弈
我链接mysql 报这个错 是啥意思呀?
Technology implementation | Apache Doris cold and hot data storage (I)
NFT双币质押流动性挖矿系统开发
R语言corrplot相关热图美化实例分析
Volcano成Spark默认batch调度器
This is not safe
How to select the ECS type and what to consider?
MySQL binlog data source configuration document, please share
Source code analysis of ArrayList
System design idea of time traceability
佛祖保佑 永无BUG
Server lease error in Hong Kong may lead to serious consequences