You are on page 1of 6

Programming Timer Interrupts:-

 In this section we are using Interrupts to program the AVR timers.


 If the timer interrupt in the interrupt register is enabled, TOV0 is raised whenever the
timer rolls over and the microcontroller jumps to the interrupt vector table to serve the
ISR.
 The TOIEx bit enables the interrupt for a given timer.
 TOIEx bits are held by the TIMSK register.
INTERRUPT PROGRAMMING IN C:-
In C language there is no instruction to manage the interrupts. So to manage the
interrupts add the following.
1. Interrupt include file should include if we are using interrupts in our
program.
#include <avr/interrupt.h>
2. cli is used to clear and sei is used to set the I bit of the SREG.
3. Defining ISR:- To write an ISR for an interrupt, we use the following
structure. For the interrupt vector name, we must use ISR names in
the table below.
ISR(interrupt vector name)
{
//Our program
}
Example:
ISR(TIMER0_COMP_vect)
{
}
Example:-
PROGRAMMING EXTERNAL HARDWARE INTERRUPTS:-
 The number of external hardware interrupts varies in different AVRs.
 ATmega32 has three external hardware interrupts.
1. INT0 – at pin PD2 (PORTD.2)
2. INT1 – at pin PD3 (PORTD.3)
3. INT2 – at pin PB2 (PORTB.2)
 Upon activation of these pins, the AVR is interrupted in whatever it is doing and
jumps to the vector table to perform the ISR.
 Hardware interrupts must be enabled before they can take effect.
 This is done using the INTx bit located in the GICR register.

Example:-

You might also like