Interrupt is one of the powerfull concept in microcontroller.
- If interrupt occurs in microcontroller,then controller completes the execution of the current instruction and starts the execution of an Interrupt Service Routine (ISR).
- ISR is a piece of code that tells the controller what to do & when the interrupt occurs.
- After the execution of ISR, controller returns back to the instruction.
Types Of Interrupt
- Two type of interrupt
1.Hardware interrupt.
2.Software interrupt.
Hardware interrupt.
- If the interrupts are generated by the interfaced devices like switch is called hardware interrupt.
Software interrupt.
- Interrupts are generated by a piece of code is called software interrupt.
-
8051 has
six interrupts of which five are available to the
programmer.
1.RESET interrupt
2.Timer interrupts
3.External interrupts
4.Serial interrupt
Reset Interrupt
- This is known as Power on Reset .
- If RESET interrupt is received, the controller restarts executing code from 0000H location.
- This is an interrupt which is not available to programmer.
Timer Interrupt
- A timer interrupt notifies the microcontroller that the corresponding Timer has finished counting.
External Interrupt
- There are two external interrupts to serve external devices. INT0 – P3.2 , INT1 – P3.3.
- An external interrupt notifies the microcontroller that an external device needs its service.
Serial Interrupt
- Interrupt is used for serial communication.
- It notifies the controller whether a byte has been received or transmitted.
Interrupt Programming
- Configuring the Interrupt Enable (IE) register.
- IE is used to enable or disable the various available interrupts.
Interrupt Enable Register

- T o enable any interrupt EA must be set to 1.
- ET0,ET1,ET2 are used to enable timer interrupt.
- EX0,EX1 are used to enable external interrupt.
- ES are used to enable Serial interrupt.
- EA- EA bit acts as a lock bit.
- EA bit is not set, the interrupt will not function.
External Interrupt Programming
- External interrupt can be edge triggered or level triggered.
1.Edge triggering.
Interrupt is enabled for a high to low transition at INTx pin.
2.Level triggering
Interrupt is enabled for a low at INTx pin. - The edge or level trigger is decided by the TCON register. The TCON register has following bits:
- The IT0 and IT1 bits make the external interrupt 0 and 1.
If 0=level triggering.
If 1=edge triggering.

Code
#include <REGX51.H> unsigned char count; void main(void) { IE=0x81; // Enable hardware interrupt TCON=0x01; while(1) { P1=count; } } // interrupt function void extint0() interrupt 0 { count=count+1; }