Activity 5.2.1. Reviewing the Keyboard Counter.
With your group, demo your program and read each other’s code, then take turns working through the questions below. Answer each one about the code you read rather than about your own. The questions ask whether you understand that code well enough to modify or maintain it, rather than asking you to find bugs in it.
(a) Trace.
Looking at the code you read, trace what happens when the user presses
u, then d, then r, each pressed once just before the USART’s RXNE (receive data register not empty) flag is checked in a given loop iteration. What count value does the terminal display after each of those three loop cycles?
(b) State.
In the code you read, where is the counter value stored? What data type is it? What is the largest value it can hold before it wraps around? Is that likely to matter in practice?
(c) Extension.
Without modifying any existing lines in the code you read, where and how would you add support for pressing
z or Z to increment the counter by 10? How many new lines of code would it take?
(d) Timing.
The RXNE flag is checked once per loop, just before the
printf and delay_ms(500). If two different keys are pressed within the same 500 ms window, what happens? Could the code you read miss a keypress, and if so, is that a fundamental limitation of the design or a bug?
