PDA

View Full Version : PS/2 keyboard emulation



CumQuaT
- 24th September 2009, 02:48
Hi all,

I'm having a look into a project that takes input from a circuit (push buttons) and sends it through to a PS/2 cable that can be plugged into the keyboard port of a PC. I'm trying to get the push buttons in the circuit to send the data of certain keys from the keyboard. For example, when I press one push button it sends a lower case "a" to the computer, and when I press the other push button it sends a space.

Has anyone had a play around with this before? I've been having a fiddle with using a PIC for it without much luck...

Any help would be great.

bethr
- 24th September 2009, 04:18
Has anyone had a play around with this before?


I did ! (-Played-) several yrs ago....
look at this i dont remember but it's part off a bigger program... any way I hope you can find it useful...


'ps2 emu-sw betomax
DEFINE SHIFT_PAUSEUS 15
char var Word 'character
datpin var porta.0 'Keyboard Data ' 10k pull up
clkpin var porta.1 'Keyboard Clock ' 10k pull up
col VAR BYTE ' Keypad column
row VAR BYTE ' Keypad row
key VAR BYTE ' Key value
delayer con 100 'delay btw chars
CMCON = 7
trisa =0
datpin = 1
clkpin = 1
OPTION_REG.7 = 0 ' Enable PORTB pull-ups
h var word : h = %11001100110
o var word : o = %11010001000
l var word : l = %11010010110
a var word : a = %10000111000
b var word : b = %10001100100
c var word : c = %11001000010
d var word : d = %10001000110
uno var word : uno = %10000101100
dos var word : dos = %11000111100
tres var word : tres = %10001001100
cuatro var word : cuatro = %10001001010
extcode var word : extcode = %10111000000 'e0
berak var word : berak =%11111100000 'f0
intro var word : intro = %11010110100 '5a

Start:

GOSUB Getkey ' from switch / keypad

Select CASE Key ' wich key ??
case 1
char = uno : GOSUB sendchar : pause 500
case 2
char = dos :GOSUB sendchar : pause 500
case 3
char = tres :GOSUB sendchar: pause 500
case 4
char = cuatro: GOSUB sendchar: pause 500
case 5
char = a : GOSUB sendchar: pause 500
case 6
char = b: GOSUB sendchar: pause 500
case 7
char = c : GOSUB sendchar: pause 500
case 8
char = d : GOSUB sendchar: pause 500
case 9
char =h:GOSUB sendchar: pause 500
case 10
char =o:GOSUB sendchar: pause 500
case 11
char = l:GOSUB sendchar: pause 500
END SELECT
pause 500
goto start

'actually make ps2 tx !

sendchar:
shiftout datpin,clkpin,0,[char\11] : pauseus 50
shiftout datpin,clkpin,0,[berak\11] : pauseus 50
shiftout datpin,clkpin,0,[char\11]: pauseus 50
return

CumQuaT
- 24th September 2009, 04:29
This looks neat! I'll have a crack at it!

I was wondering though, do you have more of the keyboard codes? The application I plan on using will make use of 21 keys in the end...

mackrackit
- 24th September 2009, 04:30
Did you try searching the forum? Found this.
http://www.picbasic.co.uk/forum/showthread.php?t=2736

CumQuaT
- 24th September 2009, 04:32
Yeah, I had seen that, but it is dealing with the exact opposite of what I'm trying to do. I'm not trying to interface a keyboard to a PIC.

mackrackit
- 24th September 2009, 04:49
Yeah, I had seen that, but it is dealing with the exact opposite of what I'm trying to do. I'm not trying to interface a keyboard to a PIC.
Hmmm. Did you read the whole thing? Guess not.

CumQuaT
- 24th September 2009, 05:14
When scanning a forum for similar topics, no-one reads each thread in it's entirety.

I'll have a look now you've drawn my attention to it. Thanks for the link.

mackrackit
- 24th September 2009, 05:30
When scanning a forum for similar topics, no-one reads each thread in it's entirety.

I knew I was doing something wrong :D

Archangel
- 25th September 2009, 04:32
When scanning a forum for similar topics, no-one reads each thread in it's entirety.

Nobody's ever always or never. I usually do.