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|