Do I need to learn C language thoroughly to learn 51 single chip microcomputer?

Do I need to learn C language thoroughly to learn 51 single chip microcomputer?

Have you watched a lot of online videos or articles? Is their suggestion to teach you to read a C language book for a few months? When you really start programming the microcontroller, you will find that the microcontroller programming language only uses hundreds of C language. Less than ten percent, wasting my youth and killing my interest in electronics! Really learning the single-chip microcomputer requires a certain amount of hands-on ability, and the teaching mode of combining theory and practice does not teach you a lot of C language knowledge at the beginning.

Therefore, it is recommended to start with a development board and a tutorial. The initial knowledge requires very little C language. Later, when you find that your C language skills are not enough to make your programs feel like a duck to water, go back and learn C language seriously.

How to set the four working modes of the 51 single-chip microcomputer? Since it has four working modes, like the timer counter, if you want to use the timer counter, it also has four working modes, it must have a special function register to set it, so the serial number In fact, the control and operation of the line port is also the operation of the special function register. The special function register in the serial port is SBUF. Next, we will introduce a special function register, that is, to send and receive, which has been solved. Relying on the special function register SBUF is to write the data into the SBUF when sending, and to read the data from the SBUF to receive, but how to configure this working method? Or how to set the baud rate of the serial port? How to get him to start the transmission? This must be configured with a special function register. This special function register is the control register of the serial port. In addition to SCON, there is also a special function register related to the serial port. This is the PCON. The power management control register is actually only The highest bit is used, and the other bits have nothing to do with the serial port.

To set four working modes, there must be two bits to determine the setting of this working mode, namely SM0 and SM1. These two bits have four states. Generally speaking, these two bits are set to 01. , these two bits are in the low position, and the order often goes forward. The SM2 bit is a multi-machine control bit, which is mainly used for multi-machine communication. This is rarely used. When master-slave communication is required, it is generally This bit is not specially used for multi-computer communication. Generally, different slaves are determined by means of the application layer communication protocol of the upper computer, and different slave addresses are assigned to them, and then solved by the software layer protocol. The same machine does not use this method. This person can just clear it directly to 0 when it is not needed. REN is mainly to allow the receiving bit, that is to say, whether to allow the serial port of the current microcontroller to receive data, if you want to allow the receiving, It is necessary to set it to 1. If it is not allowed to receive, just clear it to 0 for sending. Generally, it will be set to 1, and it is also received when sending, so it is generally set to 1.

After the lower four digits are determined, the next step is the upper four digits. Among the upper four digits, TB8 and RB8 are mainly used in mode 2 and mode 3, and mode 2 and mode 3 are rarely used, so you don’t need to use them. Anyway, if you are interested, you can take a look for yourself. In fact, the ninth bit of the transmitted data can be specified in the software. It is mainly used in combination with SM2. Of course, it can also be used as a parity check. To send this parity bit, these two bits can be cleared directly to 0 if they are not used at ordinary times. The next two flag bits, one is the sending interrupt flag bit, and the other is the receiving interrupt flag bit. If you want to send a frame of data, When the data is written to SBUF, there is a send interrupt flag bit to 1 to determine that it is a receive interrupt after sending, and the hardware will automatically reset to 1 after receiving. It will make him to 1. This moment is to start sending the stop bit when the stop bit is sent. It will make the automatic hardware to 1 to apply for an interrupt to CBA, or to query this flag bit. In the interrupt service routine, it must be The software clears it to 0.

This is different from the interrupt flag bits TF0 and TF1 in the timer counter, which is automatically cleared by hardware when entering the interrupt service function, but the flag bit of the serial port cannot be automatically cleared by hardware, and must be cleared by software. , whether you use the query mode or the interrupt mode, you must clear this flag to 1 after the flag is not queried, or after the interrupt is triggered. As for the receive interrupt flag bit, it means that the stop bit is received. At the middle moment, when sending a frame of data, the last one is the stop bit sent. When receiving the serial communication, at the middle moment of receiving the stop bit, the RI bit will be automatically set to 1 by hardware. The CPU applies for an interrupt. It can process the received data by querying or interrupting. In fact, it is read away. It must be cleared in software. It will not be automatically cleared by hardware. The interrupted serial port These two flag bits of the interrupt are special. They cannot be automatically cleared by hardware. They are different from the interrupt flag bit of external interrupt and the interrupt flag bit of timer counter. They are in the interrupt service function. Once entered, the hardware will automatically clear it. Cleared to 0, but the serial port will not be automatically cleared to 0 by hardware, and it must be cleared to 0 by software.

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/123980692