INTERRUPTS 8051 MICROCONTROLLER HOW to use external interrupt

USING INTERRUPTS 8051 MICROCONTROLLERInterrupts are used for communication between the microcontroller and the external device. We already explained the purpose of interrupts use in previous article of interrupts use in PIC microcontroller in detail. Now the purpose of this article to explain how to use interrupts in 8051 microcontroller. Before reading this article you should know how to use keil for programming of 8051 and how to use input output ports of 8051 microcontroller.


8051 microcontroller can recognize six different types of events that request the microcontroller to stop to perform the current program temporarily and make time to execute a special code. The interrupts sources present in 8051 microcontroller are:

  • Reset interrupt
  • Timer0 overflow interrupt TF0
  • Timer1 overflow interruptTF1
  • External hardware interrupt INT0
  • External hardware interrupt INT1
  • Serial communication interrupt (RI/TI)

Timers and Serial interrupts are internally generated by the microcontroller while the external interrupts are generated when externally interfacing devices or switches are connected to the microcontroller. These external interrupts can be edge triggered or level triggered.

8051 microcontroller INTERRUPTS SERVICE

A fixed memory area is assigned for each interrupt inside the microcontroller. The Interrupt Vector Table contains the starting address of the memory location of every interrupt. When an interrupt occurs, the controller transfers the content of program counter into stack. Then it jumps to the memory location which is specified by Interrupt Vector Table (IVT). The code written on that memory area by the programmer starts its execution. That code is called Interrupt Service Routine (ISR) or interrupt handler.

INTERRUPTS 8051 microcontroller VECTOR TABLEtypes of interrupts in 8051 microcontroller


When reset pin is activated, controller jumps to execute code from 0000H memory location. Mostly it is not used. It is also known as power on reset.


Two timers (T0 and T1) are present in 8051 microcontroller which is responsible for Timer interrupt. A timer interrupt informs the microcontroller that corresponding Timer has finished the counting.Memory locations 000BH and 001BH in the interrupt vector table belongto Timer0 and Timer1 respectively.


There are two external interrupts (INT0 and INT1) to serve external devices. Pinnumbers 12 and 13 in port 3 are for the external hardware interrupts.Both these interrupts are active low. An external interrupt informs the microcontroller that an external device needs its routine service.Memory locations 0003H and 0013H in the interrupt vector table belong to INT0 and INT1 respectively.


This interrupt is used for serial communication. It has a single interrupt that belongs to both receive andtransmit. When enabled, it notifies the controller whether a byte has been received or transmitted.The interrupt vector table location 0023H belongs to this interrupt.

  • REGISTER CONFIGURATION (for interrupt selection):

Now we have to specify the microcontroller that which interrupts must be served. All of the above interrupts can be used by configuringsome bit in special function register known as Interrupt Enabled (IE) register. This registers enable or disable the various available interrupts.

INTERRUPTS 8051 microcontroller ENABLE (IE) REGISTERinterrupt enable register in 8051

EA:     Enable Interrupt

EA bit must be set to 1 to enable any of the interrupts. By default all the interrupts are in disabled mode.
EA = 1 Enable Interrupt
EA = 0 Disable Interrupt

ET2:   Timer2 interrupt enable bit

Enable or disable Timer2 overflow or capture interrupt only in 8052. In AT89C51, there are only two timers, so ET2 is not used.

ES:      Serial port interrupt enable bit

Enable or disable Serial port interrupt.

ET1:   Timer1 interrupt enable bit

ET0 = 1, Enable Timer1 overflow interrupt
ET0 = 0, Disable Timer1 overflow interrupt.

EX1:   External interrupt INT1 enable bit

EX1 = 1, Enable INT1
EX1 = 0, Disable INT1

ET0:   Timer0 interrupt enable bit

ET0 = 1, Enable Timer0 overflow interrupt
ET0 = 0, Disable Timer0 overflow interrupt

EX1:   External interrupt INT0 enable bit

