Continue to Site

Welcome to

Welcome to our site! is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

AT Keyboard and initialization

Not open for further replies.


Member level 5
Jan 15, 2002
Reaction score
Trophy points
Another world
Activity points

I need information about commands that PC sends to Keyboard in initialization process (when booting), or anothers configuration commands, and their sequence.
I need then to interfacing with pic


AT keyboard interface

Try hxxp:// which seems to have a good description of how it all works.

I did a google search for "PC keyboard interface ps/2 command".

I used to work for a keyboard manufacturer, and we worked out how to do it by unsoldering the mask-programmed micro on kbd and motherboard, and reverse-engineering them. The IBM AT reference manual (if you can get your hands on it - at least 15yrs old now!) has some timing diagrams and interface descriptions too.

It's an interesting bidirectional interface, fun to code a controller for, and quite hard to get right, so good luck!


IBM top secret!

mmmh I have read that web some time ago, and have some obscure points.

maybe, I could get IBM's AT keyb manual xD, buf... I will be a hard work.

The principal problem is.. timmings, and comands that host sends to keyboard and what it response: usually only simple responses are showed, as typematic, rate.. but nothing about anothers commands.. xD

IBM manual... I gotcha U!!


No big timing problems, PS/2 keyboard is syncronous, the interface uses 4 pins: 5V, GND, DATA (bidir) and CLOCK. The interface uses open collector with pullups. Never DRIVE this pins or you'll blow something. Best way is to keep the port LOW and invert it form input (HIGH via pullup) to outpt (LOW). It's not easy to do what you intend to, took me 2 months to have a fully working keybord emulator (code is copyrighted, sorry)

mmh yes, I know that interface, doing ports input or output.

I've got engouh information about timings, but sometimes it says opposite things!!. Now timings are't problem... but commands and their responses are.

mmmh www!!! I'm coming again!!

Thanks for your advisory. xD

mmmh what was most dificult for you when coding your keyb emulator?

Dear Alunaro,
you wrote:

>I need information about commands that PC sends to Keyboard in >initialization process (when booting), or anothers configuration >commands, and their sequence.
>I need then to interfacing with pic

What you need is on the August 2002 issue of 'Electronics World':
"Interfacing an AT keyboard to a PIC microcontroller".

Best Regards,


mmh do u know if there is some web with this magazine in electronico format? xDD I think it could be a little hard to find here xDD

hahahaha :roll:

Thank u.

help wit some questions.... if you can

Hi again.. xD

I have some questions and I have several responses to them, but sometimes the information contradict itself:

1. keyb have a buffer of 16 bytes, and when it generates an buffer-overrun, some docs say that the error code must be placed in 17th byte of buffer!!! (amazing! if it only has 16 byte!!). Any body knows how it works? :? I know that error code must be sent to host if buffer-overrum happen, but I dont know if I must simply send the error code in next transmition or I must place the error code byte in the buffer (pos 17th) and when host tries to read the buffer, it will read only the 17th byte of buffer (error code).
I have read answers of all flavours about it xD

2. The have 2 docs: one says that keyboard latches data from host (host send data to keyb) when clock pulse is in high level. The other, says in the rising edge of clock pulse. :?: <-- my face when I read it!

anybody can help me with this questions? I'll be very pleased xD
:lol: <-- my face if I resolve these questions

mmmh I love this forum :D <-- my face when I read this forum

Thanks for all.

Re: help wit some questions.... if you can

1. 16-byte buffer with overflow
Be realistic; after all if you've got overflows, whether you actually lose the 15th or 16th isn't going to make any real difference, so if some data has to be sent when the buffer is full, write the error code over what was in the 16th location. If you don't like the idea of losing anything, unnecessarily, you could define 'full' as having 14 codes in the buffer, write the 15th which is the overflow and add the error code in the 16th location.

2. What it's saying is that the value has to be stable at the sender while the clock is high (i.e. change before it goes high and not change until clock has gone low), and the receiver should read it as soon as the clock goes high.


yeah.. xD I thought that idea about buffer, but as I want to make a realistic keyb emulator.. I only wanted to understand how real key works, but docs aren't very clean sometimes xD

and about data stable.. I found out some docs about it, this afternoom... data must be stable at least 1us after the high level, and keyb usually latches data in rising edge of clock signal. But really, it doesn't matter because timings aren't too much strict about this xD

aah I forgot to tell that i'm makin a manual of keyb protocol but in spanish, so sometimes I need exact information and not the things that I have found xDDD English, sometimes is hard to me, and translating techinical documents about protocols, need a exact translation xD

Thank 4 u time xDD I hope don't disturb u too much !!

Dear Alunaro,
I hope I can help you a little bit.
I try to read something about the connection between
a keyboard and an host microcontroller (a pic in the example).
I found this information:

1- When serial data is sent from keyboard to PIC, data is read on the falling clock edge.

2-Sending commands to the keyboard, data is set on the falling clock edge and read by the keyboard on the rising clock edge.

The communication protocol is bidirectional, but as there are only two lines the handshaking between keyboard and PIC is more complicated. The keyboard communication is a strange mix with elements of both synchronous(separate data and clock) and asynchronous (start/stop bits)data transmission.


Please try this link
**broken link removed**
the software written in BASCOM 8051 may help you.
I tested this example and is okay.

Hey Guys,
I had to programm a keyboard controller some time ago. No paper told me that time, that you have to wait some hundret's of milliseconds before you have to send BAT complete. Timing is no problem because it's really edge triggered. To see working code go to and look for some keyboard reference designs (section USB).

look at
there are a routine for ps2 at keybord i test it and it works fine

i have converted the bascom code to assembly and it works prefectly

It is very simple if you search on Yahoo ,i don't remember detail however i know a pdf file that give information about interface between HC6805 and AT keyboard.Try your best ! Good luck

Not open for further replies.

Part and Inventory Search

Welcome to