Is the single-chip microcomputer as eager to learn as imagined? I am very confused. Some say positive and some negative

Is the single-chip microcomputer as eager to learn as imagined? I am very confused. Some say positive and some negative

The advantage of the modern Internet is that you can collect all kinds of messy resources, but this is also easy to confuse people. It has advantages and disadvantages. The advantage is that there is a lot of information and it is easy to get started, but your colleagues are also very dazzling, so you have no idea where to start. There are friends who want to get started with MCU You can continue to pay attention to me, and I will carefully organize a set of video tutorial materials for you to quickly learn to reach a monthly salary of over 10,000 and share them with you for free.

Timing is actually also called counting, but its timing reference is the time of a machine cycle. To generate a timing, in fact, it is based on the machine cycle to see how many times it travels, how many pulses come, and the value inside. It will be added several times, but the function structure of this timer counter is relatively simple. It will overflow in only one case, that is, when the value in it is full, it will take another machine cycle time, and adding one more will generate Overflow, this is its timing function.

If the counting function is performed at this time, it is still an up-counter, but this time it does not count the pulses of the internal machine cycle, but counts the pins of the microcontroller. This pin is called T0, which refers to the microcontroller. The P3.4 pin in the P3 port is the pulse input pin of the counting function of the timer counter. When using the timer counter, whether it is the timer function or the counting function, it is a counter that adds one. When counting, it is Count the pulse on this pin, and it will also increase by one for every clock pulse on the pin. When the number of pulses is added to FFFF, there will be another pulse on this pin, and the timer will overflow, you can Handle the external pulse count event by query or interrupt.

It should be noted that when the CPU of the single-chip microcomputer processes the level sampling on this pin, it is sampling in the previous machine cycle, such as a high level, and the next machine cycle adopts a low level, at this time it can It is considered that a pulse is coming, so there is a requirement for the pulse frequency on this pin. It can be measured not at any frequency. When the frequency is relatively high, when the microcontroller exceeds the frequency range, you can do a split screen externally, and then come back Measurement, this is relatively easy to implement. The two functions of the timer counter are actually a plus-one counter. When doing internal timing, it counts the internal machine cycles. When measuring the external pulse pin, it It is also a counter, but the root is different.

C/T is equivalent to an electronic switch, which pushes the source of the counting pulse to the machine cycle. If it is 1, it will hit the counting source to the pin. To control it is equivalent to making a countdown stopwatch. To start it, it starts timing. The timing counter is the same. The timing counter has a control bit TR0 or TR1, which is used to control the timing counter to turn on and off. To do the timing function, you must first initialize, set Whether it is a timer or a counter, after setting it, you can start the timer counter, and it can work, and it has several working modes, which need to be set in TMOD. The two bits of M0M1 can be set to four working modes. The value set by the two bits can be 00, 01, 10 and 11, thus setting four working modes, and you need to select the specific working mode when using it.

There are these bits in TCON. TF0 and TR0 are overflow flag bits, and T20 is the control start bit. This issue mainly understands how the timer counter works. When doing the timing function, it is the internal machine cycle. Counting, when doing the counting function, it counts the external pulses on the pin. One of its essence is an up-counter. Whether it is timing or counting, it can generate overflow, but the conditions for overflow are all It is when the values ​​in TH0 and TL0 are pulses or external pulses, and each time a pulse is added to FFFF after adding one, it will overflow with another pulse or another external pulse. First, it needs to be initialized, select the working mode, select The timing function is still the counting function. At the same time, the timing counter should be turned on, and the overflow can be processed after it is full. This is its basic working principle.

If you are interested in single-chip microcomputer, you can check the content shared in previous issues , hoping to help everyone take some detours on the road of learning single-chip microcomputer . If you want to get started with single-chip microcomputer, you can continue to pay attention to the programming of single-chip microcomputer , and reply "Take me to learn" to view more content sharing .

Guess you like

Origin blog.csdn.net/m0_66707146/article/details/123712789