8052 PS/2 Keyboard Interface

Thread Starter

Aggam

Joined Oct 15, 2021
11
I want to interface a PS/2 keyboard with a 8052 microcontorller. What I've found so far is this very blurry schematic and some code, and this forum replay with some c code.

However, the c code in the mentioned forum replay does not mention and electronic parts required besides the 8052 itself. Do I need anything? Does anybody have any info? Also, this is gonna be my first project in micorcontrollers (not programming tho) so I would also like to asm, what pins do I need to wire the PS/2 keyboard to in the microcontroller for the forum post code to work?

thank you in advance for your help :)
 

Papabravo

Joined Feb 24, 2006
21,159
I want to interface a PS/2 keyboard with a 8052 microcontorller. What I've found so far is this very blurry schematic and some code, and this forum replay with some c code.

However, the c code in the mentioned forum replay does not mention and electronic parts required besides the 8052 itself. Do I need anything? Does anybody have any info? Also, this is gonna be my first project in micorcontrollers (not programming tho) so I would also like to asm, what pins do I need to wire the PS/2 keyboard to in the microcontroller for the forum post code to work?

thank you in advance for your help :)
That schematic is incomplete. It shows the crystal which is used to derive the processor clock, a reset circuit, and the interface to the PS/2 keyboard. What is missing is the serial port hardware for the display. It would normally be connected to TxD and RxD which I believe are on PORT3, bits 0 and 1.
 

MrChips

Joined Oct 2, 2009
30,714
If I can recall correctly, all you need is a CLK signal and a bi-directional input-output port. Generating the CLK signal and sending/receiving data can be accomplished via software. The next part after that would be how to decode/interpret the received data.
 

trebla

Joined Jun 29, 2019
542
Do I need anything? Does anybody have any info? Also, this is gonna be my first project in micorcontrollers (not programming tho) so I would also like to asm, what pins do I need to wire the PS/2 keyboard to in the microcontroller for the forum post code to work?
I see that the code and scematics only demonstrate how to connect the MCU to PS2 keyboard. How do yo get out data from MCU is up to you. The second code seems to be faulty, in while(1) loop ps2_read() has no output variable, probably SBUF missed.
 

Thread Starter

Aggam

Joined Oct 15, 2021
11
I see that the code and scematics only demonstrate how to connect the MCU to PS2 keyboard. How do yo get out data from MCU is up to you. The second code seems to be faulty, in while(1) loop ps2_read() has no output variable, probably SBUF missed.
"How do yo get out data from MCU is up to you " wdym?
I want to read key presses.
 

Thread Starter

Aggam

Joined Oct 15, 2021
11
If I can recall correctly, all you need is a CLK signal and a bi-directional input-output port. Generating the CLK signal and sending/receiving data can be accomplished via software. The next part after that would be how to decode/interpret the received data.
CLK?
 

Thread Starter

Aggam

Joined Oct 15, 2021
11
That schematic is incomplete. It shows the crystal which is used to derive the processor clock, a reset circuit, and the interface to the PS/2 keyboard. What is missing is the serial port hardware for the display. It would normally be connected to TxD and RxD which I believe are on PORT3, bits 0 and 1.
I just want to connect a ps/2 keyboard... Do I need to do anything that is not simply connecting it into the 8052? do I need additional circuity?
 

Thread Starter

Aggam

Joined Oct 15, 2021
11
You might want to check out Ben Eater's YouTube channel where he has 3 episodes dedicated to interfacing with PS/2 keyboards:
In the videos he turns the ps/2 signal to a parallel signal. can I connect the ps/2 keyboard to 2 pins (ps2clock and ps2data) and check for ps2clock to be 1, and then take ps2data and this way construct the data without using 8 pins?
 

LesJones

Joined Jan 8, 2017
4,174
You could implement the shift register in software. I looked up the specification for "PS2 keyboard protocol" and found this link. You may find this link easier to follow than the video but the video gives you a good understanding of what is required by using hardware to do the serial to parallel conversion. I think you could also use the built in UART on the microcontroller to do the serial to parallel conversion. I have never tried to interface to a PS2 keyboard myself but I think the video and the link would be enough information to get me started.

