/* Filename: Excercise 3
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>
// volatile unsigned char overflowCounter = 0;
int main(void)
{
cli(); // disable all interrupts
DDRA = 0x80; // PORTA output
PORTA = 0x00; // clear PORTA
TCNT0 = 0x00; // clear the timer
TCCR0A = 0b01000010; // Mode 2: CTC (Clear Timer on Compare Match)
TCCR0B = 0x05; // 1024 prescaler
OCR0A = 7812; // Compare value for 0.5 second at 16 MHz clock (1024 prescaler)
TIMSK0 = (1 << OCIE0A); // Enable Timer/Counter0 Output Compare Match A interrupt
sei(); // Enable interrupts globally
while (1)
{
;
}
}
ISR(TIMER0_COMPA_vect)
{
PORTA ^= 0x80;
// _delay_ms(500);
}