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.
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.
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…..!