UART (Universal Asynchronous Receiver Transmitter) or USART (Universal Synchronous Asynchronous Receiver Transmitter) are one of the basic interfaces which you will find in almost all the controllers. This interface provides a cost effective simple and reliable communication between one controller to another controller or between a controller and PC.
Serial Communication
Since IBM PC are widely used to communicate with the 8051-based systems, We will emphasize serial communications of 8051 with the COM port of the PC. To allow the data transfer between the PC and an 8051 systems without any error, the baud rate of the TRX and the RCX should match.
SBUF Register
SBUF is an 8-bit register used solely for serial communication in the 8051. For a Byte of data to be transferred via TxD line, it must be placed in the SBUF register. Similarly, SBUF can holds the byte of data when it is received from the 8051 RxD line. SBUF can be accessed like any other register of 8051.
MOV SBUF,#D MOV SBUF,A MOV A,SBUF
SBUF
The moment the data is written into SBUF, it is framed with the start and stop bits and transferred over the TxD line.
SM0
TI
RI
0
1 1
1
0 1
SCON
SM2: This bit (D5) enables the Multiprocessing capability - Not using 8051 in multiprocessor environment, so make SM2=0 REN: Receive enable bit. Set to one enable reception.
REN =1 Enable 8051 to transfer and receive the data The instruction is SETB SCON.4 REN=0 The receiver is disabled The instruction is CLR SCON.4
Importance of TI Flag
The Byte character to be transmitted is written in the SBUF register. It transfers the start bit. The 8-bit character is transferred one bit at a time. The stop bit is transferred. It is during the transfer of the stop bit that the 8051 raises the TI flag (T1=1), indicating that the last character was transmitted and it is ready to transfer the next character. By monitoring the TI flag ,We make sure that we are not overloading the SBUF register.
Importance of TI Flag
If we write another byte into SBUF register before T1 is raised, the un-transmitted portion of the previous byte will be lost. After SBUF is loaded with a new byte, the T1 flag bit must be forced to 0 by the CLR T1 instruction in order for this new byte to be transferred.