Back to: Build a 6502 based computer
Adding a keyboard is a very useful addition to the computer. There has been a number of implementations of keyboard connections and protocols. I want to make my computer work with PS/2 keyboards. Technically this means that my computer will also work with AT keyboards – even though they use different connectors, electrically they are the same.
A PS/2 connector has 6 connections but only 4 are used. These are ground, 5V, clock and data. When a key is pressed, a serial frame of data that consists of 11 bits, is sent over the data line. The clock line puts out a pulse for every bit that is sent over the data line.
The 11 bits are made up from a start bit, an 8-bit keycode, a parity bit and a stop bit.
The 8-bit keycode corresponds to a unique key. To begin with, I will work on A – Z and 0 – 9. Here is a table that shows the hexadecimal representation of each key. Each key actually has 2 keycodes. This is to distinguish between a key being pressed (key down) and the release of a key (key up). There are applications where it is important to be able to identify both a key down and a key up (such as games). To identify a key up, the key down code is used with F0 preceding it.
KEY | KEY DOWN | KEY UP |
---|---|---|
A | 1C | F0, 1C |
B | 32 | F0, 32 |
C | 21 | F0, 21 |
D | 23 | F0, 23 |
E | 24 | F0, 24 |
F | 2B | F0, 2B |
G | 34 | F0, 34 |
H | 33 | F0, 33 |
I | 43 | F0, 43 |
J | 3B | F0, 3B |
K | 42 | F0, 42 |
L | 4B | F0, 4B |
M | 3A | F0,3A |
N | 31 | F0,31 |
O | 44 | F0,44 |
P | 4D | F0,4D |
Q | 15 | F0,15 |
R | 2D | F0,2D |
S | 1B | F0,1B |
T | 2C | F0,2C |
U | 3C | F0,3C |
V | 2A | F0,2A |
W | 1D | F0,1D |
X | 22 | F0,22 |
Y | 35 | F0,35 |
Z | 1A | F0,1A |
0 | 45 | F0,45 |
1 | 16 | F0,16 |
2 | 1E | F0,1E |
3 | 26 | F0,26 |
4 | 25 | F0,25 |
5 | 2E | F0,2E |
6 | 36 | F0,36 |
7 | 3D | F0,3D |
8 | 3E | F0,3E |
9 | 46 | F0,46 |