What is an interrupt?
An interrupt is an asynchronous signal that needs attention. An interrupt stops the CPU of a microcontroller, leaving the tasks that it is currently doing, to give attention to the interrupt signal. Once the attention has been given to the interrupt signal, the CPU goes back to its unaccomplished task before the interrupt has occured and continues the task.
The Interrupts of AT89C2051
The interrupts of AT89C2051 is compatible with the interrupts of the original 8051 microcontroller. It has 6 interrupts sources ( 5 interrupts + RESET). The interrupt sources of AT89C2051 are the following:
| Interrupt | Source | Priority Number | |
| 1 | RESET | RST | N/A |
| 2 | External Interrupt 0 | IE0 | 0 |
| 3 | Timer 0 Interrupt | TF0 | 1 |
| 4 | External Interrupt 1 | IE1 | 2 |
| 5 | Timer 1 Interrupt | TF1 | 3 |
| 6 | UART Interrupt | RI or TI | 4 |
Please note that in this tutorial, we will not consider the interrupt from RESET.
The table above shows the interrupt sources of AT89C2051 and their respective interrupt priority number. Knowing the priority number is important specially if two different interrupt sources occur at the same time.
Interrupt Enable Register
The Interrupt Enable (IE) register is responsible in enabling and disabling the different interrupt sources of 8051.
| EA | Disables all interrupts. If EA = 0, no interrupt is acknowledged. If EA = 1, each interrupt source is individually enabled or disabled by setting or clearing its enable bit. |
| __ | Not implemented |
| __ | Not implemented in AT89C2051 but it is implemented as ET2 in 8052 compatible microcontrollers such as AT89S52 (Enables or disables the Timer 2 overflow or capture interrupt) |
| ES | Enables or disables the serial port interrupt. |
| ET1 | Enables or disables the Timer 1 overflow interrupt. |
| EX1 | Enables or disables External Interrupt 1. |
| ET0 | Enables or disables the Timer 0 overflow interrupt. |
| EX0 | Enables or disables External Interrupt 0. |
How To Enable an Interrupt
1. Initialize the sources of interrupts such as Timers, External Interrupts, or UART.
2. Set the bits of the IE register that corresponds to the interrupt sources that you want to be enabled.
Example: If you want to enable the interrupt of the serial port or UART set ES to 1 or ES=1.
3. Enable the global interrupt by setting the EA bit of the IE register (EA=1).
How to Write an interrupt service routine or ISR
The interrupt service routine or ISR is the routine that an MCU is servicing every time an interrupt occurs. It can be treated as an ordinary subroutine in a C program.
The format of the ISR is:
void your_ISR_name(void) interrupt interrupt_priority_number
{
//your routine here
}
The your_ISR_name is user defined. It can be any name.
The interrupt_priority_number is fixed depending on the source of the interrupt. Refer to the table of the interrupt sources above for reference.














nice post..well explained….thanx
how can we improve number of interrupt in 8051
I’m not very familiar with the 8051, but in most systems you can use a programmable interrupt controller (PIC) to handle, prioritize, or nest interrupts, and have it alert the processor using just one interrupt pin. In the processor’s interrupt handler code there can be more elaborate communication with the PIC to gather type/level/vector related data and respond accordingly.
I use the Intel 8259a regularly, but this is in a very outdated lab using mostly intel 8086 chips.