Use the Spectrum 128 style menu below to navigate to the various sections detailing the keypad.

Keypad Main Menu Title
View History Of The Keypad
View Appearance Of The Keypad
View Editing Functions Available Via The Keypad
View Method Of Operation
View Communication Details
View Timing Details
View Hardware Details
View Software Details
View Details About Building A Compatible Keypad


Building A Compatible Keypad

The preceding sections describes the interface and protocol that the Spectrum 128 uses to communicate with the keypad. Using this information it is possible to build a compatible keypad or even a computer program that mimics the functionality of the keypad. To verify that the details I had worked out were indeed correct I designed and produced a compatible keypad and this section presents full details on its hardware and software components. The finished article is shown below.

Photo Of The Compatible Keypad Photo Of Inside The Compatible Keypad

The prototype circuit was built on veroboard, although a P.C.B. design is availabe below and is shown in the Hardware Details section. The twisted black and red wires connect to the yellow LED mounted in the top right hand corner of the keypad.

The case was manufactured by PacTec and is model HP-9VB SWITCH PAC (item code 69813-510-000). It comes with a 6 by 4 key matrix which is designed to be customisable. The matrix emerges on the underside of the front casing as ribbon cable and terminates with a 10-way connector.

For the compatible keypad the top row and the two 'missing' keys on the bottom row were removed. To use the '0' key it must be pressed left of centre and to use the 'Enter' key it must be pressed above centre. The image of the keys was drawn and stuck on top of this matrix.
Photo Of The Case For The Compatible Keypad

The connector that is fitted to the end of the keypad cable is called a 6-way left-handed handset plug (BT Type No. 630W).

The keypad circuitry is based around a PIC16C54 microcontroller rather than a PIC1652 as this is no longer in production. The PIC16C54 is similar to the PIC1652 but has 512 x 12 words of ROM, includes a watchdog timer and has a maximum clock frequency of 20MHz. The pin out is identical. In 1989 Microchip was formed from a division of General Instruments and whilst they produced a PIC16C52 microcontroller this is also no longer in production. The closest device currently available is thus the PIC16C54.

The circuit diagram for a PIC16C54 based compatible keypad is virtually the same as that used in the original keypad, and is shown below.

Compatible Keypad Circuit Diagram

The differences to the original keypad design are highlighted in red. Although the PIC16C54 can be clocked at a maximum of 20MHz the compatible keypad uses the same LC circuit as that in the real keypad and hence the nominal frequency is 3.422568MHz. The L.E.D. (D3) and series resistor (R6) are connected to I/O line RB2. This is configured in the new code to be an output and is used to indicate when communications to the keypad has been established. It will flash on momentarily whilst the Spectrum 128 polls the keypad to determine its presence and will then remain on once successful communications has been established.

Note that any device that can communicate via RS232 levels could be used as the basis of a compatible keypad, but bare in mind the signal inversions that the keypad must take into account.

The following flow diagrams show the processes that the new keypad must perform in order to make the Spectrum 128 'believe' it is communicating with a real keypad. The I/O lines referred to take into account the fact that the Spectrum 128 will 'see' inverted versions of these lines. These inversions occur since the Spectrum 128 uses true RS232 line drivers and receivers where as the keypad circuitry does not.


Compatible Keypad Software Overview

The PIC I/O lines can be configured to be inputs or outputs and so the first step is to define these. The line to the Spectrum 128 is set to a high level and hence will be read in by the Spectrum 128 as a low. Delaying for 0.5 seconds will cause the Spectrum 128 to detect an 'error' on the line and so it will reset its communication attempt to the keypad. It will then try to poll the keypad 3 seconds later. Once a poll has been received the keypad enters a loop where it alternatively scans the key matrix and monitors the line from the Spectrum 128. If a request does arrive from the Spectrum 128 then the keypad responds by sending the five row nibbles of data.

Compatible Keypad Overview Flow Chart


Looking For A Poll

When the Spectrum 128 polls the keypad it toggles its line to the keypad high. The keypad will receive this as a low and is expected to respond by setting the line back to the Spectrum 128 with the same state. The Spectrum 128 then repeats this process but this time it sets the line to the keypad low. The keypad is again expected to respond by copying the input line status. The Spectrum 128 then sets the line high again and expects the keypad to respond once more. Finally the Spectrum 128 sets the line to the keypad low and expects the keypad to respond by sending a nibble of data. The Spectrum 128 expects this nibble of data to have the second most significant bit set. Therefore the keypad must send it out as a low, i.e. 1011b. Note that the states of the other bits are unimportant and so have been set to high.

Compatible Keypad Look For A Poll Flow Chart


Sending Row Nibbles

For each of the five rows of the keypad a status bit must be generated that indicates if any keys in that row have been pressed. As each row is processed this status bit is sent to the Spectrum 128 and only if it indicates that keys have been pressed does the Spectrum 128 expect to receive a further four bits of data that define which keys were pressed. This mechanism speeds up the process of scanning the keypad since for the majority of the time there will be no keys being held down.

Compatible Keypad Send Row Nibbles Flow Chart


Sending A Nibble

The four bits that form a nibble of data are sent one at a time. All timing matters are handled by the routine to send a bit of data.

Compatible Keypad Send A Nibble Flow Chart


Sending A Bit

First the Spectrum 128 set its output line high (which the keypad will receive as a low) and expects the keypad to respond but setting the line back to the Spectrum 128 high. The Spectrum 128 then sets its output line low and this time expects the keypad to respond by setting its return line to the state of the bit to be transmitted. The Spectrum 128 then acknowledges this by setting its output line high and checking that the keypad responds with a low. Finally the Spectrum 128 restores its output line to the low state.

Compatible Keypad Send A Bit Flow Chart

New keypad software was based directly upon the flow diagrams above and was designed to take account of the tolerance in clocking frequency. The source code was written in PIC assembly language and is available along with the compiled code (in Intel HEX) format below. If you wish to program a PIC microcontroller but do not have the facilities then please feel free to contact me.

Click here to view the source code for the compatible keypad.
Click here to download the compiled code in Intel HEX format for the compatible keypad software.

The image of the keypad keys designed to fit exactly on top of the SwitchPac casing can be downloaded below.

Click here to download the UK version overlay image for the compatible keypad.
Click here to download the Spanish version overlay image for the compatible keypad.

Datasheets for the PIC16C52 and PIC16C54 can be downloaded below.

Click here to download the PIC16C52 datasheet.
Click here to download the PIC16C54 datasheet.