84. Timer Modes

Question.4

What will be the status of LED? (after executing the following code)

Note: CPU clock is 16MHz with a 1024 prescaler.

Code

#define LED 8
void setup() {
  pinMode(LED, OUTPUT);
  TCCR1A = 0;
  TCCR1B = (1 << WGM12) | (1 << CS12) | (1 << CS10); // CTC mode, prescaler=1024
  OCR1A = 15624; // Set the Compare Match Register A for Timer1
}

void loop() {
  while ((TIFR1 & (1 << OCF1A)) == 0); // Polls OCF1A flag in TIFR1 until set.
  digitalWrite(LED, !digitalRead(LED)); // Toggle LED after flag set.
}

 

Select Answer