/* Filename: TCNT0
Author: Renier Del Rosario
Date: 10/5/2024
Description: Timer Interrupt
*/
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <util/delay.h>
#define TOGGLECYCLES 10
volatile unsigned char overflowCounter = 0;
int main(void)
{
cli(); //disable all interrupt
DDRA = 0x80; // PORTA output
PORTA = 0x00; // clear PORTA
TCNT0 = 0x00; // clear the timer
TCCR0A = 0x00; // mode 0.
TCCR0B = 0x03; // 64 prescaler
TIMSK0 = TIMSK0 | (1 << TOIE0); // Enables overflow interrupt
TIFR0 = TIFR0 | (1 << TOV0); // Set the overflow flag
sei(); // Enables all interrupts
while(1);
{
;
}
}
ISR(TIMER0_OVF_vect)
{
if(overflowCounter == TOGGLECYCLES)
{
PORTA = PORTA ^ 0b10000000;
overflowCounter = 0;
// _delay_ms(500);
}
overflowCounter++;
TIMSK0 = TIMSK0 | (1 << TOIE0); // re-arm interrupt
}