Yep… @Joseinnewworld back at it — added 3 more #NFTs to his collection yesterday 😄 At this point, I’m convinced he’s got my wallet bookmarked. Big thanks for the steady love, legend 🙌 #NFTcollector #ConsistentSupport #eCash $XEC #cryptocurrency pic.twitter.com/Q1t2hzsf09
— NFToa (@nftoa_) July 14, 2025
The MCS-51 has the ability to communicate serially via the RXD and TXD pins. One thing to keep in mind is that the communication voltage levels of both serial pins use TTL voltage levels.
1. Standard Serial Interface
In principle, serial communication is communication where data transmission is done per bit. Serial interfaces only require a few lines (usually only 2 lines) so they save more pins when compared to parallel interfaces.
There are two types of serial communication, asynchronous serial and synchronous serial. Synchronous serial is communication where there is only one party (sender or receiver) that generates the clock and sends the clock together with the data. An example of the use of synchronous serial is in keyboard data transmission.
Asynchronous serial is a communication where both parties (sender and receiver) each produce a clock but only data is transmitted, without a clock. In order for the data sent to be the same as the data received, both clock frequencies must be the same and there must be synchronization. After synchronization, the sender will send its data according to the sender's clock frequency and the receiver will read the data according to the receiver's clock frequency. An example of the use of asynchronous serial is the Universal Asynchronous Receiver Transmitter (UART) used on the computer's serial port (COM).
The MCS-51 supports asynchronous communication, and three of the four serial modes the MCS-51 has are UART compatible.
2. Serial Register
The register used to manage serial communication is in Serial Control (SCON).

Figure 35. SCON Bit Allocation

Table 13. Serial Port Control

Table 13. Serial Port Control (continued)
The following is an explanation of each SCON bit as it relates to the serial port:
a. SM0 & SM1
Serial communication mode selector.

Table 14. Serial Communication Modes
Baud rate in modes 1, 2, and 3 can be multiplied by setting the value '1' to SMOD (in SFR PCON). Variable baud rate is the baud rate generated by Timer 1 (baud rate will be discussed in section 7.4).
b. SM2
If SM2 has a value of '1' then multiprocessor communication is enabled with the conditions listed in table 15.

Table 15. Multiprocessor Communication Modes
In mode 0, the SM2 value should be '0'.
c. REN
REN must be set to '1' to enable data reception. If REN is set to '0', there will be no data reception.
d. TB8
TB8 is the 9th bit sent in mode 2 or 3. The value of this bit is set by the user program.
e. RB8
RB8 is the 9th bit received in mode 2 or 3. In mode 1, RB8 is the stop bit received. In mode 0, RB8 is not used.
3. Operation Mode
MCS-51 has 4 serial communication modes. Mode 0 is synchronous serial (shift register), while the other three modes are asynchronous serial (UART). In all modes, sending is done if there is an instruction that fills the SBUF register value. While at the time of reception, the received data will be stored in the SBUF register.
3.1. MODE 0
Mode 0 is an 8-bit shift register where data is sent and received through the RXD pin while the clock is sent and received through the TXD pin. Sending 8-bit data is done by sending the Least Significant Bit (LSB) first.
In mode 0, the baud rate used is 1/12 of the oscillator frequency.
3.2. MODE 1
In mode 1, the amount of data sent is 10 bits consisting of a start bit, 8 data bits (LSB first), and a stop bit. In the receiving process, the stop bit value will be entered into RB8 automatically. In the sending process, the stop bit will be given a value of '1' automatically.
In mode 1, the baud rate used can be set via Timer 1.
3.3. MODE 2
In mode 2, the amount of data sent is 11 bits consisting of start bit, 8 data bits (LSB first), 9th bit, and stop bit. In the sending process, the value of the 9th bit can be set by filling in the TB8 value. In the receiving process, the 9th bit will be entered into RB8 automatically.
In mode 2, the baud rate that can be used is 1/64 of the oscillator frequency or 1/32 of the oscillator frequency if SMOD is '1'.
3.4. MODE 3
Mode 3 is almost the same as mode 2. The difference is in the baud rate used. If mode 2 uses a fixed baud rate, mode 3 uses the baud rate generated by Timer 1.
4. Baud Rate
Baud rate is the clock frequency used in sending and receiving data. The baud rate unit is generally bps (bits per second), which is the number of bits that can be transmitted per second.
The baud rate for mode 0 is fixed according to the formula in equation 1.

While the baud rate for mode 2 has 2 variations depending on the SMOD condition. The baud rate formula for mode 2 is in equation 2.

Baud rate for mode 1 and 3 is generated by Timer 1. Baud rate setting for mode 1 and 3 can be done by changing the SMOD, TMOD, and TH1 values. Baud rate value can be obtained by using equation 3.

