/* Example 9.1. Timer counter 1 in timer mode - pooled version */
#include <avr/io.h>
int main( void )
{
/* *********************** Init device ************************************ */
DDRB = 0x??; // PORTB LED on PB2 is output
PORTB = 0x??; // LED Active low, LED off, No pull-ups
TCCR1A = 0b????????; // T/C1 in timer mode
TCCR1B = 0b????????; // prescale ck
TCNT1 = 0x????; // start value of T/C1 Low+High bytes
TIFR1 = 0x01; //(1<<TOV1); if a 1 is written to a TOV1 bit
// - the TOV1 bit will be cleared
/* *********************** Main Loop ************************************** */
do {
if ( (TIFR1 & 0x01) == 0x01) // If the overflow flag is set
{
PORTB = PORTB ^ 0b????????; // Toggle the LED
TCNT1 = 0x????; // Restart T/C1 - reload
TIFR1 = 0x01; // Clear the overflow flag
}
else
asm("nop"); // Do nothing
} while(1); // And do this forever
return(0);
}