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