Generally Timer 1 is operated in mode 2 (8-bit Auto Reload) so that equation 4 is obtained.

Based on equation 4, the user can calculate the TH1 value needed if the desired baud rate is known using equation 5.

One thing to note in setting the baud rate is that the baud rate and TH1 values must be exact and not rounded. For high-speed serial communication, rounding these values can cause chaos in the sending or receiving process. If there is a fractional value, the user is advised to replace the oscillator with the appropriate frequency. For low-speed communication, the tolerance for error is large enough that rounding is still allowed.
Suppose the desired baud rate is 19200 bps with an oscillator frequency of 11.0592 MHz. By entering this data into equation 5, equation 6 will be obtained.

If 2SMOD is '1', then TH1 will be 254.5. To avoid fractional TH1, 2SMOD must be '2' (SMOD is '1') so that TH1 is 253 or FDh.
To get a slow baud rate, the user can operate Timer 1 in mode 1 with the formula in equation 7.

Some commonly used baud rate configurations are listed in Table 16.

Table 16. Baud Rate Values and Configuration
5. Serial Initialization
The initialization process aims to determine the serial communication mode and baud rate used.
Registers that must be set up first include:
5.1 SCON
The first step is to determine the mode to be used (mode 0, 1, 2, or 3), the data reception capability, and the value of the 9th bit.
For example, if the mode used is mode 1 with the ability to receive data but without multiprocessor communication, then the instructions are as follows:
MOV SCON, #01010000b
atau
MOV SCON, #50h
atau
SETB SM1
SETB REN5.2. TMOD, TH1 and/or TL1, PCON, and TCON
If serial communication is used in mode 1 or 3, then the next step is to determine the baud rate.
For example, Timer/Counter 1 is used as a timer in mode 2 to generate a baud rate of 19200 bps, then the instruction is as follows:
MOV TMOD, #00100000b
MOV TH1, #0FDh
MOV PCON, #10000000b
MOV TCON, #01000000b
atau
MOV TMOD, #20h
MOV TH1, #0FDh
MOV PCON, #80h
MOV TCON, #40h
atau
MOV TMOD, #20h
MOV TH1, #0FDh
MOV PCON, #80h
SETB TR13. IE and/or IP
If the programmed serial communication is to be used as an interrupt source, then IE and/or IP must also be set.
For example, if serial communication is used as a high priority interrupt source, then the instruction is as follows:
MOV IP, #00010000b
MOV IE, #10010000b
atau
MOV IP, #10h
MOV IE, #90h
atau
SETB PS
SETB ES
SETB EAUnderstanding Serial Ports
Generally, people always assume that the serial port on the MCS51 is a UART that works asynchronously, but few realize that the serial port can also work synchronously, even though a serial port that works synchronously is an excellent means of adding input/output for a microcontroller.

Serial Port / Serial Port
There are 2 known ways of serial data transmission. The two methods are distinguished by the pulse signal (clock) used to 'push' the serial data, if the clock is sent together with the serial data, the method is called synchronous serial data transmission. While in asynchronous serial data transmission, the clock is not sent together with the serial data, the data receiver circuit must generate its own clock to drive the serial data.

Serial Communication With Computer
The MCS51 serial port can be used in 4 different working modes. Of the 4 modes, 1 mode works synchronously and the other 3 work asynchronously. In summary, the four working modes can be distinguished as follows:
Mode 0
This mode works synchronously, serial data is sent and received via pin P3.0 (RxD), and pin P3.1 (TxD) is used to channel the serial data drive clock generated by the MCS51.
Data is sent/received 8 bits at a time, starting from the bit with the smallest weight (bit 0) and ending with the bit with the largest weight (bit 7). The data transmission speed (baud rate) is 1/12 of the crystal oscillator frequency.
Mode 1
This mode and the following modes work asynchronously, data is sent via pin P3.1 (TxD) and received via pin P3.0 (RxD).
In Mode 1, data is sent/received 10 bits at a time, starting with 1 start bit, followed by 8 data bits starting from the bit with the smallest weight (bit 0), ending with 1 stop bit. In MCS51, which functions as a receiver, the stop bit is stored in RB8 in the SCON register. The data transmission speed (baud rate) can be adjusted according to needs.
This mode is commonly known as UART (Universal Asynchronous Receiver/Transmitter).
Mode 2
Data is sent/received 11 bits at a time, starting with 1 start bit, followed by 8 data bits starting from the bit with the smallest weight (bit 0), then the 9th bit which can be further adjusted, ending with 1 stop bit.
On the MCS51 which functions as a sender, bit 9 comes from the TB8 bit in the SCON register. On the MCS52 which functions as a receiver, bit 9 is stored in the RB8 bit in the SCON register, while the stop bit is ignored and not stored. The data transmission speed (baud rate) can be selected between 1/32 or 1/64 of the crystal oscillator frequency.
Mode 3
This mode is the same as Mode 2, except that the data transmission speed (baud rate) can be adjusted according to requirements, as with Mode 1.
In asynchronous mode (Mode 1, Mode 2 and Mode 3), the MCS51 serial port works in full duplex, meaning that at the same time this serial port can send data and receive data.
The SBUF register is a serial port connecting register. In the four modes above, all instructions that cause changes to the contents of the SBUF will cause the serial port to send data out of the MCS51. In order for the serial port to receive data, the REN bit in the SCON register must be '1'. In mode 0, the data reception process begins with the CLR RI instruction, while in other modes the data reception process begins with the start bit which is '0'. Data received by the serial port from outside the MCS51 is taken with the MOV A,SBUF instruction.
Fetching data from SBUF and storing data into SBUF actually works on two different registers, even though the register name is the same as SBUF.
MCS51 Serial Port Registers
MCS51 is equipped with 2 registers and several additional bits for serial port users.

