8051 Interrupts  
What are Interrupts ???

Consider that a teacher is conducting a lecture. He wants to make sure that at all times everyone undersatnds what he is explaining. He has two choices to ensure this:

  • Ask every student in class if he/she has understood the concept.

  • Any student raises his/her hand and asks him when he/she has a doubt.

    So the thing is, the first of these two alternatives is called polling. whereas the second is called interrupt. So which one is better ??? Ofcourse first approach is very tedious and time consuming.

    In above consideration, lets take teacher is our CPU which provide resources to its student (Peripheral devices).So the approach of interruption is much better in most of the cases.

    Upon receiving interrupt signal from the peripheral device, CPU stop doing its current routine and jumps to a different code segment or we can say it as an "Interrupt Service Routine". ISR contains the tasks to be handeled by CPU whenever it acknowledge some interrupt signal.

    Six interrupts in 8051 Microcontroller.

    Above is picture of 8051 Interrupt vector table. The address in right most coloumns are address of ISR vector in ROM.

    Upon reciving interrupt signal from anywhere, the microcontroller gets the address of the ISR form interrupt vector table and jumps to it. It starts to execute Interrupt service routine untill it reaches the last instruction of the subroutine, which is a return from interrupt instruction.

    In the table above only 5 interrupt sources are shown, Another interrupt is Hardware RESET which has the highest priority of all 5. but it is not for user/programmer purpose.

    How to use Interrupts ???

    By default all interrupts (except RESET) are disabled. We need to modify a special SFR called IE (Interrupt Enable) to enable some particular Interrupt. Ofcourse IE is bit addressable.

    When to use Interrupts ???

    Simply use interrupt to perform tasks, when you need to execute two or more events almost simultanously. Like for example scannig Seven segment displays and at the same time Put your data on Segments to display a kind of clock or Counter.

    Best viewed at Firefox 1024x768 resolution