EX1 = 1, Enable INT0
EX1 = 0, Disable INT0


After the selection of specific interrupt, next step is to specify the microcontroller that what to do when an interrupt occurs. We write a subroutine or function for the interrupt which is the ISR. It is automatically called when an interrupt occurs. The definition of subroutine must have the keyword interrupt with the interrupt number. Each interrupt has its specific subroutine number.


Since we already discussed how to use timers in 8051, so in this article we will just learn how to use external interrupts in 8051. External interrupts are received from the external interfaced devices at INTx pins of the microcontroller. These can be level triggered or edge triggered which is decided by TCON register.

For level triggered:      interrupt is enabled for a low at INTx pin.

For edge triggered:     interrupt is enabled for a high to low transition at INTx pin.

TCON REGISTER:external interrupt control register

Setting the IT0 and IT1 bits make the external interrupt 0 and 1 edge triggered respectively. By default these bits are set to 0, so external interrupt is level triggered.

IT1:     External interrupt1 signal type control bit.

IT1 = 1, to enable external interrupt 1 to be triggered by a falling edge signal
IT1 = 0, to enable a low level signal on external interrupt 1 to generate an interrupt

IT0:     External interrupt 0 signal type control bit, same as IT1.

IT0 = 1, to enable external interrupt 0 to be triggered by a falling edge signal
IT0 = 0, to enable a low level signal on external interrupt 1 to generate an interrupt


  1. Enable external interrupt 0 or external interrupt 1 by configuring IE register. For this we have to give command as:

For INT0:        IE=0x81;

For INT1:        IE=0x84;

  1. Now we have to write routine for external interrupt.For EX0 (INT0), the interrupt number is 0 and for EX1 (INT1) interrupt number is 1.

For using external interrupt INT0 we have to write routine as:

void ISR_ex0(void) interrupt 0

For using external interrupt INT1 we have to write routine as:

void ISR_ex1(void) interrupt 2

  1. For edge triggered external interrupt, IT0 or IT1 is set to 1.

For INT0:        IT0=1;

For INT1:        IT1=1;

PROTEUS SIMULATIONS external interrupts 8051 microcontrollerexternal interrupts  8051 microcontroller

We used the external interrupt INT0 of 8051 microcontroller. Port 2 is used to monitor the output. In beginning, alternate values are passed to P2 LEDs. When external interrupt is given through a push button, Interrupt service routine will start to execute and LEDs output will get toggle for 1 sec. This 1 sec delay is given through timer 0 when it is in mode 1.

CODE 0f external interrupts 8051 microcontroller


sbit led1= P2^0;

sbit led2= P2^1;

sbit led3= P2^2;

sbit led4= P2^3;

void ISR_ex0(void);

void Delay();

void main()

P0 = 0x00;    // Make all pins zero

        P1 = 0x00;    // Make all pins zero

        P2 = 0x00;    // Make all pins zero

        P3 = 0x04;    // making Port3 pin 2 high

  IE=0x81;             // Enable INT0

  IT0=1;                 // Set Falling Edge Trigger for INT0



                led1= 1;

                led2= 0;

                led3= 1;

                led4= 0;



void ISR_ex0(void) interrupt 0     // ISR for external interrupt INT0








void Delay()



TMOD = 0x01;                    // Timer0 mode1



               TH0=0xF8;              //initial values for 1sec delay


               TR0 = 1;               // timer0 start

while (TF0 == 0);   // check overflow condition

TR0 = 0;               // Stop Timer

TF0 = 0;               // Clear flag



This is all about how to use interrupts of 8051 microcontroller. How to use external interrupt of 8051 microcontroller. If you feel issue with programming and simulation, please let us know with your comments. Next time I will come with more interesting tutorials on 8051 microcontroller and their applications.

1 thought on “INTERRUPTS 8051 MICROCONTROLLER HOW to use external interrupt”

  1. Hi, can u rearrange the code to turn on led at starting point for 1 second and after switch on the led need to off for 2 second. Then back to on stage.


Leave a Comment