当前位置:网站首页>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 .
边栏推荐
- 西北工业大学遭黑客攻击?双因素认证改变局面!
- Would you like to ask whether the same multiple tasks of the PgSQL CDC account will have an impact? I now have only one of the three tasks
- Unityshader world coordinates do not change with the model
- Set up your own website (8)
- 上位机与MES对接的几种方式
- Using alicloud RDS for SQL Server Performance insight to optimize database load - first understanding of performance insight
- 小白请教下各位大佬,cdc抽取mysql binlog是严格顺序的吗
- Starring develops httpjson access point + Database
- Interprétation de la thèse (SR - gnn) Shift Robust GNNS: Overcoming the Limits of Localized Graph Training Data
- 论文解读(SR-GNN)《Shift-Robust GNNs: Overcoming the Limitations of Localized Graph Training Data》
猜你喜欢

Tkde2022: Dialogue recommendation system based on knowledge enhanced sampling

How to protect biological privacy in the AI era? Overview of the latest "privacy enhancement technology in biometrics" of the Autonomous University of Madrid, comprehensively detailing the biometric p

Source code analysis of ArrayList

模块五

Game between apifox and other interface development tools

西北工业大学遭黑客攻击?双因素认证改变局面!

Unity mobile game performance optimization spectrum CPU time-consuming optimization divided by engine modules

Interpreting harmonyos application and service ecology

Technology implementation | Apache Doris cold and hot data storage (I)

TKDE2022:基于知识增强采样的对话推荐系统
随机推荐
Ask a question. Adbhi supports the retention of 100 databases with the latest IDs. Is this an operation like this
我链接mysql 报这个错 是啥意思呀?
Interpreting harmonyos application and service ecology
Does finkcdc support sqlserver2008?
全链路业务追踪落地实践方案
###脚本实现raid0自动化部署
R语言 4.1.0软件安装包和安装教程
LabView之MQTT协议使用
An accident caused by a MySQL misoperation cannot be withstood by High Availability!
Unity移动端游戏性能优化简谱之 以引擎模块为划分的CPU耗时调优
How do programmers do we media?
目前是不是只cdc 监控mysql 可以拿到新增列的数据 sqlserver不行是吧
一文详解|Go 分布式链路追踪实现原理
Nokov motion capture system makes it possible for multi field cooperative UAV to build independently
Set up your own website (8)
PingCAP 入选 2022 Gartner 云数据库“客户之声”,获评“卓越表现者”最高分
Why are life science enterprises on the cloud in succession?
mysql binlog 数据源配置文档麻烦分享一下
API管理之利剑 -- Eolink
ls 常用参数