51 MCU timer timing mode

Publisher:算法之手Latest update time:2015-06-16 Source: 51hei Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Let me write some professional knowledge. I am also a beginner, so let's learn together. Okay, let's stop talking nonsense and get to the point.

Anyone who has just started learning 51 microcontrollers will come across timers. There is a lot of information about timers, including their internal structure and how to execute them. But when it comes to modes, I think when I first started learning, the mess of modes they talked about were very confusing, such as mode 0, mode 1, 16 bits, and 8 bits. I still don't understand them. But when I was programming, I had a preliminary understanding of this thing.

First of all, why should the timer be initialized? Let's take an analogy. In ancient times, hourglasses were used for timing. The hourglass was filled with sand first, and then a hole was drilled. When all the sand slipped away, it was a cycle. If you want to time it, the last time is loaded. If I set it to 10 milliseconds, it will be 10, 9, 8, 7, 6... until 0, and the interrupt will be started. Another way is to drip water in a wooden barrel. The volume of the wooden barrel is certain. When the water drips full, it is a cycle. Add that wooden barrel to hold 10 milliseconds of water. When the water overflows, it means that 10 milliseconds have arrived and the interrupt will be started. What if I don't want to load 10 milliseconds, I only want 5 milliseconds? The method is to first load 5 milliseconds of water into the barrel, and then start the timer. At this time, you only need to drip 5 milliseconds to fill the water. This is why the microcontroller timer needs to be initialized.

Another one is the mode. I read a lot of books and listened to videos, but I still don't understand what they are talking about. But I know that the difference between them is in time. Take the 12m crystal oscillator as an example. In mode 0, the maximum timer can be 8.192 milliseconds. In mode 1, the maximum timer can be 65.535 milliseconds. In modes 2 and 3, the maximum timer can be 0.256 milliseconds. When using it, it depends on your specific needs. If it is interrupted once within 10 milliseconds, mode 0 is enough. If it is interrupted once within 1 millisecond, mode 2 or 3 is required. Mode 3 automatically reloads the eight-bit timer. My understanding is that you don't need to use a program to install the initial value. The initial value is installed by hardware, saving you the time used to install the initial value. Of course, I have never used it. The most common ones I use are mode 0 and 1.

This is basically what I mean. If you have any misunderstanding, you are welcome to criticize and correct me.

Reference address:51 MCU timer timing mode

Previous article:51 single chip microcomputer DS18B20 temperature measurement
Next article:51 MCU 4-bit digital tube electronic clock source program

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号