Here is a snippet of ASM that reads a code from a PC keyboard.
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;Waits for Keypress, returns KeyCode in W
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DataPin equ 0x06 ;PIC Pin
ClockPin equ 0x07 ;PIC Pin
Char equ 0x35 ;buffer
BitCounter equ 0x36 ;number of bits to read
GetScanCode
bsf STATUS, RP0 ;select bank 1
bsf TRISB, DataPin ;set pins as input
bsf TRISB, ClockPin
bcf OPTION_REG, NOT_RBPU ;pull-ups are enabled
bcf STATUS, RP0 ;select bank 0
call ClockWait ;wait for Pull up to take effect and
;keyboard to pull clock low
;--- Read Data Bits ----
ReadKey
clrf Char
movlw .8 ;bits to read
movwf BitCounter
ReadChar
rrf Char
bcf Char, 7 ;default value is 0
call ClockWait ;wait for clock to go high then low
btfss PORTB, DataPin ;read Data
goto Next
bsf Char, 7 ;Data is High
Next decfsz BitCounter
goto ReadChar ;read next Data Bit
call ClockWait ;Parity Bit
call ClockWait ;Stop Bit
;--- Pull Clock Line Low (keyboard will buffer any further keystrokes)
bsf STATUS, RP0 ;select bank 1
bcf TRISB, ClockPin ;set clock line as output
bcf STATUS, RP0 ;select bank 0
bcf PORTB, ClockPin ;set clock line low
movf Char, W
return
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ClockWait
;wait for clock to go high
btfss PORTB, ClockPin
goto ClockWait
ClockWait2
;wait for clock to go low
btfsc PORTB, ClockPin
goto ClockWait2
return
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Go to Radioshack and buy a ps/2 extension cable, cut of the male end and use the female end to connect to the PIC. I use a 4 pin header (power, ground, clock and data). You can search for the PS/2 pinout's on the net and connect accordingly. PC keyboards use 'make' and 'break' codes to signify a keypress and keyrelease. So you'll need to filter these and convert your scancode to a keycode. Heres a simple subroutine to convert. I think these are for the AT, I cant remember, I wrote this over a year ago. Call this routine with the scan code in W and it will return the ASCII code.
CharTable
addwf PCL
dt 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ;00-0F
dt 0,0,0,0,0,'Q','1',0,0,0,'Z','S','A','W','2',0 ;10-1F
dt 0,'C','X','D','E','4','3',0,0,' ','V','F','T','R','5',0 ;20-2F
dt 0,'N','B','H','G','Y','6',0,0,0,'M','J','U','7','8',0 ;30-3F
dt 0,0,'K','I','O','0','9',0,0,0,0,'L',0,'P',0,0 ;40-4F
dt 0,0,0,0,0,0,0,0,0,0,.13,0,0,0,0,0 ;50-5F
dt 0,0,0,0,0,0,.8,0,0,0,0,0,0,0,0,0 ;60-6F
dt 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ;70-7F
dt 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ;80-8F
dt 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ;90-9F
dt 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ;A0-AF
dt 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ;B0-BF
dt 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ;C0-CF
dt 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ;D0-DF
dt 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ;E0-EF
dt 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ;F0-FF