Using a keyboard

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.

KEYKEY DOWNKEY UP
A1CF0, 1C
B32F0, 32
C21F0, 21
D23F0, 23
E24F0, 24
F2BF0, 2B
G34F0, 34
H33F0, 33
I43F0, 43
J3BF0, 3B
K42F0, 42
L4BF0, 4B
M3AF0,3A
N31F0,31
O44F0,44
P4DF0,4D
Q15F0,15
R2DF0,2D
S1BF0,1B
T2CF0,2C
U3CF0,3C
V2AF0,2A
W1DF0,1D
X22F0,22
Y35F0,35
Z1AF0,1A
045F0,45
116F0,16
21EF0,1E
326F0,26
425F0,25
52EF0,2E
636F0,36
73DF0,3D
83EF0,3E
946F0,46