In the learning process of 51 single-chip microcomputer, we often find that the interrupt, counter/timer and serial port are the difficulties in learning the single-chip microcomputer. For beginners, the contents of these parts are difficult to understand. But I personally think that these parts are the focus of MCU learning. If you don't understand these parts in a semester class or self-study, it means that you haven't mastered 51 MCUs yet, let alone the development of MCU. We all know that in the finished MCU project, there are many based on these parts. The perpetual calendar is based on timers. The alarm is mainly based on interrupts. The online communication is mainly based on serial port.
In these parts, counters/timers are easy to confuse for beginners. I will talk about this in combination with my own learning experience.
The essence of the counter and the timer are the same. They all count the pulses generated in the MCU, except that the counter is the externally triggered pulse of the MCU. The timer is the pulse generated by the internal oscillator under the trigger of the crystal oscillator. Counters and timers are a concept when their pulse intervals are the same.
There is an overflow concept in both the timer and the counter, so what is overflowing. Oh, we can get the answer from a little common sense of life. When a bowl is placed under the tap to pick up the water, after a while, the bowl of water is full, and it overflows. By the same token, assuming that the water in the faucet is dripping into the bowl, there is always a drop of water that causes the water in the bowl to overflow. The water overflowing in the bowl is wasted, but overflowing in the timer counter of the microcontroller will cause an interrupt. As for what is interrupted, we will talk about it next time. Here is only a preliminary concept. The interrupt can interrupt the normal operation of the system. The process of running the interrupt service routine, when the service program runs, automatically returns to the interrupted place to continue running.
In the timer counter, we have a concept called capacity, which is the maximum count. Mode 0 is the 13th power of 2, Mode 1 is the 13th power of 2, Mode 2 is the 8th power of 2, and Mode 3 is the 8th power of 2. The water droplet is likened to a pulse, and the last drop of water that causes the water in the bowl to overflow is the last pulse of the overflow of the timer counter.
In the various MCU books, when the timing counter is introduced, an initial value is counted. What is the initial value of the count? Here we still assume a drop bowl. Assuming that the first hundred drops of water can overflow the water in the bowl, we know that the bowl has a capacity of 100. Question 1, how can I make the bowl overflow with 10 drops of water? Oh, I can imagine that if you take an empty bowl to pick up the water, you still have to drop 100 drops of water to overflow, but if we take a bowl that already has water, then we don't need 100 drops. At this point we can figure out that if 10 drops of water are allowed to overflow the water in the bowl, then 90 drops of water must be placed in the bowl.
In the timing counter, these 90 drops are what we call the initial value. Question 2: In a workshop, how do we use the MCU to calculate the pieces of 100 products and carry out automatic packaging?
We can use the counter to count 100 and perform an automatic wrapper in the interrupt.
There are three initial counts here, assuming that there is a mode 0: the initial value of the count = 8912 (2 to the power of 13) - 100 = 8812. Method 1: Count initial value = 65536 (2 to the 16th power) - 100 = 65436. Mode 0: Count initial value = 256 (2 to the 8th power) - 100 = 156.
According to the initial value obtained, and then convert it to hexadecimal or binary, you can count or time. Of course, to make the program run completely, you need to set the corresponding registers. These can be found in a variety of microcontroller tutorials.
Doorbell Transformer,nest doorbell transformer,24v doorbell transformer,buck boost transformer
Guang Er Zhong(Zhaoqing)Electronics Co., Ltd , https://www.gezadapter.com