Question.5
What will be printed on the Serial monitor after execution of the following code in Arduino UNO?
Note: CPU frequency is 16MHz.
Code
volatile unsigned int count = 0;
void setup() {
Serial.begin(9600);
// Timer2 CTC Mode
TCCR2A = (1 << WGM21); // CTC mode
TCCR2B = (1 << CS22); // Prescaler = 64
OCR2A = 249; // Compare match value
TIMSK2 = (1 << OCIE2A); // Enable Timer2 compare match interrupt
}
ISR(TIMER2_COMPA_vect) {
count++;
}
void loop() {
delay(500); // Wait for 500 milliseconds
TIMSK2 &= ~(1 << OCIE2A); // Disable Timer2 interrupt
Serial.print("Interrupt Count : ");
Serial.println(count); // Display the final count
while (1); // Stop further execution (optional)
}