2. Explain the different types of interrupts in 8051 and their handling mechanism.







 






Q2. Explain the different types of interrupts in 8051 and their handling mechanism

Repeated: 6 Times – As per CS3691 – Embedded Systems and IoT Syllabus


1. Introduction to Interrupts in 8051

An interrupt is a signal that temporarily halts the CPU's current execution so it can respond to an urgent task. After completing that task, the CPU resumes its previous operation.
This is essential for real-time systems, IoT devices, and embedded applications.

Keywords: 8051, Interrupts, Embedded Systems, Real-Time, Priority, ISR


2. Purpose of Interrupts in Embedded Systems

  • Ensures real-time response to events like sensor inputs, timer overflows, serial data.
  • Used in IoT applications for tasks like data logging, remote monitoring, and wireless communication.
  • Helps in multitasking without polling or wasting CPU cycles.

3. List of Interrupts in 8051

8051 has 5 interrupt sources, which are:

Interrupt Name Source Vector Address Trigger Type
INT0 (External 0) External Pin P3.2 0003H Edge/Level Triggered
Timer 0 Overflow Timer 0 000BH On Timer Overflow
INT1 (External 1) External Pin P3.3 0013H Edge/Level Triggered
Timer 1 Overflow Timer 1 001BH On Timer Overflow
Serial Port UART Communication 0023H Tx/Rx Complete

Keywords: INT0, INT1, Timer0, Timer1, Serial Interrupt, Vector Address


4. Explanation of Each Interrupt

INT0 & INT1 (External Interrupts):

  • Triggered by hardware signals on external pins (P3.2 and P3.3).
  • Can be configured for edge or level triggering.
  • Useful for external events like button presses, motion sensors, etc.

Timer0 & Timer1 Interrupts:

  • Generated when the internal Timer 0 or Timer 1 overflows.
  • Mainly used for time-based applications like delays, real-time clocks, etc.

Serial Port Interrupt:

  • Triggered when data is sent or received via serial port (UART).
  • Critical for wireless communication, sensor interfaces, and data transmission in IoT.

5. Interrupt Vector Table

Interrupt Memory Location (Vector Address)
INT0 0003H
Timer0 000BH
INT1 0013H
Timer1 001BH
Serial 0023H

Keywords: ISR, Interrupt Vector Table, Address


6. Interrupt Handling Mechanism in 8051

Step-by-Step Process:

  1. Interrupt Request (IRQ): An interrupt event occurs (e.g., Timer overflows).
  2. CPU Response: Current instruction is completed.
  3. Program Counter (PC) is saved.
  4. CPU jumps to ISR based on vector address.
  5. ISR (Interrupt Service Routine) is executed.
  6. RETI Instruction used to return to the main program.
  7. CPU continues from where it left off.

Keywords: ISR, RETI, Program Counter, Interrupt Response, Execution


7. Key Registers Used

IE (Interrupt Enable) Register:

Enables or disables specific interrupts.

Bit Symbol Description
7 EA Enable all interrupts
6 Unused
5 ET2 Timer 2 (8052 only)
4 ES Enable Serial Interrupt
3 ET1 Enable Timer1
2 EX1 Enable External 1
1 ET0 Enable Timer0
0 EX0 Enable External 0

IP (Interrupt Priority) Register:

Controls interrupt priorities (0 = low, 1 = high).

Bit Symbol Description
7-5 Reserved
4 PS Serial Priority
3 PT1 Timer 1 Priority
2 PX1 External 1 Priority
1 PT0 Timer 0 Priority
0 PX0 External 0 Priority

Keywords: IE Register, IP Register, EA, EX0, EX1, Priority


8. Features of 8051 Interrupt System

  • Five interrupt sources with fixed vector locations.
  • Individual enable/disable control.
  • Two-level priority system.
  • Low-latency ISR execution.
  • Flexible triggering options.

9. Real-Time Applications in IoT and Embedded Systems

  • Smart Agriculture: Use external interrupts for soil moisture sensor input.
  • Home Automation: Trigger lights on motion detection using INT0.
  • Smart Healthcare: Timer interrupt to read pulse sensor data every second.
  • Smart Cities: Use serial interrupt to receive environmental sensor data via GSM.

Keywords: Smart Applications, IoT, Timer ISR, Serial ISR


10. Advantages of Using Interrupts

  • Efficient CPU usage (no polling).
  • Faster response to critical events.
  • Supports multitasking.
  • Ideal for real-time embedded systems.

11. Common Errors and Debug Tips

  • Forgetting to enable EA or specific interrupt bits in IE.
  • Not using RETI at the end of ISR.
  • Writing lengthy code in ISR (should be quick).
  • Improper interrupt priority settings (conflicts may arise).