当前位置:网站首页>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
边栏推荐
- MySQL - low level settings
- 数据中心的网络安全操作规范
- 【Network】IP, subnet mask
- @PostConstruct注解详解
- 我与csdn
- 设置工作模式与环境(中):建造二级引导器
- (2022 Niu Ke Duo School 5) B-Watches (two points)
- Understand the Chisel language. 30. Chisel advanced communication state machine (2) - FSMD: Take Popcount as an example
- Introduction to Totem Pole and Push-Pull Circuits
- ROS文件系统以及相关命令
猜你喜欢
随机推荐
MySQL之创建表的基本操作
Data Middle Office: Started in Ali, Prosperous in DaaS
typescript学习
设置 height: auto 却无法触发 transition 动画的解决方案
OSPF 综合实验
Postgres horizontal table, automatically create partitions, table by time
Kind of weird!Access the destination URL, the host can container but not
小说里的编程 【连载之二十一】元宇宙里月亮弯弯
sql创建表格 如图 运行完提示invalid table name 是什么原因
有点奇怪!访问目的网址,主机能容器却不行
常用的云安全防护措施盘点
Hack The Box - File Transfers Module详细讲解中文教程
图扑软件数字孪生油气管道站,搭建油气运输管控平台
2022-2023 十大应用开发趋势
WebRTC系列-SDP之编码信息收集
原型模式
HCIP 第五天
论文理解:“Cross-Scale Residual Network: A GeneralFramework for Image Super-Resolution,Denoising, and “
52.【bool类型输入任何非0数值不为1的版本原因】
Biotin hydrazide HCl|CAS:66640-86-6|生物素-酰肼盐酸盐