;******************************************************************************** ; * ; AT keyboard interface V2.0 * ; * ; Uses PIC 16F84 @ 4 MHz * ; * ; Author Danny G Page July/August 2011 * ; Modified Alan Maunder June 2016 * ; * ; DESCRIPTION: * ; ============ * ; This routine converts AT keyboard scan patterns to ASCII characters * ; and outputs them as 7 parallel bits on PORTB B0-B6 plus a positive * ; strobe pulse on B7 * ; PortA0 = keyboard data and PortA1= keyboard clock * ; For the 16F84 if PortA and PortB latches are set to 0 this level will * ; not be transfered to the pins until the TRIS registers are set to 0 * ; i.e. to output. If the TRIS registers are set to 1 (input) the pins * ; will present a high impedance state and since the two pins in question * ; are tied to +5V via a 10k resistor, they will be read as 1 to any * ; external circuit i.e. the keyboard clock and data pins in this case. * ; Thus if the two latches are set to 0, the output on A0 and A1 pins may * ; be controlled by the values of the respective TRIS register bits. * ; Thus for k/b data line, if TRISA,0=1 (i/p) PORTA0 -> Hi imp (and +5V) * ; and if TRISA,0=0 (o/p) PORTA0 -> 0V * ; for k/b clock line, if TRISA,1=1 (i/p) PORTA1 -> Hi imp (and +5V) * ; and if TRISA,0=0 (o/p) PORTA0 -> 0V * ; * ; * ; Modifications * ; ============= * ; This interface was designed to be used with a Microtan 65 computer * ; which requires an ASCII keyboard with strobe as decribed above. The * ; computer also requires a Line Feed(LF ASCII 0A) Key, * ; and a reset (Active low) line which is normally supplied by a separate * ; switch which holds a reset line high(+5v) until pressed when the line * ; is forced low. As a result the following keys were selected as * ; replacements : Num pad Enter for LF and Home for reset. * ; The LF key (Num pad Enter) produces ASCII 0x0A * ; The Reset/Home key produces a low level on PORTA,2 * ; * ; Further modifications: reducing length of the Noshift and Shifton * ; lookup tables to provide space for further 2 tables (Caps Lock and * ; Control Key Pressed). Keyboard reset inserted during Initialisation * ; so keyboard LEDs remain in sync with LEDstat following reset. * ; * ; Credits * ; ======= * ; * ; An excellent article by Craig Peacock which may be found on his * ; web site at www.beyondlogic.org/keyboard/keybrd.htm. * ; * ;******************************************************************************** LIST P=16F84, R=DEC INCLUDE "p16f84.inc" __CONFIG _CP_OFF & _WDT_OFF & _XT_OSC & _PWRTE_ON ;***** PIC register equates***** tmr0 equ 0x01 ; rtcc optreg equ 0x81 ; Option register zbit equ 2 ; Zero bit in status register carry equ 0 ; carry bit in status register ;***** Equates ***** kdata equ 0 ; PortA keyboard data pin kclk equ 1 ; PortA keyboard clock pin ;***** keyboard status bits ***** rctrl equ 7 ; If true, Right Ctrl Pressed lctrl equ 6 ; If true, Left Ctrl Pressed ralt equ 5 ; If true, Right Alt Pressed lalt equ 4 ; If true, Left Alt Pressed caploc equ 2 ; If true, Caps lock pressed rshift equ 1 ; If true, Right Shift Key Pressed lshift equ 0 ; If true, Left Shift Key Pressed ;***** Keyboard LED status bits***** pscrlck equ 4 ; if true Scroll lock pressed pnumlck equ 3 ; if true Num Lock pressed caplock equ 2 ; If true, Caps Lock is On (Active) numlock equ 1 ; if true, Num Lock is On (Active) scrlock equ 0 ; If true, Scroll lock is On (Active) ;***** variables ***** count equ 12 SC equ 13 ; Scan code or ASCII code temp equ 14 PAR equ 15 ; parity register. Lsb = parity bit LEDstat equ 16 ; keyboard leds' status register KBDstat equ 17 ; keyboard status ;****** MACROS ****** BANK1 macro ; Select register bank 1 bsf STATUS, RP0 ; Select bank1 registers endm BANK0 macro ; Select register bank 0 bcf STATUS, RP0 ; Select bank0 registers endm Setcklo macro ; k/b clock bit (A1) -> 0 (inhibits k/b transfers) BANK1 bcf TRISA & 0x07f,kclk ; TRISA1->0 (o/p) A1 pin -> 0 BANK0 endm Relclk macro ; Release clock. k/b clock bit to hi-z (+5V) - idle state (allows k/b transfers) BANK1 bsf TRISA & 0x07f,kclk ; TRISA1->0 (o/p) A1 pin -> 0 BANK0 endm Setdatlo macro ; k/b data bit (A0) -> 0 (used transmitting data to k/b) BANK1 bcf TRISA & 0x07f,kdata ; TRISA0->0 (o/p) A0 pin -> 0 BANK0 endm Setdathi macro ; k/b data bit to hi-z (+5V) - (used transmitting data to k/b) BANK1 bsf TRISA & 0x07f,kdata ; TRISA1->0 (i/p) A1 pin -> hi-z (or +5V) BANK0 endm wait macro time ; calls subroutine wait which expects to find the time(in ms) in reg temp movlw time ; Delay expects delay value in w reg call Delay endm org 0x00 ;***** Initialise ***** start clrf PORTB ; all o/p data latches -> 0 (ASCII o/p) clrf PORTA ; data(A0), clock(A1) and Reset(A2) latches -> 0 ; the data(A0) and clock pins are then toggled ; from 0 to high impedance (+5v via 10k) by the state of TRISA BANK1 clrf TRISB & 0x07F ; Set all Port B pins to output (latched values to pins) movlw 0x1F ; Set all PortA pins to input movwf TRISA & 0x07f ; Idle state i.e. +5v via 10k movlw b'00000111' ; set up timer pre-scaler to /256 movwf optreg & 0x07F BANK0 ;***************************************************** ;* * ;* rstkb - Resets Keyboard * ;* * ;***************************************************** rstkb movlw 0xFF ; Reset keyboard movwf SC call transmit ;***************************************************** ;* * ;* rstflag - Resets Status and LED Flags. * ;* * ;***************************************************** rstflag clrf KBDstat ; clear keyboard status flags clrf LEDstat ; Clear LED status flags ;***************************************************** ;* * ;* main - Main Keyboard Decoding Routine. Once key * ;* been decoded, program should return here * ;* * ;***************************************************** main call Receive ; Main keyboard decoding routine. Scan code now in SC movlw 0xF0 ; A key has been released xorwf SC,w bnz main1 goto release main1 movlw 0xAA ; Successful completion of BAT xorwf SC,w bnz main2 goto rstflag main2 movlw 0xE0 ; Extended keys xorwf SC,w bnz main3 goto extend ; Extended keys routines main3 movlw 0x12 ; Left shift key pressed? xorwf SC,w bnz main4 bsf KBDstat,lshift ; set left shift flag main4 movlw 0x59 ; Right shift key pressed? xorwf SC,w bnz main5 bsf KBDstat,rshift ; set right shift flag main5 movlw 0x14 ; Left ctrl? xorwf SC,w bnz main6 bsf KBDstat,lctrl ; set left ctrl flag main6 movlw 0x11 ; Left alt? xorwf SC,w bnz main7 bsf KBDstat,lalt ; set left alt flag main7 movlw 0x58 ; Caps lock? xorwf SC,w bnz main8 btfss KBDstat,caploc ; caps lock set goto caps ; caps lock not set bsf KBDstat,caploc ; set caploc flag again main8 movlw 0x7E ; Scroll lock pressed? xorwf SC,w bnz main9 btfss KBDstat,pscrlck ; caps lock set goto scrl bsf KBDstat,pscrlck main9 movlw 0x77 ; Num lock pressed? xorwf SC,w bnz main10 btfss KBDstat,pnumlck ; num lock set goto nums bsf KBDstat,pnumlck main10 movlw 0x7E ; Last value in Look-up table xorwf SC,w bnz main11 goto main ; Out of bounds main11 btfsc KBDstat,lctrl ; left control not set goto ctrl_on ; control set btfsc KBDstat,rctrl ; right control not set goto ctrl_on ; controlset btfsc LEDstat,caplock ; Caps lock not set goto caps_on ; caps lock set btfsc KBDstat,rshift ; right shift not set goto shifton btfsc KBDstat,lshift ; left shift not set goto shifton declc movlw HIGH Noshift ; get correct page for PCLATH movwf PCLATH ; prepare right page bits for table read movf SC,w call Noshift ; Get keyboard char in Noshift lookup table movwf SC ; ASCII code in SC goto main12 caps_on btfsc KBDstat,rshift ; rshift not set goto shifton ; if caps lock & rshift, use Shift Look-up table btfsc KBDstat,lshift ; lshift not set goto shifton ; if caps lock & lshift, use Shift Look-up table movlw HIGH CapsLk ; get correct page for PCLATH movwf PCLATH ; prepare right page bits for table read movf SC,w call CapsLk ; Get keyboard char in Shift lookup table movwf SC ; ASCII code in SC goto main12 ctrl_on movlw HIGH Ctrl ; get correct page for PCLATH movwf PCLATH ; prepare right page bits for table read movf SC,w call Ctrl ; Get keyboard char in Shift lookup table movwf SC ; ASCII code in SC goto main12 shifton movlw HIGH Shift ; get correct page for PCLATH movwf PCLATH ; prepare right page bits for table read movf SC,w call Shift ; Get keyboard char in Shift lookup table movwf SC ; ASCII code in SC main12 movf SC,f ; check if SC=0 bz main ; Scan code not in table display movf SC,w movwf PORTB ; Show SC (Ascii value) on leds wait 1 ; wait approx 1 ms bsf PORTB,7 ; strobe o/p -> 1 wait 2 ; strobe length approx 2 ms bcf PORTB,7 wait 10 ; hold data for further 10 ms clrf PORTB ; clear output goto main ;***************************************************** ;* * ;* caps - Toggle Status of Caps lock and Echo to * ;* Keyboard * ;* * ;***************************************************** caps bsf KBDstat,caploc ; Set caploc flag to prevent routine being called again movlw b'00000100' ; w=00000100 (0x04) xorwf LEDstat,f ; toggle caps lock flag in LEDstat goto LEDshow ;***************************************************** ;* * ;* nums - Toggle Status of Caps lock and Echo to * ;* Keyboard * ;* * ;***************************************************** nums bsf KBDstat,pnumlck ; Set Num lock flag to prevent routine being called again movlw 0x02 ; w=00000010 xorwf LEDstat,f ; toggle num lock flag in LEDstat goto LEDshow ;***************************************************** ;* * ;* scrl - Toggle Status of Scroll lock and Echo to * ;* Keyboard * ;* * ;***************************************************** scrl bsf KBDstat,pscrlck ; Set scroll lock flag to prevent routine being called again movlw 0x01 ; w=00000001 xorwf LEDstat,f ; toggle scroll lock flag in LEDstat goto LEDshow ;***************************************************** ;* * ;* release - A Key has been Released * ;* * ;***************************************************** release call Receive ; Get scan code of released key rel3 movlw 0x12 ; Left shift key released ? xorwf SC,w bnz rel4 bcf KBDstat,lshift ; clear left shift flag rel4 movlw 0x59 ; Right shift key released ? xorwf SC,w bnz rel5 bcf KBDstat,rshift ; clear Right shift flag rel5 movlw 0x14 ; Left Ctrl key released ? xorwf SC,w bnz rel6 bcf KBDstat,lctrl ; clear left ctrl flag rel6 movlw 0x11 ; Left Alt key released ? xorwf SC,w bnz rel7 bcf KBDstat,lalt ; clear left Alt flag rel7 movlw 0x58 ; Caps Lock key released ? xorwf SC,w bnz rel8 bcf KBDstat,caploc ; clear Caps Lock flag rel8 movlw 0x7E ; Scroll Lock key released ? xorwf SC,w bnz rel9 bcf KBDstat,pscrlck ; clear Scroll Lock flag rel9 movlw 0x77 ; Num Lock key released ? xorwf SC,w bnz rel10 bcf KBDstat,pnumlck ; clear Num Lock flag rel10 goto main ;***************************************************** ;* * ;* LEDshow - Copies the 3 LSB of the LED register to * ;* keyboard for the keyboards Status LED's * ;* E.g. Num Lock, Caps Lock, Scroll Lock * ;* * ;***************************************************** LEDshow movlw 0xED ; Transmit prepare for transmission movwf SC call transmit call Receive ; get Ack from k/b movf LEDstat,w ; get LED status byte andlw 0x07 movwf SC call transmit ; transmit LED status bits call Receive ; Ack goto main ;*********************** Subroutines ************************ ;***************************************************** ;* * ;* Probe - Simulate a logic probe to examine the * ;* value of a bit by means of PORTB,7 * ;* * ;***************************************************** probe btfss LEDstat,caploc ; this line must be adjusted to select the required bit goto p2 ; bit is lo bsf PORTB,7 p1 return p2 bcf PORTB,7 goto $-2 ;***************************************************** ;* * ;* extend - An extended key has been pressed * ;* * ;***************************************************** extend call Receive ; Get byte following E0h movlw 0xF0 ; An extended key has been released xorwf SC,w bnz extend1 goto rel_ext extend1 movlw 0x11 ; Right Alt pressed xorwf SC,w bnz extend2 bsf KBDstat,ralt goto extend7 extend2 movlw 0x14 ; Right Ctrl pressed xorwf SC,w bnz extend3 bsf KBDstat,rctrl goto extend7 extend3 movlw 0x71 ; Delete key has been pressed xorwf SC,w bnz extend4 movlw 0x7F ; ascii delete goto extend7 extend4 movlw 0x5A ; Enter on Num Keypad has been pressed xorwf SC,w bnz extend5 movlw 0x0A ; ascii LF goto extend7 extend5 movlw 0x6C ; Scan code for Home (used for Microtan65 reset) xorwf SC,w bnz extend6 goto mtrst extend6 movlw 0x4A ; '/' key on Num Keypad has been pressed xorwf SC,w bnz main movlw '/' extend7 movwf SC goto display ;***************************************************** ;* * ;* mtrst - Reset for Microtan65, PORTA,2 set to 0 * ;* * ;***************************************************** mtrst BANK1 bcf TRISA & 0x07f,2 ; Set PortA pin2 to 0 : output reset state i.e. 0 BANK0 goto main ;***************************************************** ;* * ;* rel_ext - An extended key has been released * ;* * ;***************************************************** rel_ext call Receive ; get next byte movlw 0x11 ; Right Alt released xorwf SC,w bnz rel_ex2 bcf KBDstat,ralt goto main rel_ex2 movlw 0x14 ; Right Ctrl released xorwf SC,w bnz rel_ex3 bcf KBDstat,rctrl goto main rel_ex3 movlw 0x6C ; Home (Microtan65 reset) released xorwf SC,w bnz rel_ex4 BANK1 bsf TRISA & 0x07f,2 ; Set PortA pin2 to input : Idle state i.e. +5v via 10k BANK0 rel_ex4 goto main ;***************************************************** ;* * ;* Receive - Get a Byte from the Keyboard. Result * ;* stored in SC. * ;* * ;***************************************************** Receive clrf SC ; clear scan code movlw 8 ; Number of bits movwf count clrf PAR ; Clear parity register Relclk ; Release clock (Clear to send) btfsc PORTA,kclk ; Wait for start bit goto $-1 ; Clock is 1 so check A0 again btfsc PORTA,kdata ; Check k/b data lo (Start bit) goto Receive ; k/b data hi so false start bit. Restart ; data is to be put in scan code register SC Recdata rrf SC,f ; Move SC bit0 into carry call Highlow ; Wait for hi to lo transition btfsc PORTA,kdata ; k/b data 0 goto Recset ; k/b data 1 bcf SC,7 ; write 0 into SC bit7 goto Recnext Recset bsf SC,7 ; write 1 into SC bit7 incf PAR,f ; bump parity register Recnext decf count,f btfss STATUS,zbit ; count=0. All bits read goto Recdata ; loop until 8 bits received call Highlow movf PORTA,w ; parity bit in w bit0 xorwf PAR,w ; parity bit detection andlw 0x01 ; isolate bit0 btfsc STATUS,zbit ; result not zero goto r_error ; result=0 - error call Highlow ; wait for stop bit btfsc PORTA,kdata ; stop bit=0 (error) return ; Scan code is now in SC r_error movlw 0xFF ; Display all 1s movwf PORTB ; goto Receive ;***************************************************** ;* * ;* highlow - Waits for next High to Low Transistion * ;* on the Clock Line * ;* * ;***************************************************** Highlow ; Waits for next Hi to Lo transition on clock btfss PORTA,kclk ; Loop until clock is high goto $-1 ; Clock is 0 so check A0 again btfsc PORTA,kclk ; Wait for clock to go low goto $-1 ; Clock is 1 so check A0 again return ;***************************************************** ;* * ;* Transmit - Send Data stored at SC to the * ;* Keyboard. Result * ;* * ;***************************************************** transmit movlw 8 movwf count ; 8 data bits Setcklo ; Hold keyboard with keyboard clock low movlw 0x15 ; wait loop : approx 64 us @ 4 Mhz movwf temp tx1 decfsz temp,f goto tx1 clrf PAR ; clear parity register BANK1 ; bcf TRISA & 0x07f,kdata ; Set k/b data line lo bsf TRISA & 0x07f,kclk ; Release k/b clock line, set to input BANK0 call Highlow tloop rrf SC,f ; lsb of SC to carry btfsc STATUS,carry ; bit is 0 goto mark Setdatlo ; KEYBOARD DATA LINE -> 0 goto next mark Setdathi incf PAR,f ; parity calculation next call Highlow ; wait for hi to lo transition decf count,f bnz tloop movf PAR,w andlw 0x01 bnz clr_par ; PAR is odd so transmit 0 set_par Setdathi ; PAR is even so transmit 1 goto tr_ackn clr_par Setdatlo ; Set k/b data line lo tr_ackn call Highlow ; wait for hi to lo clock transition Setdathi ; release data line call Highlow ; wait for hi to lo transition btfsc PORTA,kdata ; check for Ack (data line lo) goto terror ; data line hi so no Ack. Error condition btfss PORTA,kclk ; wait for idle clock goto $-1 Setcklo ; Hold keyboard with keyboard clock low return terror movlw 0xFF ;reset movwf SC call transmit return ;******************************************************** ;* * ;* Delay timer - delay = 1ms * value in w register * ;* * ;******************************************************** Delay movwf count db1 clrf tmr0 ; clear to start btfss tmr0,2 ; test rtcc bit 2 (4*0.256=1.024ms) goto $-1 ; bit 6 not clear yet decfsz count,f ; decrement until zero goto db1 ; count <> 0 retlw 0 ;*********************************************************** ;* * ;* Noshift - Lookup Table Used when Shift not pressed * ;* * ;*********************************************************** org 0x200 Noshift ; (used for characters typed when shift button not active) addwf PCL,F ; SC retlw 0 ; 00 invalid entry retlw '9' ; 01 F9 -> 9 0x01 retlw 0 ; 02 retlw '5' ; 03 F5 -> 5 retlw '3' ; 04 F3 -> 3 retlw '1' ; 05 F1 -> 1 retlw '2' ; 06 F2 -> 2 retlw '2' ; 07 F12 -> 2 retlw 0 ; 08 retlw '0' ; 09 F10 -> 0 retlw '8' ; 0A F8 -> 8 0x0A retlw '6' ; 0B F6 -> 6 retlw '4' ; 0C F4 -> 4 retlw 0x09 ; 0D TAB retlw '`' ; 0E ` or ¬ retlw 0 ; 0F retlw 0 ; 10 retlw 0 ; 11 Left Alt retlw 0 ; 12 Left Shift retlw 0 ; 13 retlw 0 ; 14 Left Ctrl retlw 'q' ; 15 DT: MPASM directive to create a table (retlw x) retlw '1' ; 16 1=(1 or !) retlw 0 ; 17 retlw 0 ; 18 retlw 0 ; 19 DT "zsaw2" ; 1A-1E (2 or ") retlw 0 ; 1F retlw 0 ; 20 DT "cxde43"; 21-26 (3 or £), (4 or $) retlw 0 ; 27 retlw 0 ; 28 retlw ' ' ; 29 SPACE DT "vftr5" ; 2A-2E (5 or %) retlw 0 ; 2F retlw 0 ; 30 DT "nbhgy6"; 31-36 (6 or ^) retlw 0x1B ; 37 retlw 0 ; 38 retlw 0 ; 39 DT "mju78" ; 3A-3E (7 or &), (8 or *) retlw 0 ; 3F retlw 0 ; 40 DT ",kio09"; 41-46 (, or <), (0 or )), (9 or () retlw 0 ; 47 retlw 0 ; 48 DT "./l;p" ; 49-4D (. or >), (/ or ?), (; or :) retlw '-' ; 4E (- or _) retlw 0 ; 4F retlw 0 ; 50 retlw 0 ; 51 DT "'" ; 52 (' or @) retlw 0 ; 53 retlw '[' ; 54 ([ or {) retlw '=' ; 55 (= or +) retlw 0 ; 56 retlw 0 ; 57 retlw 0 ; 58 CAPS LOCK, check and alter CAPflag on key release retlw 0 ; 59 Right Shift goto _SHIFT ; SHIFT retlw 0Dh ; 5A Enter retlw ']' ; 5B (] or }) retlw 0 ; 5C retlw '#' ; 5D (# or ~) retlw 0 ; 5E retlw 0 ; 5F retlw 0 ; 60 retlw 0x5C ; 61 (0x5C = '\') retlw 0 ; 62 retlw 0 ; 63 Up Arrow retlw 0 ; 64 Delete retlw 0 ; 65 End retlw 0x08 ; 66 Backspace retlw 0 ; 67 Insert retlw 0 ; 68 retlw '1' ; 69 (NUM 1 or End) retlw 0 ; 6A > retlw '4' ; 6B (NUM 4 or Left) retlw '7' ; 6C (NUM 7 or Home) retlw 0 ; 6D retlw 0 ; 6E retlw 0 ; 6F retlw '0' ; 70 NUM - 0 or INS retlw '.' ; 71 NUM - Del or . retlw '2' ; 72 NUM - 2 or DOWN retlw '5' ; 73 NUM - 5 retlw '6' ; 74 NUM - 6 or RIGHT retlw '8' ; 75 NUM - 8 or UP retlw 0x1B ; 76 ESC retlw 0 ; 77 NUM LOCK retlw 0 ; 78 F11 retlw '+' ; 79 NUM - + (Plus) retlw '3' ; 7A NUM 3 or PAGE DOWN retlw '-' ; 7B NUM - - (Minus) retlw '*' ; 7C NUM - * retlw '9' ; 7D NUM - 9 or PAGE UP Nsend retlw 0 ; 7E SCROLL LOCK ; retlw 0 ; 7F Table length reduced to provide space for 4 tables * ; retlw 0 ; 80 * ; retlw 0 ; 81 * ; retlw 0 ; 82 * ; retlw 0 ; 83 F7 * ; retlw 0 ; 84 * ; retlw 0 ; 85 * ; retlw 0 ; 86 * ; retlw 0 ; 87 * ; retlw 0 ; 88 * ; retlw 0 ; 89 * ; retlw 0 ; 8A * ; retlw 0 ; 8B * ; retlw 0 ; 8C * ; retlw 0 ; 8D * ; retlw 0 ; 8E * IF (high (Noshift) != high (Nsend)) ERROR "Keyboard lookup table hits page boundary!" ENDIF ;*********************************************************** ;* * ;* Shift - Lookup Table Used when Shift pressed * ;* * ;*********************************************************** org 0x280 Shift ; (used for characters typed when shift button active) addwf PCL,F ; SC retlw 0 ; 00 retlw 0 ; 01 F9 retlw 0 ; 02 retlw 0 ; 03 F5 retlw 0 ; 04 F3 retlw 0 ; 05 F1 retlw 0 ; 06 F2 retlw 0 ; 07 F12 retlw 0 ; 08 retlw 0 ; 09 F10 retlw 0 ; 0A F8 retlw 0 ; 0B F6 retlw 0 ; 0C F4 retlw 0x09 ; 0D TAB retlw '¬' ; 0E ` or ¬ retlw 0 ; 0F retlw 0 ; 10 retlw 0 ; 11 Left ALT retlw 0 ; 12 Left SHIFT retlw 0 ; 13 retlw 0 ; 14 Left Ctrl retlw 'Q' ; 15 Q retlw '!' ; 16 1 or ! retlw 0 ; 17 retlw 0 ; 18 retlw 0 ; 19 DT "ZSAW" ; 1A-1D retlw '"' ; 1E 2 or " retlw 0 ; 1F retlw 0 ; 20 DT "CXDE" ; 21-24 retlw '$' ; 25 4 or $ retlw '£' ; 26 3 or # retlw 0 ; 27 retlw 0 ; 28 retlw ' ' ; 29 Space DT "VFTR" ; 2A-2D retlw '%' ; 2E 5 or % retlw 0 ; 2F retlw 0 ; 30 DT "NBHGY"; 31-35 retlw '^' ; 36 6 or ^ retlw 0 ; 37 retlw 0 ; 38 retlw 0 ; 39 DT "MJU" ; 3A-3C retlw '&' ; 3D 7 or & retlw '*' ; 3E 8 or * retlw 0 ; 3F retlw 0 ; 40 retlw '<' ; 41 , or < DT "KIO" ; 42-44 retlw ')' ; 45 0 or ) retlw '(' ; 46 9 or ( retlw 0 ; 47 retlw 0 ; 48 retlw '>' ; 49 > or . retlw '?' ; 4A / or ? retlw 'L' ; 4B L retlw ':' ; 4C ; or : retlw 'P' ; 4D P retlw '_' ; 4E - or _ retlw 0 ; 4F retlw 0 ; 50 retlw 0 ; 51 retlw '@' ; 52 ' or @ retlw 0 ; 53 retlw '{' ; 54 [ or { retlw '+' ; 55 = OR + retlw 0 ; 56 retlw 0 ; 57 retlw 0 ; 58 Caps Lock retlw 0 ; 59 Right Shift retlw 0x0D ; 5A Enter retlw '}' ; 5B ] or } retlw 0 ; 5C retlw '~' ; 5D # or ~ retlw 0 ; 5E retlw 0 ; 5F retlw 0 ; 60 retlw '|' ; 61 retlw 0 ; 62 retlw 0 ; 63 retlw 0 ; 64 retlw 0 ; 65 retlw 0x08 ; 66 Backspace retlw 'G' ; 67 retlw 0 ; 68 retlw '1' ; 69 NUM - 1 or END retlw 0 ; 6A retlw '4' ; 6B NUM - 4 or LEFT retlw '7' ; 6C NUM - 7 or HOME retlw 0 ; 6D retlw 0 ; 6E retlw 0 ; 6F retlw '0' ; 70 NUM - 0 or INS retlw '.' ; 71 NUM - . or DEL retlw '2' ; 72 NUM - 2 or DOWN retlw '5' ; 73 NUM - 5 retlw '6' ; 74 NUM - 6 or RIGHT retlw '8' ; 75 NUM - 8 or UP retlw 0x1B ; 76 ESC retlw 0 ; 77 NUM LOCK retlw 0 ; 78 F11 retlw '+' ; 79 NUM - + (Plus) retlw '3' ; 7A NUM 3 or PAGE DOWN retlw '-' ; 7B NUM - - (Minus) retlw '*' ; 7C NUM - * retlw '9' ; 7D NUM - 9 or PAGE UP Send retlw 0 ; 7E SCROLL LOCK ; retlw 0 ; 7F Table length reduced to provide space for 4 tables * ; retlw 0 ; 80 * ; retlw 0 ; 81 * ; retlw 0 ; 82 * ; retlw 0 ; 83 F7 * ; retlw 0 ; 84 * ; retlw 0 ; 85 * ; retlw 0 ; 86 * ; retlw 0 ; 87 * ; retlw 0 ; 88 * ; retlw 0 ; 89 * ; retlw 0 ; 8A * ; retlw 0 ; 8B * ; retlw 0 ; 8C * ; retlw 0 ; 8D * ; retlw 0 ; 8E * ;Send retlw 0 ; 8F * IF (high (Shift) != high (Send)) ERROR "Keyboard lookup table hits page boundary!" ENDIF ;*********************************************************** ;* * ;* CapsLk - Lookup Table Used when Caps Lock active * ;* * ;*********************************************************** org 0x300 CapsLk ; (used for characters typed when Caps Lock active) addwf PCL,F ; SC retlw 0 ; 00 invalid entry retlw '9' ; 01 F9 -> 9 0x01 retlw 0 ; 02 retlw '5' ; 03 F5 -> 5 retlw '3' ; 04 F3 -> 3 retlw '1' ; 05 F1 -> 1 retlw '2' ; 06 F2 -> 2 retlw '2' ; 07 F12 -> 2 retlw 0 ; 08 retlw '0' ; 09 F10 -> 0 retlw '8' ; 0A F8 -> 8 0x0A retlw '6' ; 0B F6 -> 6 retlw '4' ; 0C F4 -> 4 retlw 0x09 ; 0D TAB retlw '`' ; 0E ` or ¬ retlw 0 ; 0F retlw 0 ; 10 retlw 0 ; 11 Left Alt retlw 0 ; 12 Left Shift retlw 0 ; 13 retlw 0 ; 14 Left Ctrl retlw 'Q' ; 15 DT: MPASM directive to create a table (retlw x) retlw '1' ; 16 1=(1 or !) retlw 0 ; 17 retlw 0 ; 18 retlw 0 ; 19 DT "ZSAW2" ; 1A-1E (2 or ") retlw 0 ; 1F retlw 0 ; 20 DT "CXDE43"; 21-26 (3 or £), (4 or $) retlw 0 ; 27 retlw 0 ; 28 retlw ' ' ; 29 SPACE DT "VFTR5" ; 2A-2E (5 or %) retlw 0 ; 2F retlw 0 ; 30 DT "NBHGY6"; 31-36 (6 or ^) retlw 0x1B ; 37 retlw 0 ; 38 retlw 0 ; 39 DT "MJU78" ; 3A-3E (7 or &), (8 or *) retlw 0 ; 3F retlw 0 ; 40 DT ",KIO09"; 41-46 (, or <), (0 or )), (9 or () retlw 0 ; 47 retlw 0 ; 48 DT "./L;P" ; 49-4D (. or >), (/ or ?), (; or :) retlw '-' ; 4E (- or _) retlw 0 ; 4F retlw 0 ; 50 retlw 0 ; 51 DT "'" ; 52 (' or @) retlw 0 ; 53 retlw '[' ; 54 ([ or {) retlw '=' ; 55 (= or +) retlw 0 ; 56 retlw 0 ; 57 retlw 0 ; 58 CAPS LOCK, check and alter CAPflag on key release retlw 0 ; 59 Right Shift goto _SHIFT ; SHIFT retlw 0Dh ; 5A Enter retlw ']' ; 5B (] or }) retlw 0 ; 5C retlw '#' ; 5D (# or ~) retlw 0 ; 5E retlw 0 ; 5F retlw 0 ; 60 retlw 0x5C ; 61 (0x5C = '\') retlw 0 ; 62 retlw 0 ; 63 Up Arrow retlw 0 ; 64 Delete retlw 0 ; 65 End retlw 0x08 ; 66 Backspace retlw 0 ; 67 Insert retlw 0 ; 68 retlw '1' ; 69 (NUM 1 or End) retlw 0 ; 6A > retlw '4' ; 6B (NUM 4 or Left) retlw '7' ; 6C (NUM 7 or Home) retlw 0 ; 6D retlw 0 ; 6E retlw 0 ; 6F retlw '0' ; 70 NUM - 0 or INS retlw '.' ; 71 NUM - Del or . retlw '2' ; 72 NUM - 2 or DOWN retlw '5' ; 73 NUM - 5 retlw '6' ; 74 NUM - 6 or RIGHT retlw '8' ; 75 NUM - 8 or UP retlw 0x1B ; 76 ESC retlw 0 ; 77 NUM LOCK retlw 0 ; 78 F11 retlw '+' ; 79 NUM - + (Plus) retlw '3' ; 7A NUM 3 or PAGE DOWN retlw '-' ; 7B NUM - - (Minus) retlw '*' ; 7C NUM - * retlw '9' ; 7D NUM - 9 or PAGE UP Csend retlw 0 ; 7E SCROLL LOCK ; retlw 0 ; 7F Table length reduced to provide space for 4 tables * ; retlw 0 ; 80 * ; retlw 0 ; 81 * ; retlw 0 ; 82 * ; retlw 0 ; 83 F7 * ; retlw 0 ; 84 * ; retlw 0 ; 85 * ; retlw 0 ; 86 * ; retlw 0 ; 87 * ; retlw 0 ; 88 * ; retlw 0 ; 89 * ; retlw 0 ; 8A * ; retlw 0 ; 8B * ; retlw 0 ; 8C * ; retlw 0 ; 8D * ; retlw 0 ; 8E * IF (high (CapsLk) != high (Csend)) ERROR "Keyboard lookup table hits page boundary!" ENDIF ;*********************************************************** ;* * ;* Ctrl - Lookup Table Used when Ctrl pressed * ;* * ;*********************************************************** org 0x380 Ctrl ; (used for characters typed when Ctrl active) addwf PCL,F ; SC retlw 0 ; 00 invalid entry retlw '9' ; 01 F9 -> 9 0x01 retlw 0 ; 02 retlw '5' ; 03 F5 -> 5 retlw '3' ; 04 F3 -> 3 retlw '1' ; 05 F1 -> 1 retlw '2' ; 06 F2 -> 2 retlw '2' ; 07 F12 -> 2 retlw 0 ; 08 retlw '0' ; 09 F10 -> 0 retlw '8' ; 0A F8 -> 8 0x0A retlw '6' ; 0B F6 -> 6 retlw '4' ; 0C F4 -> 4 retlw 0x09 ; 0D TAB retlw '`' ; 0E ` or ¬ retlw 0 ; 0F retlw 0 ; 10 retlw 0 ; 11 Left Alt retlw 0 ; 12 Left Shift retlw 0 ; 13 retlw 0 ; 14 Left Ctrl retlw 0x11 ; 15 q retlw '1' ; 16 1=(1 or !) retlw 0 ; 17 retlw 0 ; 18 retlw 0 ; 19 retlw 0x1A ; 1A z retlw 0x13 ; 1B s retlw 0x01 ; 1C a retlw 0x17 ; 1D w retlw '2' ; 1E 2 retlw 0 ; 1F retlw 0 ; 20 retlw 0x03 ; 21 c retlw 0x18 ; 22 x retlw 0x04 ; 23 d retlw 0x05 ; 24 e retlw '4' ; 25 4 retlw '3' ; 26 3 retlw 0 ; 27 retlw 0 ; 28 retlw ' ' ; 29 SPACE retlw 0x16 ; 2A v retlw 0x06 ; 2B f retlw 0x14 ; 2C t retlw 0x12 ; 2D r retlw '5' ; 2E 5 retlw 0 ; 2F retlw 0 ; 30 retlw 0x0E ; 31 n retlw 0x02 ; 32 b retlw 0x08 ; 33 h retlw 0x07 ; 34 g retlw 0x19 ; 35 y retlw '6' ; 36 6 retlw 0x1B ; 37 retlw 0 ; 38 retlw 0 ; 39 retlw 0x0D ; 3A m retlw 0x0A ; 3B j retlw 0x15 ; 3C u retlw '7' ; 3D 7 retlw'8' ; 3E 8 retlw 0 ; 3F retlw 0 ; 40 retlw ',' ; 41 , retlw 0x0B ; 42 k retlw 0x09 ; 43 i retlw 0x0F ; 44 o retlw '0' ; 45 0 retlw '9' ; 46 9 retlw 0 ; 47 retlw 0 ; 48 retlw '.' ; 49 . retlw '/' ; 4A / retlw 0x0C ; 4B l retlw ';' ; 4C ; retlw 0x10 ; 4D p retlw '-' ; 4E (- or _) retlw 0 ; 4F retlw 0 ; 50 retlw 0 ; 51 DT "'" ; 52 (' or @) retlw 0 ; 53 retlw '[' ; 54 ([ or {) retlw '=' ; 55 (= or +) retlw 0 ; 56 retlw 0 ; 57 retlw 0 ; 58 CAPS LOCK, check and alter CAPflag on key release retlw 0 ; 59 Right Shift goto _SHIFT ; SHIFT retlw 0Dh ; 5A Enter retlw ']' ; 5B (] or }) retlw 0 ; 5C retlw '#' ; 5D (# or ~) retlw 0 ; 5E retlw 0 ; 5F retlw 0 ; 60 retlw 0x5C ; 61 (0x5C = '\') retlw 0 ; 62 retlw 0 ; 63 Up Arrow retlw 0 ; 64 Delete retlw 0 ; 65 End retlw 0x08 ; 66 Backspace retlw 0 ; 67 Insert retlw 0 ; 68 retlw 0x1B ; 69 (NUM 1 or End) retlw 0 ; 6A > retlw 0x1E ; 6B (NUM 4 or Left) retlw '7' ; 6C (NUM 7 or Home) retlw 0 ; 6D retlw 0 ; 6E retlw 0 ; 6F retlw '0' ; 70 NUM - 0 or INS retlw '.' ; 71 NUM - Del or . retlw 0x1C ; 72 NUM - 2 or DOWN retlw 0x1F ; 73 NUM - 5 retlw '6' ; 74 NUM - 6 or RIGHT retlw '8' ; 75 NUM - 8 or UP retlw 0x1B ; 76 ESC retlw 0 ; 77 NUM LOCK retlw 0 ; 78 F11 retlw '+' ; 79 NUM - + (Plus) retlw 0x1D ; 7A NUM 3 or PAGE DOWN retlw '-' ; 7B NUM - - (Minus) retlw '*' ; 7C NUM - * retlw '9' ; 7D NUM - 9 or PAGE UP Ctsend retlw 0 ; 7E SCROLL LOCK ; retlw 0 ; 7F Table length reduced to provide space for 4 tables * ; retlw 0 ; 80 * ; retlw 0 ; 81 * ; retlw 0 ; 82 * ; retlw 0 ; 83 F7 * ; retlw 0 ; 84 * ; retlw 0 ; 85 * ; retlw 0 ; 86 * ; retlw 0 ; 87 * ; retlw 0 ; 88 * ; retlw 0 ; 89 * ; retlw 0 ; 8A * ; retlw 0 ; 8B * ; retlw 0 ; 8C * ; retlw 0 ; 8D * ; retlw 0 ; 8E * IF (high (Ctrl) != high (Ctsend)) ERROR "Keyboard lookup table hits page boundary!" ENDIF end