8052 PS/2 Keyboard Interface

Thread Starter

Aggam

Joined Oct 15, 2021
11
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.
Thanks. This PDF is very useful but I don't understand something about Figure 1 in pg3 - why do I need a data and inverted data and clock and inverted clock?
 

trebla

Joined Jun 29, 2019
470
code from which link?
In first link code with schematics is pointed to Port2 pins in comments:
Code:
//PS/2- Keyboard Pin sbit PS2_DATA = P2^0;

//PS2 Data sbit PS2_CLK = P2^1;
In second link code uses Port3:

Code:
sbit data_bit=P3^3;
sbit clk=P3^2;
also so I could just connect the MCU to the PS/2 keyboard directly and use that code?
No, you should correct and modify both codes, these are examples only.
 

LesJones

Joined Jan 8, 2017
3,646
Re post #21. I/O pins A and B are configured as inputs and are used when receiving data from the keyboard. The keyboard will be generating both the data signal and the clock signal.
I/O pins C and D are configured as outputs and are used when sending data to the keyboard. The microcontroller will be generating both the clock and data signals. Both the keyboard and the microcontroller can only pull the data and clock lines low. They are pulled high by by the two resistors. So in the idle state both the clock and data lines will be at a high logic level. You could implement the data transfer totally in software just by reading and writing to the 4 I/O pins. In this case you could select almost any I/O pins. (Note There are a few pins on PIC microcontrollers that can only be used as inputs.)
Assuming the microcontroller that you are using has a USART peripheral you could use that to do a lot of the work. It would need to be configured to work in synchronous mode. In that case you would have a more limited choice of which I/O pins can be used.

Could you clarify if you will be writing your code in assembler or "C" ? I mostly work mostly with assembler as I find "C" difficult.
I have not written any code to run on an 8052.
Les.
 

Thread Starter

Aggam

Joined Oct 15, 2021
11
Re post #21. I/O pins A and B are configured as inputs and are used when receiving data from the keyboard. The keyboard will be generating both the data signal and the clock signal.
I/O pins C and D are configured as outputs and are used when sending data to the keyboard. The microcontroller will be generating both the clock and data signals. Both the keyboard and the microcontroller can only pull the data and clock lines low. They are pulled high by by the two resistors. So in the idle state both the clock and data lines will be at a high logic level. You could implement the data transfer totally in software just by reading and writing to the 4 I/O pins. In this case you could select almost any I/O pins. (Note There are a few pins on PIC microcontrollers that can only be used as inputs.)
Assuming the microcontroller that you are using has a USART peripheral you could use that to do a lot of the work. It would need to be configured to work in synchronous mode. In that case you would have a more limited choice of which I/O pins can be used.

Could you clarify if you will be writing your code in assembler or "C" ? I mostly work mostly with assembler as I find "C" difficult.
I have not written any code to run on an 8052.
Les.
I am yet to decide on the programming language. In addition, if I would not like to send commands to the PS/2 keyboard and just type on it and get input, can I just hook up CLK and DATA to some AD ports and read when CLK is 1 and then read DATA - repeat 8 times and get an input?
 
Top