当前位置:网站首页>Button to control the running water light (timer)
Button to control the running water light (timer)
2022-08-02 08:21:00 【Fate gathering 654】
Today we will understand and learn to use the internal timer of the microcontroller
The most basic function of the timer is timing. This time, the running water lamp is also implemented based on this function. Of course, the internal timers of different types of microcontrollers are slightly different. The timer configuration based on my microcontroller model is as follows
p>The following is a block diagram of the internal structure of the timer, from which you can intuitively see the working principle of the timer
When using the timer again, we first need to configure the timer mode through programming, and STC also provides us with a very convenient method to configure the timer mode
It should be noted that when setting the parameters, you must select the type corresponding to the microcontroller, otherwise an error will occur.
It is very easy to program the running water lamp after learning to use the timer. Add the timer module to the modular programming and configure the timer, and then add the timer interrupt function to the main function.
#include #include "TIMER0.h"#include "Key.h"#include unsigned char KeyNum, LEDMode;void main(){P2=0xFE;Timer0_Init();while(1){KeyNum=Key();if(KeyNum){if(KeyNum==1){LEDMode++;if(LEDMode>=2)LEDMode=0;}}}}unsigned int T0Count;void Timer0_Poutine() interrupt 1{TL0=0x18;TH0=0xFC;T0Count++;if(T0Count>=500){T0Count=0;if(LEDMode==0)P2=_crol_(P2,1);if(LEDMode==1)P2=_cror_(P2,1);}}
Timer
#include void Timer0_Init(){TMOD=TMOD&0xF0;TMOD=TMOD|0x01;TF0=0;TR0=1;TH0=0xFC;TL0=0x18;ET0=1;EA=1;PT0=0;}
Running Results
f3dc52bab67a4b8bc4e19f791f1224
边栏推荐
- Aided by training and learning by battle | The new version of the Offensive and Defense World Platform is officially launched!
- Inverter Phase Locking Principle and DSP Implementation
- Install Metasploitable2 on VMware
- Visual Analysis of DeadLock
- HCIP 第十一天
- 小说里的编程 【连载之二十五】元宇宙里月亮弯弯
- WebForm DropDownList分别绑定年月
- MySQL压缩包方式安装,傻瓜式教学
- 五款优秀免费的在线抠图工具
- flutter在导航栏处实现对两个列表的点击事件
猜你喜欢
随机推荐
2022年防止网络攻击的15个网络安全实践,你学会了吗?
研发过程中的文档管理与工具
MySQL - low level settings
CSRF-Cross-site request forgery-related knowledge
HCIP 第十三天
Database Plus 的云上之旅:SphereEx 正式开源 ShardingSphere on Cloud 解决方案
小说里的编程 【连载之二十五】元宇宙里月亮弯弯
优炫数据库的逻辑复制怎么样?
Biotinyl Cystamine|CAS:128915-82-2|生物素半胱胺
多版本node的安装与切换详细操作
node(三) 模块化
Aided by training and learning by battle | The new version of the Offensive and Defense World Platform is officially launched!
@RequestParam使用
爬虫 视频爬取工具you-get
离线部署通过tiup 配置好topology.yaml文件指定PD TV TIDBserver 是不是会自动在其他机器创建好对应得模块?
Visual Analysis of DeadLock
HCIP第二天
I.MX6U-ALPHA开发板(定时器按键消抖)
学习笔记(7)Funtion
@FeignClient configuration参数配置