Home     Contact     Projects     Experiments     Circuits     Theory     BLOG     PIC Tutorials     Time for Science     RSS     Terms of services     Privacy policy  
 Home      Projects     Experiments     Circuits     Theory     BLOG     PIC Tutorials     Time for Science   

6 March 2009
Author: Giorgos Lazaridis
The PS2 protocol

The commands

The keyboard and the host communicate together using a pre-defined command set, also part of the PS2 protocol. Those commands are detailed analyzed below.

The host commands

These are the commands that the host will send to the keyboard:

0xED - Write LEDs

This command is followed by a byte indicating the desired LEDs setting.

Bits 7-3: unused [0]
Bit 2: CapsLock LED state. [1]=On [0]=Off.
Bit 1: NumLock LED state. [1]=On [0]=Off.
Bit 0: ScrollLock LED state. [1]=On [0]=Off.

When OK, both bytes are acknowledged. If the second byte is recognized as a command, that command is acknowledged and done instead, otherwise a NACK is returned.

0xEE - Echo

This command requests an echo return by the keyboard (again 0xEE).

0xF2 - Read keyboard ID

This command reads a 2-byte keyboard ID. XT keyboards do not answer to this command. AT keyboards will reply with an ACK (0xFA) only. The MF2 and other keyboards will reply with a 2 byte ID. A 10msec delay should be considered after this command.

0xF3 - Set repeat rate and delay

Following this command is a byte with the desired delay and repeat rate.

Bit 7: unused, [0].
Bits 6-5: Delay. [0]=250, [1]=500, [2]=750, [3]=1000msec. The default value after a reset is 500msec
Bits 4-0: inter-character delay. To calculate the delay, follow the next formula:

Delay= ((2^A)*(8+B))/240 cps (characters per second)

where A=Bits 4-3 and B=bits 2-0. By default after reset the delay is 10.9 cps

0xF4 - Keyboard enable

The keyboard is automatically disabled after every transmission failure. This command re-enables the keyboard and clears its internal 16-byte buffer.

0xF5 - Set defaults and disable keyboard

This command resets the keyboard, clears the output buffer, switch off the LEDs, resets repeat rate and delay to defaults and disable the keyboard scan.

0xF6 - Set defaults

This command resets the keyboard, clears the output buffer, switch off the LEDs and resets repeat rate and delay to defaults.

0xFE - Resend

Forces the keyboard to resend the last byte sent.

0xFF - Keyboard reset

Reset and runs a self-test. The self-test (BAT) will return aa if OK or fc if there is a problem. During this test, all the LEDs flashes once.

The keyboard commands

The keyboard will respond to host commands or to external events (like key presses) with it's own commands as follows:

0xFA - Acknowledge (ACK)

Sends the ACK command to the host when needed.

0xAA - Power on self test passed (BAT completed)

When the host sends a reset command to the keyboard (ff), it must run a self test and answer with this command.

0xEE - Echo

This command requests an echo return by the host (again 0xEE).

0xFE - Resend

Forces the host to resend the last byte sent.

0x00 - Error or buffer overflow

This command is sent when an error or a buffer overflow occurs.

0xFF - Error or buffer overflow

This command is sent when an error or a buffer overflow occurs.

Relative pages
  • Basic transistor circuits
  • PWM signal theory
  • Learn about the origin of Internet, how it started and the course to what we know today as Internet
  • Learn about the WiFi interferences to the human body
  • How to make a MAMME arcade machine controller without the use of a keyboard
  • Learning PICs @ PCB Heaven On-Line Book

  • Comments


      Email (shall not be published)


    Notify me of new posts via email

    Write your comments below:
    BEFORE you post a comment:You are welcome to comment for corrections and suggestions on this page. But if you have questions please use the forum instead to post it. Thank you.


  • At 25 March 2014, 14:21:47 user Bruce Smith wrote:   [reply @ Bruce Smith]
    • Your diagram of the PS/2 connector could use some changes:

      1. There is no description of whether this is a diagram of the female connector on the host PC or the male connector on the device (mouse or keyboard).
      2. The "notch" in the mini-DIN connector is at the same end as the square polarization tab, not at the opposite end as you have drawn it.
      3. The pin numbers for every other PS/2 connector in the Internet including Wikipedia.org has the pin numbers alternating from side to side instead of around the circle as you have drawn it.

      Perhaps you could change your diagram so that it matches the Wikipedia.org diagram?

  • At 21 December 2010, 10:54:24 user Slam wrote:   [reply @ Slam]
    • Dear Kammenos,

      As far as I know, the data sent to PS/2 mouse are latched on the rising edge of CLK. The data received from PS/2 mouse are latched on the falling edge of CLK instead.

  • At 30 September 2010, 9:43:26 user Kammenos wrote:   [reply @ Kammenos]
    • I think i have not write this quite clear. I mean that data are read on the falling edge of the clock all the time. The phrase "except the first one...." does not mean that the first bit is read on the rising edge. I mean that the first bit is not data (it is the start bit actually).

  • At 30 September 2010, 8:12:42 user tmp wrote:   [reply @ tmp]
    • From the host to the keyboard:
      "All data are read from the keyboard after every falling edge excluding the first one that is for synchronization purposes."

      -- Are you sure this is correct?

  • At 9 June 2010, 17:49:40 user Shourav wrote:   [reply @ Shourav]
    • Thanks a lot. The timing diagram makes things really clear.

  • At 17 March 2010, 6:02:07 user David wrote:   [reply @ David]
    • I do not know if it is helpful of my design.

    reddit this Reddit this

     HOT in heaven!

    NEW in heaven!

    New Theory: Basic Transistor Circuits

     Contact     Forum     Projects     Experiments     Circuits     Theory     BLOG     PIC Tutorials     Time for Science     RSS   

    Site design: Giorgos Lazaridis
    © Copyright 2008
    Please read the Terms of services and the Privacy policy