SBUF and SCON register in 8051 Microcontroller

In the 8051 microcontroller, the Serial Control (SCON) and Serial Buffer (SBUF) registers are crucial for serial communication. 8051 Microcontroller has a serial port which is full duplex which allow it can transmit and receive simultaneously.

The port is a receive buffered. Hence it can start receiving byte before the previous bytes has already been read from the register SBUF. There will be collision if the byte arrives in SBUF before the previous byte is read from it.

The serial port receive/transmit registers are both accessed at SBUF. The serial port can operate in 4 modes as mentioned below. Let's explore these registers in detail.

Format of SCON register in 8051

The SCON register is an 8-bit register used to control the operation of the serial port. It contains bits for configuring the serial port's mode, handling interrupt flags and controlling data transmission and reception.

The serial port control and status register is the Special Function Register SCON. This register contains not only the mode selection bits, but also the 9th data bit for transmit and receive (TB8 and RB8), and the serial ports interrupt bits (TI and RI). SCON is bit addressable. Here is the bit structure of the SCON register.

SCON register

SM0-SCON.7- Serial port mode specifier(Table-1)
SM1-SCON.6- Serial port mode specifier(Table-1)
SM2-SCON.5- Enable multiprocessor communication in modes 2/3.
REN-SCON.4- Set/clear by software to enable/disable reception
TB8-SCON.3- The 9th bit that will be transmitted in mode2/3, set/clear by software
RB8-SCON.2- In mode2/3, it is the 9th bit that was received. In mode 1, if SM2=0, RB8
is the stop bit that was received, In mode 0, it is not used.
TI-SCON.1- Transmit Intterupt flag, set by hardware at the end of 8th bit time in mode 0,
at the beginning of the stop bit in the other modes, it must be cleared by software.
RI-SCON.0- receive Interrupt flag, set by hardware and must be cleared by software.

Table-1

Based on SM0 and SM1 various baudrates are selected as shown in the table below.


SM0 SM1 Mode/Description/Baud rate
0 0 0,shift register,(Fosc./12)
0 1 1,8 bit UART,Variable
1 0 2,9 bit UART,(Fosc./64) OR (Fosc./32)
1 1 3,9 bit UART, Variable

Function of SBUF register in 8051

The SBUF register is an 8-bit register used for serial data transmission and reception. It acts as a buffer, holding the data to be transmitted or the data that has been received.

SBUF (Serial Buffer):
• Writing to SBUF loads the data to be transmitted into the transmit buffer.
• Reading from SBUF fetches the received data from the receive buffer.

Microcontroller Serial Port Initialization C program

microcontroller serial port initialization program

As shown in the C program, it initializes timer 0 for delay and timer 1 for baud rate of 9600 bps.

Transmission via SBUF

SBUF='S'; while(!TI); TI=0; /* One character at a time/*

for(i=0;i<max;i++)
{

SBUF=transmit_array[i++]; /* Transmitting character array/*
while(!TI); TI=0;

}

Summary

➨SCON Register: Configures the serial port's mode, controls data transmission and reception and handles interrupt flags.
➨SBUF Register: Acts as a buffer for serial data transmission and reception.
➨Understanding these registers is essential for implementing and managing serial communication in 8051-based systems.


8051 Microcontroller Related Posts