The interrupts library must be included. The OCIE1A (Output Compare Interrupt Enable) is set in the TIMSK1 (Timer mask) register to enable the interrupts for the timer/counter when the ICR (Input Capture Register) is reached. The Global Interrupt is used sei();. When the ICR value is reached, the ISR (Interrupt Service Routine) for the TIMER1_COMPA_vect is called.
#include <avr/io.h>
#include <avr/interrupt.h>
int main(void)
{
TCCR1A |= 1<<WGM11;
TCCR1B |= 1<<WGM12 | 1<<WGM13 | 1<<CS10;
TIMSK1 |= 1<<OCIE1A;
sei();
ICR1 = 19999;
while(1)
{
}
}
ISR(TIMER1_COMPA_vect)
{
//Code to execute when the Timer Reaches the ICR1 value.
}
Comments and Additional Information
Have some code to share? Or additional information? Respond here:
You need to be logged in to save a response on this page. The response must be constructive, helpful, supplimentary or to correct the existing video, code or narrative content.