Keyboard PS/2 to Parallel converter

Dave Dunfield dave06a at
Wed Jan 9 09:46:26 CST 2008

>> If anyone is interested, I have a very small bit of 8051 code which reads an
>> attached PC keyboard, providing the scan codes over an RS-232 link. It also 
>> supports commands to set LEDs on/off etc.  I specifically avoided using the 
>> P1 line in my design (full 8-bits  parallel I/O available even on an 8031),
>> so these are free, making it very trivial to modify this  to output parallel
>> instead of serial - it  would also be very easy to add a translate table
>> and recognition of shift/ctrl modifiers so that it would output fully decided
>> ASCII. 

> have you just the code or even the circuit PCB layout? 

I've built up hand-wired prototypes, but I have not laid out a PCB.
The schematic is just an 8051 with power/crystal attached, or an 8031
with external ROM and address latch as per any 8051/8031 datasheet.
The PC keyboard clock and data lines are attached to the pins indicated
in the comments in my code. If you want RS-232 levels, you need a level
convertor (MAX232 etc.) on the 8051/31 RX/TX signals.

> And have you an idea to how to transform the circuit from serial to
> parallel? 

Instead of polling for TX ready and writing the scancode to SBUF, just
write it to P1 (8-bit parallel output). You will also need a key-down
strobe, which you can implement via another pin, using key-down scancodes
to set, and key-up scancodes to clear.

Assuming you want ASCII instead of scancodes, you would need a translate
table (scancode to ASCII), and to recognize and track the state of the
SHIFT, CTRL keys and CAPS-LOCK state, either using alternate translate
tables (most flexible), or modifying the codes from one table accordingly.

Implementing rollover properly requires a bit more logic - once you have
processed a key-down, you must queue any other scancodes you receive until
you get the corresponding key-up, then process the queued codes after you
have released the strobe.

You can get fancier, implementing auto-repeat etc. if you like, the logic
is pretty straightforward (if key-down persists beyond the initial delay,
begin toggling the strobe at the repeat rate).


dave06a (at)    Dave Dunfield
dunfield (dot)  Firmware development services & tools:
com             Collector of vintage computing equipment:

More information about the cctalk mailing list