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


Timing Details

The Spectrum 128 operates at a clock frequency of 3.5469MHz with each machine language instruction taking at least four clock cycles (T-states). The following section describes the timing details of the communications protocol in terms of the number of T-states taken at each stage. The line levels referred to in all subsequent diagrams and text follows the standard RS232 convention, i.e. logic 0 is represented by +3V to +15V and logic 1 is represented by -3V to -15V.

The process of reading the keypad is described in the previous section entitled Method Of Operation. The diagram below shows the timing involved in reading the five keypad rows. These are quoted in T-states with the equivalent time in microseconds shown in brackets.

Reading All Rows Timing Diagram

The Spectrum 128 polls the keypad via a call to 3938h, and if successful will enter a loop 50 T-states later which reads in the five keypad rows. If communication has already been established then the poll is skipped and the Spectrum 128 proceeds to read in the five row nibbles. This skipping action takes 189 T-states. At 28 T-states into this loop a call is made to 38D8h to read the current row's key press status bit. If this bit is 0 then there were no keys pressed in that row and so the loop is repeated for the next row 97 T-states later. If a key was pressed then the row's nibble of data is read in. This happens 42 T-states later via a call to 38DFh. Upon returning from this routine, the Spectrum 128 takes 186 T-states to store the nibble before the loop is repeated for the next row.

The timing involved in polling the keypad occurs as follows. The Spectrum 128 sets the output line, bit 0, high (logic 1) and expects the input line, bit 5, from the keypad to already be high. If this is the case, the Spectrum 128 will set bit 0 low (logic 0) and will wait up to 3593 T-states for the keypad to set bit 5 low. When this occurs, the Spectrum 128 will set bit 0 high; this takes 100 T-states. It then waits up to 3917 T-states for the keypad to set bit 5 high in response. When this happens, the Spectrum 128 takes 100 T-states before it sets bit 0 low. It then waits 4121 T-states before reading in a nibble of data from the keypad, via a call to 38DFh. Bit 2 of this nibble must be set; the states of the other bits are unimportant. Upon obtaining the nibble, it takes 57 T-states to exit the poll routine.

Preparing To Read A Row Nibble Timing Diagram

The routine at 38D8h to read in a row's status bit and the routine at 38DFh to read in a row's key data nibble both make use of the same loop to read in the required number of bits. Both routines start by specifying how many bits to read in before they make use of the loop to read in that number of bits. Thus their timings are identical. A check is made to ensure that the input line, bit 5, is high; the output line, bit 0, will be low. This check takes 195 T-states when reading in a nibble and 207 T-states when reading in a bit. The bit loop is now entered and 105 T-states into this loop, the Spectrum 128 will set bit 0 high. It then waits up to 17643 T-states for the keypad to respond by setting bit 5 low. When this happens the Spectrum 128 will set bit 0 low, taking 90 T-states. Upon detecting this change, the keypad sets bit 5 to the level of the bit to transmit. The Spectrum 128 expects this bit to be available on bit 5 after 662 T-states from the time that it set bit 0 low. It then reads in the bit and sets bit 0 high after a further 153 T-states. The keypad responds by setting bit 5 high. 616 T-states after setting bit 0 high, the Spectrum 128 sets it low again. Bits 0 and 5 will now be back at their original levels. After a further 527 T-states, the loop is repeated if further bits are to be received, otherwise the routine is exited. This exiting occupies an extra 5 T-states.

Reading A Nibble Timing Diagram

In the event of the input line, bit 5, being found at the incorrect level, the Spectrum 128 will set bit 0 high and will then abandon communications with the keypad for the next three seconds. The keypad will detect that this line has gone high and will assume the start of a read cycle. However, since no further action occurs on the line, the keypad will timeout and will then await a new poll. The Spectrum 128 will also set bit 0 high when it is powered up or reset and hence this will also cause the keypad to wait for a new poll.