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.
Previous article:51 single chip microcomputer DS18B20 temperature measurement
Next article:51 MCU 4-bit digital tube electronic clock source program
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- [Repost] Is wireless charging useless or a black technology?
- (Customized watches participate in the lucky draw) Make a good watch with a "core" | Infineon smart watch solution
- The double-tube counterattack input voltage rises inexplicably
- Op amp gain multiple problem
- How to control two dsp of hyperlink to initialize and synchronize two dso
- Bojing Network 4G router solution security monitoring 4G module car 4G router motherboard usage tutorial
- TI motorware library vector control laboratory inspinlabs_FOC labs_2b program
- Have you heard of this black technology that kills earthworms and destroys the soil?
- Good information on clock division
- Let’s practice together in 2021 + a great year!