-
-
Save chayanforyou/a9b1f657203f910b7fde285449629f63 to your computer and use it in GitHub Desktop.
atmega8 timer0 - use overflow interrupt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// All values/comments are valid with ATmega8 running at Fosc = 4.000MHz | |
#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 | |
sei(); // global interrupt enable | |
// ... 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 | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment