You Are Here: Home » AVR ATmega Projects » Interfacing(USB - RS232 - I2c -ISP) Projects » How to use External (Hardware) Interrupts of AVR Microcontroller (ATmega16)

How to use External (Hardware) Interrupts of AVR Microcontroller (ATmega16)

This article introduces the concept of interrupts and the different types of interrupts in AVR Microcontroller (ATmega16). Interrupt as the name suggests, interrupts the current routine of the microcontroller. Microcontroller executes instructions in a sequence as per the programs. Sometimes there may be a need of handling planned and higher priority events instantaneously that might occur during the normal operations. To handle such kind of events AVR microcontrollers are equipped with Interrupt Systems.

How to use External (Hardware) Interrupts of AVR Microcontroller (ATmega16)

When an interrupt occurs, the normal flow of instructions is suspended by the microcontroller and the code corresponding to the interrupt, which has occurred, is executed. Once the code corresponding to the interrupt is executed completely the execution again begins from the same instruction where it was stopped.
Following is what happens when an interrupt occurs:
1.      Microcontroller normally completes the instruction which is being executed.
2.      The program control transfers to Interrupt Service Routine (ISR). Each interrupt have an associated ISR which is a piece of code which tells the microcontroller what to do when an interrupt has occurred.
3.      Execution of ISR is performed by loading the beginning address of the corresponding ISR into program counter.
4.      Execution of ISR continues until the return from the interrupt instruction (RETI) is encountered.
5.      When ISR is complete, the microcontroller resumes processing where it left off before the interrupt occurred, i.e., program control is reverted back to the main program.
The whole process can be visualized by the following flow diagram:
How to use External (Hardware) Interrupts of AVR Microcontroller (ATmega16) schematic
Atmega16 Interrupts
Number of available interrupts varies with different microcontrollers of AVR family.  Atmega16 in total has twenty one (21) interrupts available. The available interrupts are categorized in two classes:
1.      External Interrupts- Out of the twenty one interrupts available, four interrupts are directly present on controller pins to handle the interrupts generated by external sources, so they are called as external interrupts. The four available interrupts and their respective pins are shown in the figure below in their order of priority:

Leave a Comment

You must be logged in to post a comment.

Read previous post:
How to interface LED with AVR Microcontroller (ATmega16)
How to interface LED with AVR Microcontroller (ATmega16)

ATmega16 has 32 I/O pins to communicate with external devices.  Before interfacing with external devices, these pins must be cofigured...

Scroll to top