Home  >  Article  >  What is the register that controls how the serial port works?

What is the register that controls how the serial port works?

WBOY
WBOYOriginal
2022-07-22 10:53:268862browse

The register that controls the working mode of the serial port is SCON, which is the serial port control register; SCON is used to control the selection, reception and transmission of serial communication methods, indicating the status of the serial port. SCON can be used as a byte Addressing can also be bit addressing, the byte address is "98H" and the address bits are "98H~9FH".

What is the register that controls how the serial port works?

The operating environment of this tutorial: Windows 10 system, DELL G3 computer.

What is the register that controls the working mode of the serial port?

The register that controls the working mode of the serial port is SCON

SCON (Serial Control Register) The serial port control register is used to control the mode selection, reception and transmission of serial communication, and indicates the status of the serial port. SCON can be either byte addressable or bit addressable. Its byte address is 98H and the address bits are 98H~9FH.

Structure:

What is the register that controls how the serial port works?

Working method (SM0 SM1)

(1) Mode 0 (SM0 SM1:0 0): The working mode 0 of the serial port is the shift register I/O mode, which can be connected to an external shift register, an expansion I/O port, or an external synchronous I/O device. Sending operation: When executing a "MOVSBUF,A" instruction, the sending operation is started, the shift pulse is output by TXD, and the data in SBUF is serialized by RXD. After sending 8-bit data, TI=1 is automatically set and an interrupt is requested. To continue sending, TI must be cleared by an instruction. Receiving operation: REN is the serial port reception enable control bit. When REN=0, reception is prohibited; when REN=1, reception is allowed. When the software sets REN to "1", it starts inputting data from the RXD port at the fosc/12 baud rate. When 8-bit data is received, the interrupt flag RI is set to "1". Before receiving data again, RI must be cleared to 0 by software.

(2) Mode 1 (SM0 SM1:0 1): The serial port is a 10-bit universal asynchronous interface. The data information sent or received in one frame is 10 bits, including 1 start bit "0", 8 data bits, and 1 stop bit "1". Send data: Data is output from the TXD port. When the data is written into the send buffer SBUF, the transmitter is started to send. After sending one frame of data, set the interrupt flag TI=1, apply for an interrupt, and notify the CPU that the next data can be sent. Receive data: First set REN = 1 (allow receiving data), the serial port receives data from RXD, when the sample transitions from 1 to 0, it is confirmed that the start bit is "0", and a frame of data starts to be received. When one frame of data is completed, set the interrupt flag RI=1, apply for an interrupt, and notify the CPU to take the received data from SBUF.

(3) Mode 2 (SM0 SM1:1 0): The serial port is an 11-bit asynchronous communication interface. Sending or receiving a frame of information includes 1 start bit "0", 8 data bits, 1 programmable bit, and 1 stop bit "1". Sending data: Before sending, first set TB8 to "parity bit" or "data identification bit" by software according to the communication protocol, and then write the data to be sent into SBUF to start the transmitter. The transmission process is started by executing any instruction with SBUF as the destination register, loading 8-bit data into SBUF, and also loading TB8 into the 9th bit of the transmission shift register, and then starting from TXD (P3.1) The port outputs one frame of data. Receiving data: Set REN=1 first to enable the serial port to receive data, and also clear RI to "0". Then, based on the status of SM2 and the status of the received RB8, it is decided whether the serial port sets RI=1 after the information arrives, and applies for an interrupt to notify the CPU to receive the data. When SM2=0, regardless of whether RB8 is "0" or "1", RI=1 is set, and this serial port will receive the sent information. When SM2=1 and RB8=1, it means that in the case of multi-machine communication, the received information is "address frame". At this time, set RI=1, and the serial port will receive the incoming address. When SM2=1 and RB8=0, it means that in the case of multi-machine communication, the received information is a "data frame", but it is not sent to the slave. At this time, RI is not set to "1", so the received information in SBUF The data frame will be lost.

(4) Mode 3 (SM0 SM1:1 1): It is an 11-bit asynchronous communication mode with variable baud rate. Except for the difference in baud rate, the other modes are the same as Mode 2.

For more related knowledge, please visit the FAQ column!

The above is the detailed content of What is the register that controls how the serial port works?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:What file format is prt?Next article:What file format is prt?