![Fastwel CPB902 User Manual Download Page 62](http://html.mh-extra.com/html/fastwel/cpb902/cpb902_user-manual_546458062.webp)
Functional Description
CPB902
C P B 9 0 2 U s e r M a n u a l
60
© 2 0 0 8 F a s t w e l v . 1 . 5 b E
4.3.13.2
Matrix Keypad Connection
A matrix keypad can be connected to the J17 header. It is possible to use a matrix keypad having
16 (4
х
4), 20 (4
х
5 or 5
х
4), 25 (5
х
5), 30 (6
х
5 or 5
х
6) or 36 (6
х
6) keys. To interface with a keypad
CPB902 has two ports in I/O address area – one is column scanning and interrupt control port,
another one is row scanning port.
The keyboard interface can also be used as a discrete input/output.
Column scanning and interrupt control port:
Port address –
315h
Bits 5...0 – available for read only. "1" in one of the bits indicates the number of the currently scanned
column;
Bit 6 – not used;
Bit 7 – available for read/write. When read, this bit indicates the presence of keypad interrupt.
"1" – keypad interrupt is present, cleared after read;
"0" – no interrupt.
In "write" mode controls the matrix keypad generation.
"0" – interrupt disabled;
"1" – interrupt enabled.
Row scanning port:
Port address –
316h
Bits 5...0 available for read only. "0" in one of the bits indicates the column, where the key is pressed.
If no key is pressed, all these bits are set to "1".
There are two ways to access a keypad in a user program – by reading bit 7 of 315h port or using
IRQ1 interrupt. By default, this interrupt is used by a PS/2 keyboard at P5 connector. To use it for
matrix keypad, it is necessary to switch it in BIOS Setup program (see
Upon receipt of the "key pressed" attribute or enabling the IRQ1 interrupt handler, the user
program should read the 315h and 316h ports and generate the code of the pressed key. The way
the keys are coded depend on the type of the keypad, on the KEY_R[5…0] and KEY_C[5…0] lines
connection diagram and therefore is not described in this Manual.
4.3.13.3
Using Keyboard Interface by Discrete I/O Unit
The discrete I/O unit consists of 12 I/O channels (KEY_R[5…0] and KEY_C[5…0]), routed to J17
header. The unit is enabled by writing 1 to the bit 6 of 310h port, and at the same time the matrix
keyboard unit is disconnected from KEY_R[5…0] and KEY_C[5…0] lines.
All the 12 channels are identical. Each channel allows to read the line status and, if pull-up
resistors are connected, to set the required logical state.
The line status is read from the ports 315h (bits 7...0 correspond to the channels KEY_C[1…0] and
KEY_R[5…0]) and 316h (bits 3...0 correspond to the channels KEY_C[5…2]).
For each channel logical zero is set by writing "0" to the corresponding bit of 315h and 316h ports.
Logical one is set by writing "1" to the corresponding bit of 315h and 316h ports, if pull-up resistors
are connected.
For each channel the trigger status is retrieved via the ports 316h (bits 7...4 correspond to
KEY_R[3…0] lines) and 31Bh (bits 7...0 correspond to KEY_C[5...0] and KEY_R[5...4] lines).
Discrete I/O channel block diagram is shown in Figure 4.26.
The I/O unit structure is presented in Figure 4.27.