Program and Hardware Design:
First,
a little background about the ps/2 protocol:
The ps/2 protocol is a bi-directional protocol that uses a Clock line
and a Data line. The clock is always
generated by the keyboard and each clock cycle has to be between 60 and 100uSec
long. When no data is being sent by
either the keyboard or the computer, both the Clock line and the Data line are
pulled up to 5V through pull up resistors on the keyboard side and the computer
side. When the keyboard sends data, it
generates clock pulses that go from 0V to 5V on the Clock line and it sends its
data on the Data line. If the computer
wants to send a command to the keyboard, the computer pulls the Clock line low
to 0V for at least 100uSec. After the
100uSec elapse, the computer releases the Clock line, places a start bit of 0V
on the Data line and waits for the keyboard to start generating clock
pulses. At each clock pulse, another bit
of data is placed on the Data line by the computer. Although the clock is
generated by the keyboard, the computer has control over the
communication. If the computer wants to
stop the keyboard from sending data, it just pulls the Clock line low. The keyboard then has to wait for the Clock
line to be released before it can start generating a clock and sending data. When the keyboard sends data to the computer,
it sends a total of 10 bits: A start bit (0V), 8 data bits, a parity bit and a
stop bit (1V). When the computer sends commands
to the keyboard, it also sends a total of 10 bits: A start bit(0V), 8 data bits, a parity bit
and a stop bit (1V). However, on the
next clock cycle after the stop bit of the command is sent, the keyboard has to
respond with an acknowledge bit (0V) on the data line. For more details on the ps/2 protocol, please
see Adam
Chapweske’s webpage.