Solved Examples on 8051 Microcontroller Interrupts

1. Write an 8051 program to enable external interrupts’0’ and ‘1’, configure it to receive edge triggered interrupt request and keep waiting for the interrupt.

ORG 0x00; Start of program memory

MOV P1, #00H; Initialize Port 1

MOV IE, #10001011B; Enable external interrupts (EX0 and EX1)

MOV IT0, #0; Configure INT0 for edge-triggered interrupt

MOV IT1, #0; Configure INT1 for edge-triggered interrupt

MAIN:

NOP; No operation, just wait for interrupts

SJMP MAIN; Jump back to main loop

ORG 0x03; Interrupt Vector for External Interrupt 0 (INT0)

INT0_ISR:

; Your interrupt service routine code for INT0 here

RETI; Return from interrupt

ORG 0x0B; Interrupt Vector for External Interrupt 1 (INT1)

INT1_ISR:

; Your interrupt service routine code for INT1 here

RETI; Return from interrupt

2. Write a program to flash LEDs connected at port 2 With delay of 10 msec. Read data from PORT O continuously and send it to PORT 1 .Use timer 0 in mode 1 with interrupt.

ORG 0000H

LJMP MAIN

ORG 000BH

CLR TCON.4

CLR TCON.5

CPL A

MOV P2,A

MOV THO, # ODB

MOV TLO,# OFF

SETB TCON.4

RETI

MAIN: MOV TMOD,#01h

MOV THO, # ODB

MOV TLO,# OFF

MOV IE, # 82H

MOV A,#00H

MOV P2,#00H

SETB TCON.4

BACK: MOV A, PO

MOV P1,A

SJMP BACK

Microcontrollers – 8051 Interrupts

8051 Microcontroller is a widely used embedded system, that incorporates a robust interrupt system which are important for external communications and real-time applications. Interrupts are the important feature of a microcontroller which enables the microcontroller to respond to the external events and requests, which enhances the multitasking abilities of the microcontroller. An interrupt is an external or internal event/command that interrupts the normal processing of an event and informs the microcontroller that a device needs its service. Whenever a device needs its service, the device sends an interrupt signal to the microcontroller to send a notification. Upon receiving the interrupt signal, the microcontroller stops its existing program and serves the external device request. The program which is associated with the interrupt is known as interrupt Service Routine (IRS) or interrupt handler.

The 8051 features two main types of interrupts, i.e. Hardware interrupts and software interrupts. The hardware interrupts are triggered by external signal such as peripheral events or external devices. The microcontroller can be configured to respond to specific events, allowing for efficient event-driven programming. Whereas, the Software interrupts, are initiated by specific instructions in the program code. They provide a mechanism for the programmer to force the microcontroller to interrupt its normal execution and execute a predefined routine.

The address of the corresponding interrupt service routine (ISR) is included in the suitable interrupt vector associated with every interrupt source in the 8051. The microcontroller automatically maintains its state on interrupt, fetches the interrupt vector’s ISR address, and executes the ISR’s operation. Once the ISR is finished, the microcontroller restarts the task which has been interrupted.

Table of Content

  • 8051 Microcontroller
  • 8051 Microcontroller Interrupt
  • Types of Interrupts
  • Interrupt Vector Table
  • Applications
  • Solved Examples
  • Advantages
  • Disadvantages

Similar Reads

What is an 8051 Microcontroller?

8051 microcontroller is an 8-bit data bus and 16-bit address bus Microcontroller. A 64K (216) byte code memory space and an additional 64K byte data memory space can be addressed using the 16-bit address bus. It has 40 pins and 4K on-chip read only code memory and 128 bytes of internal RAM. It also has various Special Function Registers (SFR) such as the accumulator, the B register, and many other control registers. At a time, the ALU executes an 8-bit operation. It also has two 16-bit counter timers and 3 internal interrupts and 2 external interrupts and four 8 bit I/O ports....

8051 Microcontroller Interrupt

The timer and serial interrupts are internally generated by the microcontroller whereas, the external interrupts are generated by additional peripheral devices or switches that are connected to the microcontroller externally. There are two types of external interrupts: edge-triggered and level-triggered. The interrupt service routine is carried out by the microcontroller as a reaction to an interrupt, enabling memory locations to coincide with interrupts....

