AVR microcontroller interrupts using WINAVR

I can’t imagine microcontroller without interrupts. Without interrupts you would have to do loops in order to check if one or another event occurred. Polling has many disadvantages like program have do loops what takes valuable microcontroller resources. These resources may be used for other data processing tasks. This is why microcontroller comes with built in interrupt support. Instead of checking events microcontroller has ability to interrupt normal program flow on event and jump to interrupt service subroutine. During interrupt microcontroller stops the task at current point, saves necessary information to stack and gives resources to interrupt subroutine. When interrupt subroutine finishes, and then normal program flow continues. In assembler your program would start with interrupt table: After table goes the main program (RESET) and other interrupt subroutines where program jumps after interrupt occurs. C Compiler creates this table while compiling, but how about interrupt handling routines. First of all to make compiler understand interrupt macro command include desired library; #include “avr\interrupt.h” All interrupts then can be described using macro command: ISR(), for instance: ISR(ADC_vect) { //Your code here }   This routine is for ADC complete conversion handler. This macro command is convenient for handling all unexpected interrupts. Just…

Continue reading