8051 Interrupts
An Interrupt is an external or internal event that halts or interrupts Microcontroller to inform it that a device needs its service.
A microcontroller is able to give service to many Input and Output devices connected to it. It is able to do it in two ways Interrupts and Polling.
1.1 Polling:
In this method, the microcontroller will be continuously monitoring the status of a device, until some pre-determined condition is met, and then serves the device.In this method, multitasking is not possible.For example:
Fig 1 Polling Example |
In above example until the TF0 flag is set.The microcontroller checks the status and will not serve any other service.It’s not feasible.
1.2 Interrupts:
In this method whenever a device needs the service, the device requests the microcontroller by sending it an interrupt signal.Upon reception of the interrupt signal, the microcontroller halts whatever it is doing and serves the device.
1.2.1 Interrupt Service Routine: The program related to interrupt is called Interrupt Service Routine(ISR) or Interrupt Handler.
2.Steps taken when Interrupt occurs:
When an interrupt occurs, the Microcontroller follows these steps:
Fig 3 Steps followed when an Interrupt occurs |
- 8051 Microcontroller finishes the instruction it is currently executing, and saves the contents of Program Counter(PC) on the stack (address of next instruction).
- It jumps to the interrupt vector location corresponding to the interrupt source.
- Executes the interrupt service routine, until it encounters RETI instruction.
- Returns back to the place where it was interrupted by popping the contents of stack on PC, and starts execution at that address.
More concepts in posts. Stay tuned…..!