Timers are essential components in microcontrollers that can measure time intervals, generate signals, and trigger events at precise moments.
// Configure Timer1 for CTC mode TCCR1A = 0; // Set entire TCCR1A register to 0 TCCR1B = 0; // Same for TCCR1B // Set compare match register OCR1A = 15624; // = 16MHz/1024/1Hz - 1 // Turn on CTC mode TCCR1B |= (1 << WGM12); // Set prescaler to 1024 TCCR1B |= (1 << CS12) | (1 << CS10); // Enable timer compare interrupt TIMSK1 |= (1 << OCIE1A);