KEYBOARD - GAME
BY JOCHEN JAHN
As an avid gamer, I like flight simulators. However, I always had trouble
remembering the different keyboard commands for each game. As a solution,
a switchboard came to mind, with the switches activated by levers like landing
gear in airplanes. I didn’t want to write new DLLs or mess around with the
computer. After sorting my thoughts, I got the inspiration to simulate the
keyboard strokes using inputs on a microcontroller. My choice was the
PIC16F877; 24 inputs were possible, so there would be plenty of features.
In order to re-program the chip with new keyboard settings, I needed an interface to the PC. Two pins on
the 16F877 are used for a serial interface to the PC. The
loaded data should be stored in an EEPROM — no reloading required after power off! Two more pins are used
for the I2C communication between the PIC and EEPROM.
In order to not disrupt the communication between PC
and keyboard — some computers look for the keyboard at
boot-up and send commands — a relay was used to switch
between the board and keyboard. This allows the user to
keep the board plugged in all the time (even without
power on the board). The clock and the data lines to send
the keyboard code took two more pins to realize. Two
pins are used for the setup mode and the setup selector.
Those are designed as jumpers but can be wired to
switches for easy access.
After all, all of the pins are used!
A search on the Internet revealed the code being
sent from the keyboard to the PC and the data transfer
(Figure 1). The timing is very important for the PC. The
communication protocol is one start bit, seven data bits,
one parity bit, and one stop bit.
Figure 2 shows the circuit diagram for the interface.
The circuit fits on a single-layer, approximately 3” x 6” PCB
(printed circuit board).
Let’s start with the power supply. A voltage between
nine and 20 volts is applied to K1. The 7805 regulates the
incoming voltage to 5V with support from the two
capacitors. D1 protects the circuit from reverse supply
voltage. The current drawn by the circuit is between 30
and 42 mA with the relay activated; a heatsink is not
required. K2 is a double terminal to bring the regulated + 5
volts to the switches you want to use. The PIC’s (IC1)
MRCL is held up to + 5 volts, with a cap working as a
power-up delay. All inputs are connected to K5 via pulldown resistor arrays. You can use regular resistors too, if
you can’t get hold of arrays. There are 10 pin arrays: one
pin for ground and nine signals. I just bend the last pin up
(not the one where the dot is!). IC2 is the memory — a
serial EEPROM, type 24LC16B. There are other EEPROMs
that could work; I just happened to have this one on
hand. You’ll need at least a two Kbit EEPROM,to give us
256 bytes of storage.
Two pull-up resistors terminate the connection. IC3 is
the well-known MAX232 to convert the TTL serial signals
to RS-232. The programming is done through this
connection at 9600 baud — good enough if you have to
use a USB-to-serial interface. This IC is used in a standard
configuration as (described in datasheets from Maxim).
The serial RS-232 signals are routed to a nine-pin SUB-D
Pin D6 and D7 on the PIC generate the
clock and data signals for the PC. A relay
driven by pin D5 switches the signals over to
the PIC if an input changes its state and
sends the data. After finishing the data
transfer to the PC, the relay turns off again
and reconnects the regular keyboard with the
PC. K3 is connected to the PC end and K4 to
■ FIGURE 1.