void setup() {
cli(); // Disable global interrupts
// Set up the LED pin as output
DDRB |= (1 << DDB5); // Set pin 13 as output
// Configure Timer1 for Normal mode
TCCR1A = 0; // Set entire TCCR1A register to 0, ensure WGM10 and WGM11 are 0 for Normal mode
TCCR1B = 0; // Ensure WGM12 and WGM13 are 0 for Normal mode
// In Normal mode, the timer overflows from 65535 back to 0. Let's use a prescaler to adjust the timing.
// Set CS12 bit for 256 prescaler, the closest we can easily configure for a 1-second overflow without external calculations.
TCCR1B |= (1 << CS12);
// Enable timer overflow interrupt for Timer1
TIMSK1 |= (1 << TOIE1);
sei(); // Enable global interrupts
}
ISR(TIMER1_OVF_vect) {
// ISR called upon timer overflow
// Toggle the LED connected to pin 13
PORTB ^= (1 << PORTB5);
}
void loop() {
// Nothing needed here - the ISR handles the LED blinking
}