Login

Lost your password?
Don't have an account? Sign Up

Interrupts in 8051 Microcontroller (AT89C52)

Would you like to join our comprehensive practical video course on the AT89C52 Microcontroller?

Introduction

Interrupts in 8051: Interrupts are essential in embedded systems because they allow the microcontroller to respond immediately to external or internal events without continuously polling for changes. The AT89C52 microcontroller, based on the 8051 architecture, supports a well-structured interrupt system that enhances real-time performance. In this tutorial, you’ll learn about the interrupt structure, vector addresses, registers, and programming for handling interrupts in AT89C52 using Embedded C in Keil µVision.

What is an Interrupt?

An interrupt is a signal that temporarily halts the main program execution and transfers control to a special routine known as the Interrupt Service Routine (ISR). Once the ISR is executed, the program returns to its previous operation.


Benefits of Using Interrupts:
  • Improves system response time
  • Reduces CPU overhead (no continuous polling)
  • Enables multitasking and event-driven programming

Types of Interrupts in AT89C52

The AT89C52 microcontroller supports five interrupt sources (hardware and software-based):

Interrupt SourceInterrupt FlagVector AddressPriorityDescription
External Interrupt 0IE00003HLow/HighTriggered by a falling edge or low level on INT0 (P3.2)
Timer 0 OverflowTF0000BHLow/HighGenerated when Timer 0 overflows
External Interrupt 1IE10013HLow/HighTriggered by a falling edge or low level on INT1 (P3.3)
Timer 1 OverflowTF1001BHLow/HighGenerated when Timer 1 overflows
Serial Port InterruptTI/RI0023HLow/HighOccurs when serial data transmission or reception is complete

Interrupts in 8051

Interrupt Registers

Interrupt Enable (IE) Register

The IE register enables or disables specific interrupts.

Bit76543210
FunctionEAESET1EX1ET0EX0
  • EA (Bit 7): Global Interrupt Enable (1 = enable all, 0 = disable all)
  • ES: Enables/disables Serial Port Interrupt
  • ET1: Enables/disables Timer 1 Interrupt
  • EX1: Enables/disables External Interrupt 1
  • ET0: Enables/disables Timer 0 Interrupt
  • EX0: Enables/disables External Interrupt 0

Interrupt Priority (IP) Register

The IP register defines which interrupts have higher priority when multiple interrupts occur simultaneously.

Bit76543210
FunctionPSPT1PX1PT0PX0

  • PX0: Priority bit for External Interrupt 0
  • PT0: Priority bit for Timer 0
  • PX1: Priority bit for External Interrupt 1
  • PT1: Priority bit for Timer 1
  • PS: Priority bit for Serial Port

When a priority bit is set to 1, that interrupt is assigned high priority; otherwise, it has low priority.

Example: External Interrupt 0 Using AT89C52

This example turns ON an LED when an external interrupt (INT0) occurs.
Circuit Description:

  • Connect a push button to P3.2 (INT0) pin.
  • Connect an LED to P1.0 with a 220Ω resistor.
  • The interrupt triggers when the button is pressed.
#include <reg51.h>
sbit LED = P1^0;
void delay(unsigned int t)
{
    unsigned int i, j;
    for(i=0;i<t;i++)
        for(j=0;j<1275;j++);
}
void ext_int0(void) interrupt 0   // ISR for External Interrupt 0
{
    LED = ~LED;  // Toggle LED state
    delay(200);
}
void main()
{
    LED = 0;         // Initialize LED OFF
    IE = 0x81;       // Enable External Interrupt 0 (EX0=1, EA=1)
    IT0 = 1;         // Set edge-triggered interrupt (falling edge)
    while(1);        // Wait for interrupt
}
C

Working Explanation
  1. IT0 = 1 configures External Interrupt 0 to trigger on a falling edge.
  2. IE = 0x81 enables the external interrupt and the global interrupt system.
  3. When the button connected to INT0 is pressed, the ISR (Interrupt Service Routine) is executed.
  4. The LED toggles its state inside the ISR.

Interrupts in 8051

Interrupt Vector Table

Interrupt SourceVector Address
External Interrupt 00003H
Timer 0 Overflow000BH
External Interrupt 10013H
Timer 1 Overflow001BH
Serial Port0023H

The compiler automatically places the ISR address at these vector locations during compilation.

Circuit Design in Proteus

In Proteus, place:

  • AT89C52 microcontroller
  • Push button (for INT0) connected to P3.2
  • LED (through 220Ω resistor) connected to P1.0
  • 5V power supply and ground connections
    Run the simulation. When you press the button, the LED toggles its state, confirming the interrupt’s operation.

Applications

  • Real-time event detection
  • Switch debouncing
  • External sensor triggering (IR, ultrasonic, etc.)
  • Serial data reception
  • Timer-based periodic task execution

Summary

The interrupt system of AT89C52 allows the processor to react to important events instantly. Understanding how to configure the IE, IP, and TCON registers helps in writing efficient, event-driven programs. External interrupts can be used for user input, while timer and serial interrupts enable precise timing and data handling.

Do you want to go beyond just configuration and build real embedded projects?
🎓 Join our Complete Practical Video Course to Master the AT89C52 Microcontroller.

Get step-by-step guidance on Timers, Interrupts, UART, I/O Interfacing, ADC (using ADC0804), and I²C/SPI (Software Implementation) — with real circuits, simulations, and hardware demonstrations!

Downloading and Installing Keil µVision IDE
  • Visit the official Keil website at https://www.keil.com or KEIL IDE
  • Navigate to the Downloads → C51 Compiler section.
  • Register (if required) and download the latest version of Keil µVision for 8051 (C51).
  • Run the installer and follow the on-screen instructions.
  • Once installed, launch the Keil µVision IDE from the Start Menu.

Home » Recent posts » Learn › 8051>Interrupts in 8051

https://bitziga.com

Leave a Comment

Your email address will not be published. Required fields are marked *

*
*