keyboard driver

Now I need to write a keyboard driver. The plan is to create a table that is in a fixed location in ROM, that stores all of the different scancodes for the different keys. I will start with all of the keys alpha-numeric and punctuation keys. I will then work on adding the ones that are affected by shift and caps lock. Finally, I will work on the special keys. Each value in the table will be a byte in size. Each row will have 16 bytes and there will be 16 rows. Therefore the table will take up 256 bytes of space in the ROM (16 x 16 bytes). For any locations that do not have a corresponding key, I will use a question mark as a placeholder. 83 – 104 keys, 256 will be more than sufficient. As mentioned previously, not all scancodes work the same. For the first part of my program I will create a table that can be used to look up which key has been pressed. This will include the alphanumeric and punctuation codes. 51 of the 104 keys.

  • get scancode
  • remove start bit, parity bit and stop bit
  • find scancode in lookup table
  • send ascii code to LCD print routine

This will then run in a loop.

ascii_tbl:
  .byte "????????????????"       ; 00-0F
  .byte "?????q1???zsaw2?"       ; 10-1F
  .byte "?cxde43?? vftr5?"       ; 20-2F
  .byte "?nbhgy6???mju78?"       ; 30-3F
  .byte "?,kio09??.?l?p??"       ; 40-4F
  .byte "????????????????"       ; 50-5F
  .byte "?????????1?47???"       ; 60-6F
  .byte "0.2568????3??9??"       ; 70-7F
  .byte "????????????????"       ; 80-8F
  .byte "????????????????"       ; 90-9F
  .byte "????????????????"       ; A0-AF
  .byte "????????????????"       ; B0-BF
  .byte "????????????????"       ; C0-CF
  .byte "????????????????"       ; D0-DF
  .byte "????????????????"       ; E0-EF
  .byte "????????????????"       ; F0-FF
keypress:
  lda ascii_tbl, x ; get ascii code
  cmp #$0a
  beq enter_pressed
  cmp #$1b
  beq esc_pressed
enter_pressed:
  lda #$00 ; move cursor to beginning of line 1
  lda #$40 ; move cursor to beginning of line 2

  lda #$14 ; move cursor to beginning of line 3
  lda #$54 ; move cursor to beginning of line 4
  jsr lcd_instruction	  
  jmp keypress 
esc_pressed:
  lda #$1 ; Clear display
  jsr lcd_instruction
  rts
ascii_tbl:
  .byte "????????????? `?"       ; 00-0F
  .byte "?????q1???zsaw2?"       ; 10-1F
  .byte "?cxde43?? vftr5?"       ; 20-2F
  .byte "?nbhgy6???mju78?"       ; 30-3F
  .byte "?,kio09??./l;p-?"       ; 40-4F
  .byte "??'?[=????",$0a,"]?\??" ; 50-5F
  .byte "?????????1?47???"       ; 60-6F
  .byte "0.2568",$1b,"??+3-*9??" ; 70-7F
  .byte "????????????????"       ; 80-8F
  .byte "????????????????"       ; 90-9F
  .byte "????????????????"       ; A0-AF
  .byte "????????????????"       ; B0-BF
  .byte "????????????????"       ; C0-CF
  .byte "????????????????"       ; D0-DF
  .byte "????????????????"       ; E0-EF
  .byte "????????????????"       ; F0-FF

The scan code for the esc key is $1b.

The scan code for the enter key is $0a.