Page 449 - Programming Microcontrollers in C
P. 449
434 Chapter 8 MCORE, A RISC Machine
Next the key depress interrupt is enabled and the key release interrupt
is disabled. The parameters passed to the initialization routine are
now saved in static external variables. These parameters are used in
the interrupt service routine.
The column outputs on the four least significant bits are all set to
zero so that any key depression will cause the normally high inputs
sensed by the key inputs to be pulled low. This action will initiate the
key depress synchronizer operation. Approximately four milliseconds
later, if the input key has the same state, a key depressed interrupt
will be requested. The key release operates similarly. As long as a
key remains depressed, nothing happens. When the key is released,
the key release synchronizer initiates its action. If the key has the
same state after the synchronizer time-out, a key release interrupt
can be requested. For these operations to work, the column outputs
must all be held at zero.
It is most convenient to use both the key depress and the key
release interrupts for the task at hand. Each time a key is depressed,
it is detected and the position of the key in the keypad is saved in a
buffer. Conditions to cause a key release interrupt are then set up.
Then control is returned to the interrupted program. When the key is
released, a key release interrupt is requested, and in the interrupt
service routine, a key depress interrupt is set up so that the next key
press will be detected. Each time a key position is entered into the
buffer, the next position in the buffer is marked with a 0xff.
I speak of the key position. In the interrupt service routine below,
it is first tested to determine if the interrupt was caused by a key
depress or a key release. If it is a key depress interrupt, control is
immediately passed to a for loop. Within this loop, the columns are
first loaded with a 0xe, which will have the three highest bits in the
column high and the least significant bit low. A test checks to
determine if all of the column bits are high. If not the value of column
is impressed on KPDRB.COLUMNS. The next test checks the value
found on KPDRB.ROWS. If there is no button depressed that connects
column 1 with any of the rows, the result will be 0xff. Therefore,
control will go to the next column. If the value found on rows is not
0xff, the least significant four bits will indicate the row in which the
switch is depressed. Then, the row and column data is combined into
a single value that is stored in the data array. The column contains 4

