Interfacing a PC/AT-compatible Keyboard by Lee Davison

Hardware

The connector on the top left of the diagram is from my own 6502 boards and is as it is for two reasons. It's easy to wire on a stripboard layout and I have a lot of 26 way ribbon, headers and plugs. All the signals are directly from the 6502 except /SEL0 and /SEL1 which are used to select the block $F1xx with /SEL0 = 1 and /SEL1 = 0.

The 5 pin DIN socket is shown looking at the holes of the socket.

The circuit is built on stripboard. Layout is not critical, power is linked using 0.8mm uninsulated copper (the centre from tv coax, or similar, is ideal) and the logic is wired on the print side with self fluxing 32swg enamel covered copper wire. The header and DIN socket were re-cycled froma dead PC motherboard using a 750w hot air paint stripper.

The two capacitors are low ESR electrolytics and are placed near the GAL and near the keyboard socket. If you don't have this type to hand you can use standard electrolytics with some low value caramic capacitor, say 0.1uF, in parallel.

  

The GAL16V8A is used purely to generate the read and write strobes. Each is a negative going pulse coincident with phase 2. The interface uses just one byte in the address range. For anyone interested the equations for this chip are in atkey_01.pld and can be compiled with WinCUPL. The fuse file, atkey_01.jed, is also included.

The 74LS74 is used to latch the two lowest bits of the data bus during write access to the interface. The reset line is connected so that both of these outputs are cleared at startup (this disables the keyboard until required).

The outputs from the latches are used to drive the enable pins on two of the four buffers from the 74LS125, these are then used to drive the data and clock lines of the keyboard. The buffers have their inputs tied low so behave like open collector outputs when used like this.

The other two buffers are used to drive the data bus during read access. Note that the keyboard supplies the pullup for both the data and clock lines so with no keyboard connected you may read zero when you expect a one.

Software

The software required to read and decode a PC/AT-compatible keyboard is somewhat larger than the average hardware mini-project. The source code can be downloaded from here: kbd6502s.txt.

The software has a few basic routines to raw handle the keyboard...

There is one routine to make the keyboard look something like a standard ASCII character device. This is...

Notes on the Decoding Table

Using the Routines

A Final Thought.


Last page update: March 27, 2001.