Activity 9.2.7. Homework: counterTwoButtons.c.
The program is due on Thursday, uploaded to Canvas.
(a)
Start from
counterResetButtonInt.c as you wrote it today, and add the Nucleo’s blue user button on PC13, so that pressing it reverses the counting direction. PC13 is also on lines 4 to 15, so it shares EXTI4_15_IRQHandler with PB4, and the handler has to tell the two apart. You will need a second initialization function, and a second field in a different EXTICR register. One thing to think about before you build: the test that wraps the count at MAXCOUNT was written when the count only ever went up. What should happen when it runs the other way?
(b)
The same press of the blue user button should also toggle the on-board LED on PA5 (header D13), and a press of PB4 should not. Do the toggle inside the handler rather than in
main(). The handler runs the moment the edge arrives, while main() only reaches its button test after delay_ms(1000) has finished, so a toggle placed there could be up to a second late. The LED’s clock enable and MODER setup can come from the program you wrote last night. Drive it with GPIOA->BSRR, not GPIOA->ODR: BSRR has no toggle of its own, so keep the LED’s state in a variable that main() never writes and set or clear the pin from it, exactly the way redOn does in the TIM14_IRQHandler we wrote with BSRR.
