当前位置:网站首页>Learning notes: how to time 10ms for 51 single chip microcomputer (STC89C52)
Learning notes: how to time 10ms for 51 single chip microcomputer (STC89C52)
2022-06-28 18:14:00 【LJX】
1. How to time the timer
First of all, describe the timing principle of the timer , In fact, the essence is just one sentence : Every machine cycle , Add... To the register 1.
Here we have to explain what a clock cycle is , What is a mechanical cycle . our 51 Whether it is the development board or the smallest system board , There will be an electronic component called “ Crystal oscillator ”, This crystal oscillator is a single-chip computer “ The heart ”. Usually in order to make the serial port baud rate stable to transmit data , Most of 51 The crystal oscillator frequency on the single chip microcomputer is 11.05922MHz. Clock cycle The calculation method is the reciprocal of the crystal vibration frequency , That is to say 11.0592 One second . The clock cycle is the most basic in a computer 、 The smallest unit of time . In a clock cycle ,CPU Just complete one basic action . A clock cycle is an amount of time . Smaller clock cycles mean higher operating frequencies . With the clock cycle, we can then calculate the mechanical cycle , One Mechanical cycle = 12 x Clock cycle =12 x (1/ clock frequency ) second = 12 / clock frequency second = 12 / 11059200 second = 12 000 000 / 11059200 Microsecond = 1.085 Microsecond . To sum up , The process of timer timing is equivalent to counting several mechanical cycles , After counting the mechanical cycle, the timer will overflow and end the timing .

2. How to schedule 10ms

Use 51 SCM timing has to understand TCON register ,TR0: Control start timing ,TF0: Judge whether the timer overflows ( This position when overflowing 1),TL0 The lower eight bits of the initial value of the timer ,TH0 The initial value of the timer is eight bits higher ( Do not configure the initial value. The default value is from 0 Start counting ). That is to say, the timer mode is in 16 In case of automatic reloading of bit , from 0 Start counting , Count up 65536 A mechanical cycle, that is 71ms The timer will overflow . So if we want to schedule 10ms Just from 61ms Time to start counting , Count to 71ms The timer just overflows . At this time, you only need to configure the upper eight bits and the lower eight bits of the initial value of the timer .
The process of configuring the upper octet and the lower octet :
The configuration process is not complicated , First determine 10ms Several mechanical cycles are involved :
10ms1.085us=9216( Pay attention to unit conversion here )
If from 0 From the beginning of counting to overflow, the total number is 65536 A mechanical cycle , Well, if you go from 61ms Start timing is also from 65536-9216=56320 Start counting , The conversion 16 The binary system is shown in the following figure :

So the high order is DC, Low position is 0. Perfect scattered flowers !!!
Of course, now some software can automatically generate after inputting the timing time C Code , for example ISP. But I want to contact the early days of SCM “ shortcut ” Try not to walk , It is very helpful to learn more about the underlying things .

边栏推荐
- 阿里云服务器里装的mysql是8版本的,是因为dataworks的mysql驱动版本不支持吗?现在提
- Ten MySQL locks, one article will give you full analysis
- How to upgrade from RHEL 8 to RHEL 9
- Why insert is configured with'select last_ INSERT_ What if id() 'returns 0?
- DMS的SQL结果集导出支持传参数吗?
- GCC getting started manual
- nuc980心跳灯
- Google推出Advanced API Security 保护API免受安全威胁
- 终于辞职了,全职ue了
- Currency circle earthquake: earned 1million last year and lost 5million this year
猜你喜欢

Applet graduation design based on wechat gym private education appointment applet graduation design opening report function reference

Ten MySQL locks, one article will give you full analysis

Matlb| optimal operation and marketization of power system

moco挡板制作及运行成功

2022年山东省安全员C证考试练习题及模拟考试

halcon知识:矩阵专题【01】

MCU modifies network hardware driver (PHY chip replacement)

Applet graduation project reservation based on wechat housekeeping service applet graduation project opening report function reference

Small program graduation project based on wechat chess and card room small program graduation project opening report function reference

Small program graduation project based on wechat campus lost and found graduation project opening report function reference
随机推荐
Applet graduation project is based on wechat property maintenance application property applet graduation project opening report function reference
DNSLog注入
Flutter 小技巧之 MediaQuery 和 build 优化你不知道的秘密
架构自治服务:构建数据驱动的架构洞察
通达信能开户炒股吗?安全吗?
kubeadm创建kubernetes集群
Visio use
如何从RHEL 8升级到RHEL 9
Node foundation ~ node level
moco挡板制作及运行成功
Leetcode 6. Z 字形变换(牛逼,解决了)
全力冲unreal了
WPF video hard decoding, rendering and playing (no airspace) (support 4K, 8K and high frame rate video)
Redis6 notes 04 master-slave replication, cluster, application problems, new redis6 features
Can data sources only be connected to Alibaba cloud cloud databases? Can't you connect the databases installed in Alibaba cloud servers?
C 语言进阶
听说转行软件测试只能自学,培训机构是个坑?
Does face recognition test involve privacy and security issues? A foreign company was urgently stopped
Why can't China produce products like idea?
Redis 原理 - Hash