/*
=== Could not get this to work, maybe it's a problem with
Wokwi and Timer1. Try breadboarding this...
Controlled by:
* TCCR1 (Timer/Counter1 Control Register)
* GTCCR (General Timer/Counter Control Register)
* OCR1A, OCR1C (Compare registers)
* TCNT1 (Timer/Counter1)
* TIMSK (Interrupt mask)
* TIFR (Interrupt flags)
*/
#define F_CPU 8000000UL
#include <avr/io.h>
#include <avr/interrupt.h>
#define LED_PIN PB1
void timer1_init(void) {
TCCR1 = 0; // Normal mode
// Prescaler = clk/64 → CS12=1, CS11=1, CS10=1 (binary 0b111)
TCCR1 |= (1 << CS12) | (1 << CS11) | (1 << CS10);
// Enable Timer1 overflow interrupt
TIMSK |= (1 << TOIE1);
// Clear counter
TCNT1 = 0;
}
ISR(TIMER1_OVF_vect) {
PORTB ^= (1 << LED_PIN); // Toggle LED on every overflow
}
int main(void) {
DDRB |= (1 << LED_PIN); // Set LED pin as output
PORTB &= ~(1 << LED_PIN); // Ensure LED starts low
timer1_init(); // Start Timer1
sei(); // Enable global interrupts
while (1) {
// Nothing here — just wait for interrupt
}
}