timer_flag is changed in ISR and read in main, so it must be volatile to prevent optimization.
Step 2: Review other options
ISR return type can be void; printf() can be used if supported; while condition is logically correct.
Final Answer:
timer_flag should be declared volatile -> Option B
Quick Check:
Shared variable with ISR needs volatile = C [OK]
Hint: Use volatile for variables changed by interrupts [OK]
Common Mistakes:
Ignoring volatile keyword
Changing ISR return type unnecessarily
Thinking printf is always disallowed
5. You want to blink an LED every 1 second without stopping other tasks. Which timer approach is best in embedded C?
hard
A. Use a timer interrupt to toggle LED flag every 1 second
B. Use a blocking delay loop for 1 second
C. Use a recursive function to blink LED
D. Use a global variable incremented in main loop
Solution
Step 1: Understand blinking without stopping other tasks
Blocking delay (Use a blocking delay loop for 1 second) stops other tasks; recursive function (Use a recursive function to blink LED) is inefficient; global variable incremented in main (Use a global variable incremented in main loop) may not be precise.
Step 2: Use timer interrupt for precise, non-blocking control
Timer interrupt toggles LED flag every 1 second without blocking main program.
Final Answer:
Use a timer interrupt to toggle LED flag every 1 second -> Option A
Quick Check:
Timer interrupt enables non-blocking blinking = A [OK]
Hint: Use timer interrupts for non-blocking periodic tasks [OK]
Common Mistakes:
Using blocking delays that freeze program
Trying recursion for timing
Relying on main loop variable without timer
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.