Programming Serial Interrupts using 8051 Microcontroller

Serial Interrupt using 8051
Serial interrupt in 8051 was used to create an interrupt routine by means of sending a character through the UART. It plays a significant role in Embedded system Design where the controller has to perform a certain tasks based on the incoming character through the UART. Before going through this tutorial you must be familiar with Serial Communication in 8051 Microcontroller to get a clear idea about Serial Communication.


IE Register

This IE register is responsible for all activating all the interrupts in 8051. For serial Interrupt we need to activate EA which is enabling activating usage of interrupts and ES for activating Serial Interrupts. So the value of IE will be
IE= 1001 0000
IE= 0x90

Every Interrupt Service Routine must be inside a sub routine followed by the respective interrupt numbers. The below table will shows the interrupt numbers for respective interrupts in 8051.
Interrupt Number table


  1. Initiate Timer to generate Baud rate for the Serial communication, and TH1 register should be loaded with the value 0xFD to generate baud rate of 9600 bps.
  2. Initiate SCON register to select the mode of serial communication, i have chosen Mode 1 since i have used timer 1 for Baud rate generation.
  3. Load the value 0x90 into the IE register to initiate the Serial interrupt.
  4. Write sub routine for the interrupt with the interrupt number 4.
Usually every key you press in your hyper terminal reaches the controller as a Hex value. This will also allow you to place conditional statements inside the subroutine to make the controller to respond only to specific key press from the terminal rather than from all the keys.


The code was built using Keil C Software

  1. #include<regx51.h>
  2. void main()
  3.   {
  4.    TMOD=0x20;                                //Choosing Timer mode
  5.    TH1=0xFD;                                   //Selecting Baud Rate
  6.    SCON=0x50;                               //Serial mode selection
  7.    TR1=1;
  8.    IE=0x90;                                      //Enabling Serial Interrupt
  9.    while(1);
  10.    }
  11. void ser_intr(void)interrupt 4        //Subroutine for Interrupt
  12.  {
  13.   char c;
  14.   c=SBUF;  
  15.   IE=0x00;                      //Turning off interrupt to prevent recursion
  16.    if(c==0x0d)
  17.    {
  18.    P0=~P0;                                
  19.    SBUF='A';                 //Sending back "ACK" as   Acknowledgement 
  20.    while(TI==0);
  21.    TI=0;
  22.    SBUF='C';
  23.    while(TI==0);
  24.    TI=0;
  25.    SBUF='K';
  26.     while(TI==0);
  27.     TI=0;
  28.     }
  29.    RI=0;
  30.    IE=0x90;                            //Reactivating the interrupt
  31.   }
All the initialization of the Timers and Interrupts took place in the main() function of the program. In the subroutine "ser_intr" i have used a condition to check received variable from interrupt as "0x0D". This "0x0D" is a equivalent of "Enter" key in the keyboard, so whenever you press enter the Microcontroller toggle the port 0 and Send ACK back to the terminal.

You can use condition for any key in the keyboard by identifying the HEX values of the respective keys in your keypad. This will help you to perform specific tasks with each key press.

Like this tutorial? Share this with others through social sites and don't forget to follow us there. Post your queries below and we get back to you as soon as we can.

Programming External Interrupts in 8051 Microcontroller

External Interrupts in 8051 Microcontroller
External interrupts paves way for the users to interfere the process of Microcontroller externally and force it to execute a specific set of commands. Since the interrupt is generated from a external source it is named as External interrupts and here we are about to use a simple switch button to generate the interrupt to the Microcontroller.

I assume you are familiar with the concept, working and registers involved in the Interrupts, if not kindly go through this 8051 Interrupt introduction and programming

16x2 LCD and Keypad Interface with PIC16F877A Microcontroller

Design of LCD and Keypad Interface to PIC Mircocontroller
Interfacing of LCD and Keypad are one of the important interfacing concepts of PIC microcontroller since both the input and output element can form a complete embedded system design. This tutorial is about teaching you how to get input input values from keypad by polling method and display the input into a 16x2 LCD.