My question is: Doesn't the program get stuck at while (1)? How is the flow of this program? I mean, can the program execute what is inside while (1) loop and execute interrupts and then go back to while (1)?
#include <avr/io.h>
#include <avr/interrupt.h>
// TIMER0 with prescaler clkI/O/1024
#define TIMER0_PRESCALER (1 << CS02) | (1 << CS00)
void main()
{
// ... do something ...
// init Timer0
TIMSK |= (1 << TOIE0); // interrupt enable - here overflow
TCCR0 |= TIMER0_PRESCALER; // use defined prescaler value
// ... do something ...
while (1)
{
// ... do something ...
} /* end of while(1) */
}
// *** Interrupt Service Routine *****************************************
// Timer0 overflow interrupt handler (~65ms 4MHz@1024 precale factor)
ISR(TIMER0_OVF_vect)
{
// handle interrupt
}
#include <avr/io.h>
#include <avr/interrupt.h>
// TIMER0 with prescaler clkI/O/1024
#define TIMER0_PRESCALER (1 << CS02) | (1 << CS00)
void main()
{
// ... do something ...
// init Timer0
TIMSK |= (1 << TOIE0); // interrupt enable - here overflow
TCCR0 |= TIMER0_PRESCALER; // use defined prescaler value
// ... do something ...
while (1)
{
// ... do something ...
} /* end of while(1) */
}
// *** Interrupt Service Routine *****************************************
// Timer0 overflow interrupt handler (~65ms 4MHz@1024 precale factor)
ISR(TIMER0_OVF_vect)
{
// handle interrupt
}