We need to get various kinds of inputs for our microcontroller circuit. If we need to use key board to input data,we can either use simple buttons or 4x4 keypad…etc. In here I’m going to show you how to use a standard PS/2 computer keyboard for this purpose. It is so cheap and readily available.It is easy to replace a keyboard even for a laymen in an error.
Here I’m using a Mercury branded PS/2 keyboard I got 10 years back.I just cut the cable and got wires directly connected to the circuit.You may find a female PS/2 keyboard socket from ebay or from an old motherboard and use in your projects.
Here is the pinout of a PS/2 keyboard and how i connected to the uC. uC pins are showed in red and the colours of wires on my keyboard are shown in brackets.
Here is the circuit I used to test this.It consists of a 16F887 uC and a simple 16*2 LCD display.You can find additional information on my previous post.
Here is the connection between keyboard and the circuit
I used MikroC built in PS/2 keyboard library for this purpose. You can find more information from here.
I wrote a simple program to display the ASCII value of the pressed key and to show pressed keys in the LCD. You can change the code as you like to get key presses as you wish. The PS/2 library help page is much useful in this.Please note the bolded lines are for keyboard stuff.
sbit LCD_RS at RB5_bit; sbit LCD_RS_Direction at TRISB5_bit; void main() { Lcd_Cmd(_LCD_CLEAR); for(;;){ } |
I used following configuration options for this. Please note I’m using 8Mhz internal oscillator in my projects.
Happy keyboarding!!!!
Good one
ReplyDeleteNice Project but I have problem with PIC16F877A. Not working the register ANSEL, ANSELH and OSCCON. I tried using ADCON0 and ADCON1 but does not work. Could someone help me?
ReplyDeleteThank you
can you make a tutorial how to make a pic processor emulator pres automaticly some key on ps2 port of pc computer ? more info i can give on [email protected]. waiting for contact from you.
ReplyDelete