Page 448 - Programming Microcontrollers in C
P. 448
Keyboard 433
KPSR.KRIE=OFF; /* disable release interrupt */
FIER.EF6=ON; /* enable Fast Interrupt number 6 */
semaph=sem; /* save the semaphore */
data=s;
savedata=s; /* and array information for */
leng=length; /* use in the isr */
}
It is expected that the calling program will attach a semaphore
and provide a buffer into which the input data will be stored. The
semaphore is passed to the initialization routine as sem, and the array
by a pointer to its first element and its length. We plan to use a 4 by
4 matrix keyboard. This keyboard will be connected to the least
significant four rows and columns of the keyboard controller interface.
There are several registers that attach to these interfaces. The KPCR
is a control register, the KPDR is the data register, and the KDDR is
the data direction register. In creating the header file for the keyboard
controller, I added an extra letter, N or B, to these pseudovariable
names to indicate that they have been broken into groups of bits
rather than a register of single bits. A register name that has the letter
N appended is split into two 8-bit fields named COLUMNS and ROWS.
Those with a letter B appended are split into four fields named
HICOLS, LOCOLS, HIROWS and LOROWS. Therefore, the command
KPCRN.LOROWS=0xf;
will cause the least significant bits of the ROWS field in KPCR to be
set to 1.
The comments above explain the various actions that take place
in the initialization routine. The Key Pad Data Register, KPDR, is a
register that connects to the external keyboard interface. The most
significant 8 bits are to connect to columns and the least significant
bits connect to the rows. The plan is to detect cross connections
between a column and a row. The columns serve as outputs and the
rows inputs. Therefore, the columns will be set as open drain and as
outputs through the data direction register. In the KBSR, Key Board
Status Register, the Key Pad Key Depressed bit, KPKR, is set
whenever the system detects a depressed key. This bit is reset by
writing a 1 to it. On both key depress and key release, there is a
synchronizer that aims to hide any key bounce that might occur. The
key depress synchronizer is cleared by writing a 1 to KPSR.KDSC.

