I am working on designing a Z80 computer and I would like to use a PS/2 Keyboard for input. I would like to use a PIO to communicate with it, but I am having trouble finding any documentation online on how to do so (outside of people saying you can).

I would like to avoid using any additional chips if possible (so no using shift registers) and I don't want to use any microcontrollers.

I believe that to start it would have to have the clock pin of the keyboard trigger an interrupt, outside of that I am not sure. If someone can write a detailed way to accomplish this, I would greatly appreciate it. Or if someone could write a code that works in my system, I would be willing to give a $10 reward via an Amazon Gift Code or something (unless you want to do it out of the generosity of your heart).

Feel free to ask questions. If you want schematics, let me know and I can email them to you. Thank you for your help in advance! I am new to all of this, so please forgive any ignorance on this project or using this forum :)


2 Answers 2


Preface, this is not really how RC.SE works. If you're looking for someone to design your hardware or write you a program, there are many sites out there where you can put a reward for someone taking the job. RC.SE is about answering your questions, as detailed as they are asked

I am working on designing a Z80 computer and I would like to use a PS/2 Keyboard [...] use a PIO

Well, this means you want to bitbang the serial protocol. Not a big deal. Essentially just follow the PS/2 protocol. It can be done synchronous or asynchronous. With a clock rate of just 10-16 kHz either way may work.

I am having trouble finding any documentation online on how to do so

All you need is a Z80 PIO manual and a protocol description, like this one which came up first when searching for "PS/2 protocol". It describes well what the interface expects/delivers, so all neccessary will be to handle the PIO as needed. All details see the Zilog manual.

Now, if you have to ask how to bitbang a rather simple protocoll like PS/2 on a Z80 PIO, then this project might bea above your level and it may be appropriate to rather use either a mouse/keyboard controller as the PC does, or, well, create your own using an AVR, PIC, 8051 or alike. Many projects exist out there, to be be easy adapted.

There is no shame in dedicating this task to another controller, it's the default way. Not at least as doing it from the Z80 will complicate your software, slow down your system and add unnecessary constrains.


I too have found a curious gap in the literature about how to program the PIO. Page 225 of the PIO manual gives the programming overview. My project is to use a PIO as a digital to analogue (D-A) converter, and I will be using 8 resistors in a binary weighted array to get 8-bit data bytes to set up the appropriate voltage.

One problem I find as an elderly gent is the presence of jargon in the advice offered all over the web, which shows my ignorance, but for instance, the original poster, like myself, might have no idea what a "bitbang" is and would have to research the term first.

The question would appear to me to involve serial data processing for which the SIO would indeed be a more sensible option. However, since Benjamin has stated exactly what he wants to do, rather than trying to change his direction, I will post the Z80 assembly code for my PIO project here in a few days (when it works!) so he can see my solution.

However, a few hours research later, I now realise that my application is too different from Benjamins so my code would be of little use to him. In looking through the Zilog Z80 PIO Technical Manual, there is a good example of an I/O interface on page 18 which I think would be a place for him to start. I'm guessing that the PS/2 keyboard has a serial data connection, so Benjamin might be able to use the circuit using a single PIO data line as an input to the PIO.

Essentially Benjamin, once you have designed the hardware circuit for the PS/2, you can select an operating mode, most likely Mode 2 (bidirectional) and then follow the PIO setup sequence in the PIO Technical manual. If you like you could email the relevant schematics to me. I would imagine you would might choose to use interrupts rather than polling although it is a bit more tricky to get working, in which case you would load an interrupt vector to point to the code to be executed by the interrupt service routine. The Zilog Applications book published by Sybex has a load of good stuff in it if you can find one

I think you need to have the Zilog books in front of you to get the hang of it. In essence it is easy, like everything else, once you have done it. With the best will in the world, there's a bit too much to put into a post like this.

Busybee I agree with you. I would have to research the PS/2 keyboard spec to know what his hardware design would look like, but guessing the Zilog circuit could be adapted with minimal work.

  • 2
    Welcome to SE/RC! Please take the tour to learn about this site. You try to do the right thing, and we appreciate that. However, your answer does not answer the OP's question. -- You are mostly right with some terms like "bitbang", but specifically this one is in wide use since years. Unfortunately the PS/2 protocol is not implemented in common serial interface chips, so engineers are forced to implement it themselves. That's why the casual solution is to use a PIO and to handle the protocol bit by bit and step by step; this is bit banging. Jan 15, 2021 at 14:56
  • BItbang simply means doing a protocol 'manually' using a generic Interface like a PIO instead of a dedicated interface. "Banging one bit at a time".
    – Raffzahn
    Jan 15, 2021 at 21:19

Not the answer you're looking for? Browse other questions tagged .