Les.
 

MrChips

Joined Oct 2, 2009
30,714
CLK is the short hand form of CLOCK.

Read the link posted by Les. It tells you everything you need to know.
If your MCU has SCI or I2C functions you can use that.
 

Papabravo

Joined Feb 24, 2006
21,159
I just want to connect a ps/2 keyboard... Do I need to do anything that is not simply connecting it into the 8052? do I need additional circuity?
I would say that you most certainly need additional circuitry.
If you connect just the PS/2 keyboard to the microcontroller, how are you going to know that anything is happening?
How will you know that the microcontroller knows which key was pressed?
If the answer is that you don't care, then vaya con dios.
 

trebla

Joined Jun 29, 2019
542
"How do yo get out data from MCU is up to you " wdym?
I want to read key presses.
In these (pointed by you) code examples is implemented only reading keyboard data and storing it in buffer variable. How do you display contents of this variable is your decision - either you add code and hardware to display data on LCD or send trough serial port or control some other device. If this is your first MCU project, i suggest some practicing with serial port and LCD based example projects.
 

atferrari

Joined Jan 6, 2004
4,764
I want to interface a PS/2 keyboard with a 8052 microcontorller. What I've found so far is this very blurry schematic and some code, and this forum replay with some c code.
Hola Aggam

I forgot how many years ago I taught a 18F family PIC micro to communicate with a mouse following the PS/2 protocol. For that I decided to actually sweat all the details. When debugging with my my brand new DSO, the attached diagram helped me to make it work. Doubt you could find any better in the Web.

This is not a response to your request but, if you desire to dig on how it actually works (I doubt so), it could help.

Buena suerte.
 

Attachments

Thread Starter

Aggam

Joined Oct 15, 2021
11
In these (pointed by you) code examples is implemented only reading keyboard data and storing it in buffer variable. How do you display contents of this variable is your decision - either you add code and hardware to display data on LCD or send trough serial port or control some other device. If this is your first MCU project, i suggest some practicing with serial port and LCD based example projects.
I will be using LCD display, but my quiestion is, for this code, what pins do I need to connect to what - both in the 8052 and the PS/2 input, and also if I need any additional circuitry.
 

Thread Starter

Aggam

Joined Oct 15, 2021
11
I would say that you most certainly need additional circuitry.
If you connect just the PS/2 keyboard to the microcontroller, how are you going to know that anything is happening?
How will you know that the microcontroller knows which key was pressed?
If the answer is that you don't care, then vaya con dios.
IDK, that's why I'm asking. What additional circuitry am I gonna need exactly? I was planning to just have a function inp() and have it listen to the clock pin and when it starts doing stuff I'll start reading the data pin which will be directed to IO ports on the 8052.
 

trebla

Joined Jun 29, 2019
542
what pins do I need to connect to what - both in the 8052 and the PS/2 input, and also if I need any additional circuitry.
PS/2 keyboard signal levels are 5V, so no additional level translators aren't needed. You need power supply 5V about 300mA (minimum) to power up the keyboard. According attached code listing are connected MCU Port2 pins 0 (data) and 1 (clk) to PS/2 mini-DIN connector pins 1 (data) and 5 (clk). Mini-DIN pin 3 is ground and pin 4 is Vcc (+5V).
 

Thread Starter

Aggam

Joined Oct 15, 2021
11
PS/2 keyboard signal levels are 5V, so no additional level translators aren't needed. You need power supply 5V about 300mA (minimum) to power up the keyboard. According attached code listing are connected MCU Port2 pins 0 (data) and 1 (clk) to PS/2 mini-DIN connector pins 1 (data) and 5 (clk). Mini-DIN pin 3 is ground and pin 4 is Vcc (+5V).
code from which link? also so I could just connect the MCU to the PS/2 keyboard directly and use that code?
 
Top