Serial Communication in 8051 Microcontroller

Serial Communication using 8051

Microcontrollers need to communicate with external devices such as sensors, computers and so on to collect data for further processing. Data communication generally done by means of two methods : Parallel and Serial mode. In the parallel mode data bits are transferred in a fast manner using more number of lines. But when comes to a Microcontroller system, we cannot afford to dedicate many lines for data transfer. So UART or Serial communication in 8051 microcontroller will allow the controlller to send and receive data’s just byusing two pins

Serial Communication uses only two data lines to establish communication between Microcontroller and external devices. In this communication data bits are transferred one bit at a time, so the process will be slow. This article describes the Interfacing of  8051 with  PC to establish communication through a serial port RS232.

RS232 AND MAX232:

To establish communication between a controller and PC, we must use a serial I/O standard RS-232 which was widely used in PC and several devices. PC works on the RS-232 standards which operates at a logic level of -25V to +25V. But Microcontrollers use TTL logic which works on 0-5V which is not compatible with the RS-232 standards.

MAX232 is a specialized IC which offers intermediate link between the Microcontroller and PC. The transmitters of this IC will convert the TTL input level to the RS-232 Voltage standards. Meanwhile the receivers of this IC will convert RS-232 input to 5V TTL logic levels. Read the complete working of  MAX232 IC.


SCON Register

SCON is a bit addressable register is used to set the mode in which the serial communication takes in the controller. The above figure shows the configuration of the SCON register. The functions of each bit are listed below.

Serial Mode of 8051

SM0, SM1:  Serial Mode control Bits

SM2: Multiprocessor mode control bit, logic 1 enables Multi processor mode and 0 for normal mode.

REN: Enables Serial reception. If set it enables the reception, otherwise the reception is disabled.

TB8: It is the 9th bit of the data that is to be transmitted.

RB8: It is used in modes 2 and 3, it is the 9th bit received by the microcontroller.

TI: It is known as Transmit Interrupt flag which is set by the hardware to indicate the end of a transmission. It has to be cleared by the software.

RI: It is  known as Receive Interrupt flag which is set by the hardware to indicate the end of a reception. It has to be cleared by the software.


It is defined as number of bits transmitted or received per second and usually expressed in Bits per second bps. For mode 0 and mode 2 the baud rate is determined by means of 1/12, 1/32 or 1/64 of the crystal frequency whereas for mode 1 and 3 it is determined by means of timer 1.

Baud Rate by Timer1

Learn how to configure Timers in 8051.


It is a 8 bit register that holds the data needed to be transmitted or the data that is received. The serial port of the 8051 is full duplex so the microcontroller manages to transmit and receive data into the register simultaneously.


void initialize()     // Initialize Timer 1 for serial communication
     TMOD=0x20;    //Timer1, mode 2, baud rate 9600 bps
     TH1=0XFD;      //Baud rate 9600 bps
     TR1=1;             //Start timer 1
void receive()        //Function to receive serial data
    unsigned char value;
    while(RI==0);       //wait till RI flag is set
    RI=0;                    //Clear the RI flag
void transmit()       // Funtion to transmit serial data
    SBUF='o';            //Load  'o' in SBUF to transmit
    while(TI==0);      //Wait till TI flag is set or data transmission ends
    TI=0;                  //Clear TI flag
void main()

Initialize – Initialize timer for baud rate and set mode for serial transmissionThe above program is coded in such a way to receive a character from PC and in return transmits “ok” to it. This code have three parts initialize,receive and transmit to perform the process of serial communication. This can be tested using Hyperterminal software after connecting your controller to PC through RS232.

  • Receive – Enable controller to receive data bit from PC.
  • Transmit – Enable transmission of data from 8051 to PC.  

Ask your query

2 Comment threads
1 Thread replies
Most reacted comment
Hottest comment thread
3 Comment authors
himanshu kathuriaFrank DonaldBonham Recent comment authors
newest oldest most voted
Notify of
himanshu kathuria
himanshu kathuria

How can I use 8051 in shIFT register serial communication mode


thank you for the code