Serial Interrupt Programming in 8051 Microcontroller

Serial Interrupt using 8051

Serial interrupt programming in 8051 plays a significant role since it was used to perform interrupt operation through UART protocol. 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-8051

IE= 1001 0000This 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= 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
void main()
   TMOD=0x20;                                //Choosing Timer mode
   TH1=0xFD;                                   //Selecting Baud Rate
   SCON=0x50;                               //Serial mode selection
   IE=0x90;                                      //Enabling Serial Interrupt
void ser_intr(void)interrupt 4        //Subroutine for Interrupt
  char c;
  IE=0x00;                      //Turning off interrupt to prevent recursion
   SBUF='A';                 //Sending back "ACK" as   Acknowledgement 
   IE=0x90;                            //Reactivating the interrupt

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.

The following two tabs change content below.
Frank Donald

Frank Donald

Junior Network Engineer at Tata Communications
Frank Donald is an Electronics and Communication Engineer who loves building stuff in his free time. Video games, blogging and programming are the things he loves most

Ask your query

6 Comments on "Serial Interrupt Programming in 8051 Microcontroller"

newest oldest most voted
Notify of

when i enter a character from keyboard code works ,but i cannot see it on the hyperterminal what i entered when using uart interrupts


are we able to use the incoming character the one which causes the interrupt?

Frank Donald

Of course you can, read the value like i did “c=SBUF” in the 14th line and then use it for any purpose.


Thanks great tutorial

Frank Donald