You can use this to interface a PIC to an XT type keyboard. The code as
is does not do anything else.
The scan code bit 0 determines whether a key is pressed (1) or released
(0).

If you need more scan codes I'm afraid you will need to find a table for
them on the web somewhere as I have missplaced my old copy.
Sorry about the length.

          movlw .9            ; set bit counter
          movwf bitcnt
          clrf flag1

mnloop    btfss porta,KBclk   ; (0) test for low/high keyboard clock
          goto clkizlo
          ;
          btfss flag1,hilo    ; (1) ignore if flagged high already
          bsf flag1,hilo      ; (1) flag clock is high
          goto mnloop
          ;
clkizlo   btfss flag1,hilo    ; (1) ignore if flagged low
already
          goto mnloop
          ;
          bcf flag1,hilo      ; (1) flag clock is low
          bcf status,carry
          btfsc porta,KBdat   ; (1) test data input
          bsf status,carry
          rlf keydata         ; move data bit into data register
          decfsz bitcnt       ; test for complete data byte
          goto mnloop         ; not yet
          ;
          movlw .9            ; reset bit counter
          movwf bitcnt
          btfsc keydata,0     ; if bit 0 = 1 then key was released, so
          goto usekey         ; decypher and use keypress
          ;
          btfsc flag1,kysv    ; (2) ignore if key data obtained already
          goto mnloop         ; key is held down and repeating
          ;
          bsf flag1,kysv      ; (2) flag, key data has been read
          bcf status,carry
          rrf keydata,w       ; prepare data to convert to ASCII
          call Table          ; convert to ASCII
          movwf keydata       ; store data until key is released
          goto mnloop
          ;
usekey    ; use keypress
          ;
          goto mnloop

          ;         ______________________________________
          ;
          ; CONVERT KEY DATA TO ASCII
          ;
Table     addwf pcl
          retlw '-'             ; 0
          retlw '-'
          retlw 'd'
          retlw '-'
          retlw 'q'
          retlw '-'
          retlw 'b'
          retlw '-'
          retlw '7'
          retlw '-'
          retlw '-'             ; 10
          retlw '-'
          retlw 'o'
          retlw '-'
          retlw '-'
          retlw '-'
          retlw '3'
          retlw '-'
          retlw 'j'
          retlw '-'
          retlw 't'           ; 20
          retlw '-'
          retlw '-'
          retlw '-'
          retlw '-'
          retlw '-'
          retlw 'z'
          retlw '-'
          retlw '-'     ; carriage return
          retlw '-'
          retlw '-'             ; 30
          retlw '-'
          retlw '1'
          retlw '-'
          retlw 'g'
          retlw '-'
          retlw 'e'
          retlw '-'
          retlw 'm'
          retlw '-'
          retlw '9'           ; 40
          retlw '-'
          retlw '-'
          retlw '-'
          retlw '-'
          retlw '-'
          retlw '-'
          retlw '-'
          retlw '5'
          retlw '-'
          retlw 'l'           ; 50
          retlw '-'
          retlw 'u'
          retlw '-'
          retlw '-'
          retlw '-'
          retlw '-'
          retlw '-'
          retlw 'c'
          retlw '-'
          retlw 'a'           ; 60
          retlw '-'
          retlw '-'
          retlw '-'
          retlw '-'
          retlw '-'
          retlw 'f'
          retlw '-'
          retlw 'w'
          retlw '-'
          retlw 'n'           ; 70
          retlw '-'
          retlw '8'
          retlw '-'
          retlw '-'
          retlw '-'
          retlw 'p'
          retlw '-'
          retlw ' '
          retlw '-'
          retlw '4'           ; 80
          retlw '-'
          retlw '-'
          retlw '-'
          retlw 'y'
          retlw '-'
          retlw '-'
          retlw '-'
          retlw '-'
          retlw '-'
          retlw 'x'           ; 90
          retlw '-'
          retlw '-'
          retlw '-'
          retlw '-'
          retlw '-'
          retlw '2'
          retlw '-'
          retlw 'h'
          retlw '-'
          retlw 'r'           ; 100
          retlw '-'
          retlw '-'
          retlw '-'
          retlw '0'
          retlw '-'
          retlw '-'
          retlw '-'
          retlw '-'
          retlw '-'
          retlw '-'             ; 110
          retlw '-'
          retlw '6'
          retlw '-'
          retlw '-'
          retlw '-'
          retlw 'i'
          retlw '-'
          retlw '-'
          retlw '-'
          retlw '-'             ; 120
          retlw '-'
          retlw 'v'
          retlw '-'
          retlw 's'
          retlw '-'
          retlw '-'
          retlw '-'