SBUF is an SFR (Special Function Register) located in the internal data memory with the number $99. SBUF has a dual function, data stored in SBUF will be sent out of MCS51 via the serial port, while data from outside MCS51 received by the serial port is also taken from SBUF. So even though it only occupies one internal data memory number (number $99), SBUF actually consists of 2 different registers.

SCON is an SFR (Special Function Register) located in the internal data memory with the number $98, which is the main register for regulating the work of the MCS51 serial port. After resetting all bits in SCON are '0'.
1.) Bit SM0 and bit SM1 (bit 7 and bit 6 in the SMOD register) are used to determine the working mode of the serial port. After reset these two bits are '0'
2.) The REN bit (bit 4) is used to activate the serial port's ability to receive data. In mode 0, the RxD pin (pin P3.0) is used to send serial data (REN='0') and also to receive serial data (REN='1'). This property is also carried over when the serial port works in modes 1, 2 and 3, although in these modes the RxD pin is only used to send data, so that the RxD pin can be used to receive data, REN='1' must first be made. After resetting the REN bit is '0'.
3.) In working mode 2 and working mode 3, the serial port works with 9 bits of data, the SBUF with a capacity of 8 bits is not enough for this purpose. The ninth bit to be sent first is placed in TB8 (bit 3), while the RB8 bit (bit 2) is the bit used to accommodate the ninth bit received by the serial port.
4.) In working mode 1, RB8 is used to accommodate the received stop bit, so if RB8 has a value of '1' then the data is received correctly, conversely if RB8='0' it means a framing error has occurred.
If SM2 bit (bit 5) is set to '1', if a frame error occurs, RI will not be '1' even though the SBUF already contains data from the serial port.
This 9th bit can be used as a parity bit, only the parity bit sent must be determined by the program itself and placed on TB8, and the parity bit received on RB8 is used to determine data integrity by the program as well. Unlike in standard UART, all of that is done by the hardware in the UART IC.
5.) The TI bit (bit 1) is a marker that is equivalent to the TDRE (Transmitter Data Register Empty) marker that is commonly found on standard UARTs. After the serial port has finished sending data stored in the SBUF, the TI bit will be '1' by itself, this bit must be zeroed by the program so that it can be used to monitor the state of the SBUF in the next data transmission.
The following SerialOut subroutine is used to send serial data, applicable to all serial port modes. Line 02 waits for TI to become '1', intended to ensure that the previous data transmission has been completed.
The data to be sent has previously been stored in A, in line 03 the data is sent via the serial port by placing it in the SBUF. So that TI can be used to monitor the state of the SBUF on the next data transmission, in line 04 TI is set to zero.
01: SerialOut:
02: JNB TI,$ ; tunggu data sebelumnya selesai dikirim
03: MOV SBUF,A ; kirim data baru
04: CLR TI ; petanda ada pengiriman baru
05: RET6.) The RI bit (bit 0) is a marker that is equivalent to the RDRF (Receiver Data Register Full) marker that is commonly found on standard UARTs. After the SBUF receives data from the serial port, the RI bit will be '1' by itself, this bit must be zeroed by the program so that it can be used to monitor the state of the SBUF in receiving the next data.
The following SerialIn subroutine is used to receive serial data, applicable to all serial port modes. Line 02 waits for RI to become '1', intended to ensure that there is new data received on the SBUF. In line 03 the data on the SBUF is fetched to A. So that RI can be used to monitor the state of the SBUF on the next data transmission, in line 04 RI is set to zero.
01: SerialIn:
02: JNB RI,$ ; tunggu SBUF berisi data baru
03: MOV A,SBUF ; ambil data
04: CLR RI ; pentanda data sudah diambil
05: RET
