Computer Side Software
The software on the computer side has two main tasks. First, it listens for incoming data on the UART, determining which bytes correspond to keyboard codes. Second, it echoes these codes to the computer.
Every byte sent to the receiver is in the following format. There is an initial stream of bytes which are all 0xAA. These allow the Adaptive Gain Control on the receiver to properly handle the incoming signal. Then, 0xFF is sent. This indicates that the next byte will be a valid data byte. Finally, a data byte is sent. Since the microcontroller uses the UART to receive data from the receiver, it polls the UART regularly to see if it has received any bytes. The microcontroller decodes the sequence of bytes it receives using the state machine shown. As bytes are read from the UART they are added to a queue to be sent on the PS/2 bus.
In addition to polling the UART, the microcontroller polls the state of the PS/2 connection. When the connection is idle, and there is data to send, the microcontroller sets several state variables. These state variables cause an interrupt to generate a clock signal on the PS/2 port and to place data on the PS/2 data line. This interrupt occurs four times for every clock cycle, writing the data, stop, start and parity bits to the PS/2 connection.