Is it necessary to learn embedded and single-chip microcomputer, and where is the value reflected?

Is it necessary to learn embedded and single-chip microcomputer, and where is the value reflected?

In recent years, the phrase "software is king" has been widely spread. It is generally believed that the value of software knowledge is far greater than that of hardware. Subconsciously, learning software and engaging in software will make it easier to find higher-income and more promising jobs. Microcontrollers and embedded devices are generally classified as "hardware" and are "disgusted" by people. In addition, embedded and single-chip microcomputers are difficult to learn, and the learning cycle is relatively long, and they often feel "tortured", so that more and more The people who gave up this path are very responsible to tell you that it is incorrect to have this idea. Embedded and single-chip microcomputers are not the pure "hardware" direction that everyone knows, they are the close combination of hardware and software. of.

In the case of the serial port of the microcontroller, in fact, it is mainly composed of several circuits, the internal bus, the sending register SBUF, the sending buffer, the receiving buffer, etc. 99H refers to the special function register, which is 80H in the internal ROM. To the special function register area in FFH, 21 of them are used by 51 single-chip microcomputer, one of which is SBUF, and its address is at the address of 99H. In fact, it is physically two independent registers. It is for data transmission, and the receive buffer is mainly for data reception. In addition to these two special function registers, it also includes the sending controller, the receiving controller, and some shift registers, and Some interrupts and some circuits for control.

If you want to send a string of data, or send a frame of data, such as sending a 0X88 or sending a 88H, write the data 88H to the SBUF through the internal bus, it is actually two independent SBUF, but this independent The SBUF occupies the same address. In fact, it is distinguished by the instruction. When the instruction is directly written, the access is a serially sent register. If the read instruction is executed, the access is the serial receive register. When 88H is sent out, when you do the test yourself, you can make a short section of TSD and RSD, and you only need to write 88H to SBUF for self-send and self-receive, that is, assign this value to SBUF, and the register is like P0 port or P3 port. In the same way, assign 0X88 directly to him, write the data to SBUF, and after the data is written to him, the sending controller including the gate circuit will first convert the data into serial, and then add a start bit 0 to him, a Stop bit 1, you can add a parity bit, and then form a frame of data, which can be sent bit by bit through the TSD by the sending controller.

The clock system can control its baud rate, so that it can control the time of bit-by-bit transmission. The baud rate of 4800 takes 1/4800 second to send one bit. According to this baud rate, one bit can be sent. One bit is sent out and appears on the TXT line. In the internal circuit, it is 0 and 1. Once it appears on the pin, 0 will become a low level, 1 will become a high level, and it will become 0V And 5V, short-circuit it one by one, the bus is high when it is idle, once it is found to be low, it means that the start bit can be received, and the receiving circuit can control this The data is moved into this shift register bit by bit, and it comes in bit by bit according to the baud rate. After it comes in, each byte will be stored in SBUF. You need to know whether it is sending 0F88, you can put Read the contents of the SBUF. If you want to read the register, assign the register to him. When you receive it bit by bit, you have actually removed the start bit and stop bit when you enter the SBUF. Eight bits of data are stored, and these things are done by the hardware of the single-chip microcomputer for us, so in fact, as long as the function of the serial port is configured during programming, it is very convenient to complete the serial communication, that is, send and receive.

In order to use the serial communication interface, an initial configuration must be carried out for him. The receiver of the 51 single-chip microcomputer has a double-buffered structure. He actually has two receive buffers, representing the previous one read from the receive buffer. The second byte can be received before the four sections of data that have been received, that is, the data sent just now can be stored in this register. If this data has not been read, the next frame of data will come again. He also has a double buffer. If the data of this frame is also saved, this frame of data must be read in time. If not, he will overwrite the data of this frame and make a string When the line port is monitored, the data actually arrives in the SBUF, and some flag bits are provided to query, or use the interrupt method to know that the transmission is completed or the reception is completed. If you want to send a series of data, send this frame of data. It is necessary to send another frame of data, just write this data to SBUF. When the microcontroller is designed, it also gives you a reminder R flag bit, which is the reception flag bit. Once a frame of data is received, this R flag bit will be Automatic one, you can use the query or interrupt method, so that you know that a frame of data has been received, seize the time to read the data, you can make a receiving buffer, such as opening a buffer, that is, opening an array, you can put this The data is stored one by one, and then processed after receiving this string of data, or it can be processed while receiving. It is a different processing mechanism to receive this string of data, and then go to the specific To deal with it, different programs can be written according to the specific application.

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