The interrupt is another method to program the microcontroller. In the interrupt method, the microcontroller gets interrupted by the device connected to it. Once interrupted, it is going to run the piece of code written for particular interrupt called Interrupt Service Routine(ISR). Once it has done executing, it’s going to resumes the operation from where it’s gets interrupted.
Types of Interrupts
There are total 21 Interrupts in Atmega16 of AVR family, which can be divided into two basic types-The External and the Internal Interrupt. As the name suggests, external interrupts are triggered by hardwares(External Devices). Whereas the internal interrupts are triggered by the events occur in the program itself. Timer interrupt, Serial interrupts, ADC(Analog to Digital Converters) interrupt etc are examples of internal interrupts in Atmega16.
There are four pins in Atmega16 that are assigned to handle interrupts from the external sources. These pins are PIND0(PIN16), PIND1(PIN17), PINB2(PIN3) and RESET(PIN9). Out of these interrupts, RESET pin is non-maskable. It means that rest of the interrupts can be activated or deactivated by you(maskable) but if the RESET interrupt is triggered, the microcontroller has to execute it. Basically, RESET Interrupt resets the program loaded on the microcontroller.
There are 17 internal interrupts in Atmega16. These interrupts support the various operations in the microcontroller which include-Analog to Digital Converter(ADC), Timer Interrupts, Serial Interrupts etc. We will discuss each Interrupt in subsequent articles.
Events occur during Interrupt
What are the events that followed when an interrupt is triggered?
When an interrupt is triggered, the normal execution of the program gets suspended and the instructions written for the interrupt is executed(Interrupt Service Routine). Once, the instructions written for the interrupt gets executed, the program gets started from the same point where it gets interrupted.
General Method to Program via Interrupt
I want to discuss the general steps to program via Interrupt method. This makes you guys easier to understand the programming process of each and every interrupt.
- We are going to find the suitable register which controls the particular interrupt.
- We then set the particular bit of the register high or low according to the need to enable or disable the particular interrupt.
- We have to set the “Flag Register” of the particular interrupt as well.
- Write the Interrupt Service Routine for the particular Interrupt.
That’s the general method to program the microcontroller via interrupt method. In the coming post, we are going to discuss various types of interrupts in detail and create some awesome projects as well.
Well, that’s it for this article. If you like this article, please do subscribe us to never miss an update. See you next time.