Encoding is done by simply loading the value in the virtual matrix table using the
IREAD instruction. This enables us to easily change the encoded value and adapt to
different keyboard layouts.
After encoding, the interrupt routine will transition to fast scan state when the key is
released. This is to ensure that single key press will not be detected as multiple key strokes.
Modifications and further options
To accommodate a different 4 x 4 keyboard layout, it is very easy to just change the
virtual matrix. The first entry is for index 0 and the last entry is for the index value of 0F
(hex).
Notice that all values are negated to enable display on LED on port B. A zero causes
the LED to be lit and an one will turn it off. If desired, the ~ sign can be removed to obtain
the true value.
For example, the following matrix can be used for a 4 x 4 hexadecimal keyboard with real
value (not display value):
virtual matrix dw
$F
; bottom right
dw
$E
dw
$D
dw
$C
dw
$B
dw
$A
dw
9
dw
8
dw
7
dw
6
dw
5
dw
4
dw
3
dw
2
dw
1
dw
0
; upper left
Finally, to integrate this code with other virtual peripherals, keep in mind that it has a
varying execution rate depending on the state and therefore should be placed after code with
uniform execution rate.