Types of 8051 Microcontroller Interrupts

8051 Microcontroller suffers five different types of interrupts that hampers the main program execution. These five types of interrupts are:...

Interrupt Vector Table

The addresses of different interrupt service routines (ISRs) are stored in a table called the Interrupt Vector Table (IVT) in an 8051 microcontroller. It is a vital aspect of the interrupt handling mechanism in the microcontroller. When an interrupt occurs the interrupt specific ISR is executed by jumping the program counter to the corresponding address in the IVT. There are memory areas set aside specifically for the IVT in the 8051 microprocessors. Every interrupt has a specific place in the IVT, and the addresses kept there point to the program memory’s associated ISR’s start. By guiding the program flow to the proper place, the IVT enables the microcontroller to respond to external events like hardware interrupts or external signals quickly and effectively....

Applications of 8051 Interrupts

In real-time systems, interrupts are essential for speedy responses to external occurrences. Due to its ability to swap tasks fast through interrupts, the 8051 is a good choice for applications that need exact timing. Interrupts serve in the control of incoming data in communication applications, assuring timely transmission or rapid handling of received information. In embedded systems, 8051 interrupts are frequently utilized for activities like sensor interfacing, where the microcontroller must react quickly to environmental changes. Interruptions assist in ensuring timely data sampling and processing in situations when data must be obtained from sensors or external devices. By enabling instantaneous reactions to sensor triggers or alarm situations, interrupts in security systems can ensure prompt alerting and suitable responses....

Solved Examples on 8051 Microcontroller Interrupts

1. Write an 8051 program to enable external interrupts’0’ and ‘1’, configure it to receive edge triggered interrupt request and keep waiting for the interrupt....

Advantages of 8051 Microcontroller Interrupt

By quickly resolving problems, interrupts can be used for error detection and handling, improving the system’s robustness and reliability. The 8051’s capability to operate in a low-power mode and wake up only in response to an interrupt helps battery-powered applications operate more energy-efficiently. Interrupts make it possible to break up large, complicated processes into smaller, more manageable subroutines, which improves the readability and organization of the code. By allowing the microcontroller to be interrupted in response to a predetermined event, the interrupt system minimizes CPU overhead and boosts overall system performance. This eliminates the requirement for constant input polling. A few 8051 variations enable interrupt priority levels, which give important tasks the upper hand over less important ones and improve responsiveness and control of the system....

Disadvantages of 8051 Microcontroller Interrupt

The number of interrupt sources that can be supported is limited by the 8051 microcontroller’s two external interrupt pins (INT0 and INT1). The 8051’s interrupt priority cannot be dynamically adjusted; it is fixed. This could render handling several interruption sources with different priorities difficult. Variations in the microcontroller’s response time to an interrupt might affect real-time applications where reliable and consistent response times are essential. Careful programming is necessary to prevent unexpected behavior while handling interrupts, particularly when working with nested interruptions or crucial portions. Since the 8051 lacks vectored interrupts, unlike some other modern microcontrollers, it is required to manually examine interrupt flags in order to identify the interrupt’s source....

Conclusion

The 8051 Microcontroller has the ability to handle interrupts both external as well as internal interrupts. This helps the microcontroller to interface with the external peripherals devices and can be used for real time applications. These interrupts increase the productivity of the microcontroller and can be used for various purposes. interrupts are essential to the operation of 8051 microcontrollers because they give the processor a way to react to outside events quickly and without the need for continuous polling. They improve system efficiency by enabling the microcontroller to manage several tasks at once. Because of their capacity to manage a variety of interrupt sources and prioritize tasks, 8051 microcontrollers provide an adaptable platform for embedded systems, which makes them ideal for applications that demand multitasking and real-time responsiveness. Comprehending and executing interrupt-driven programming efficiently is imperative to fully utilize 8051 microcontrollers in diverse electronic uses....

FAQs on Microcontrollers – 8051 Interrupts

How does 8051 Prioritize interrupt?...