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:

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top