5 PS/2 connector
and pin assignments.
FIGURE 6. PS/2 serial data.
pin assignments used by the PS/2.
All data is transmitted “framed” one data byte at a
time, and each data byte is sent in a frame consisting of
11-12 bits (see Figure 6). These bits are:
FIGURE 7. PS/2
• One start bit. This is always 0.
• Eight data bits, least significant bit first.
• One parity bit (odd parity).
• One stop bit. This is always 1.
• One acknowledge bit (microcontroller to device
The parity bit is set (1) if there is an even number of
1s in the data bits, and reset (0) if there is an odd number
of 1s in the data bits. This is used for error detection. Data
changes during the clock high state, and is valid when the
clock line is low. The baud (or bit) rate is not standard and
can change from keyboard to keyboard. Typical clock
frequencies can range from 10-16. 7 kHz.
There are a few things we need to do here to retrieve
a key that is pressed on the PS/2 and then to display this
key as a ASCII character on the Experimenter LCD.
First, the Experimenter needs to sample the PS/2 data
line and clock line simultaneously and then determine
when keyboard incoming data bits are valid. For the PS/2,
Here are some important specifics:
FIGURE 8. Mini-kit.
1. The PS/2 clock can be approximated as a square
wave with a 50% duty cycle and a period of about
62. 5 to 50 microseconds. If the timer 4 interrupt is
set to sample every 25 microseconds, we are
guaranteed during a timer 4 interrupt to get at least
one sample of the PS/2 clock between falling and
rising clock edges (good enough to capture an
output PS/2 data sample).
2. Once a valid data sample is taken, it needs to be
processed as a bit in context of the larger data
frame. Once a total of 11 bits is captured, the
frame needs to be validated for correct start, stop,
and parity. If it passes this test, then it is a
legitimate key scan code.