PS2 keyboard

De la WikiLabs
Jump to navigationJump to search

Keyboard connected to a PS2 interface communicates through two ports:

  • a clock port, which is constant 1 when the keyboard does not send data, and passes to 0 when the data port is a valid bit (which implies that the circuit will be sensitive to the negative front of that signal);
  • A one-bit data port on which serial data is transmitted from the keyboard, valid on the negative signal of the clock signal.

Data port is bidirectional (you can read more about how it works in the Nexys 2 reference manual <ref> Nexys 2 Manual </ ref >), but we are currently interested in the keypad transmission to the development board. At the touch of a key, the keyboard will send 11-bit code stamps representing:

  • 1 start bit, which is always 0;
  • 8 bits (1 byte = 1 byte), beginning with the most insignificant bit, representing a unique code associated with the key, hereinafter called scancode ;
  • 1 parity bit, called 'checksum', which is 1 if the number of bits 1 in scancode is par;
  • 1 stop bit, which is always 1;

Warning: The Scancode is not the same as the ASCII code. The first one identifies a key, the second identifies a character.

The keyboard sends scancodes in the following situations:

  • when a key is pressed, the scancode associated with that key is sent; some keys have an extended code that requires the transmission of two scancode , and in this case the first code is always 8'hE0 (both codes will be transmitted respecting the 1 bit start protocol, 8 bit for ' 'scancode', 1 bit for 'checksum' and 1 stop bit, so for extended code keys, a total of 22 bits will be transmitted); if the key is held down, the code is retransmitted once to approximately 100ms;
  • when a key is released, before the scancode of the key is transmitted scancode 8'hF0, which indicates that that key has been released.

Extracting the scancode from the input bit sequence is done using an automata.

Key Codes

References