'{$STAMP BS2} '{$PBASIC 2.5} '{&PBASIC 2.5} serData VAR Byte 'the data from serial port fromPCodes VAR Byte 'which pins to set shift VAR Byte '1=shift key dind VAR Byte 'data index of converson table seqind VAR Byte 'index of key sequence ' Set all pins as outputs and set them lo DIRS=%1111111111111111 OUTS=%0000000000000000 Begin: 'use default pin as serial port (pin 16) '16780= 2400 baud, 8 Bit, no parity 'timeout delay 100ms 'if no data received in 100ms, call clearBits to set all pins lo 'store byte in serData 'Note: you may want to experiment with the timeout delay '100 seems to work well with my setup SERIN 16,16780,100,clearBits,[serData] IF serData=93 THEN 'if right-square-bracket ']', process the sequence seqind=seqload GOTO seqloop ENDIF GOSUB processinput GOTO begin 'Execute a sequence of keys until 0 is read seqloop: READ seqind,serData seqind=seqind+1 IF serData=0 THEN GOTO begin ELSE GOSUB processinput PAUSE 100 OUTS=%0000000000000000 PAUSE 500 ENDIF GOTO seqloop processinput: dind=nullchar shift=0 SELECT serData CASE "a" TO "z" 'lowercase a-z dind=dalpha+(serData-97) CASE "A" TO "Z" 'uppercase A-Z shift=1 dind=dalpha+(serData-65) CASE 48 TO 64 'numbers and some punctuation IF (serData>57) THEN shift=1 'the colon dind=dnum+(serData-48) CASE 33 TO 47 'punctuation/symbols IF (serdata <> 46) THEN shift=1 'The period dind=dnumshift+(serData-33) CASE 94 'shift 6 - carrot dind=dother shift=1 CASE 32 'space dind=dnumshift+6 CASE 10,13 'enter dind=dother+1 CASE 9 'shiftonly dind=dother+2 CASE 92,124 'shift enter - backslash/pipe dind=dother+1 shift=1 CASE 8 'backspace dind=dother+3 shift=1 CASE 95 'shift space - underscore dind=dnumshift+6 shift=1 CASE ELSE dind=nullchar ENDSELECT IF (dind=nullchar) THEN 'unknown character or serial error SEROUT 16,16780,[" S:",serData] RETURN ENDIF READ (dind),fromPCodes IF (shift=1) THEN HIGH 14 'set shift ENDIF HIGH fromPCodes.NIB1 'set row HIGH fromPCodes.NIB0 'set column RETURN clearBits: OUTS=%0000000000000000 GOTO Begin seqload DATA "jPP",0 'This types LOAD "" dother DATA $81,$C5,$B5,$85 nullchar DATA $00 ' ! " # $ % & ' ( ) * + , - . / dnumshift DATA $65,$A5,$63,$62,$61,$82,$D5,$84,$85,$83,$C3,$D4,$C2,$D4,$B1 dalpha DATA $95,$D1,$B2,$93,$73,$92,$91 'A-G DATA $C1,$A3,$C2,$C3,$C4,$D3,$D2 'H-N DATA $A4,$A5,$75,$72,$94,$71,$A2 'O-U DATA $B1,$74,$B3,$A1,$B4 'V-Z dnum DATA $85,$65,$64,$63,$62,$61,$81,$82,$83,$84 '0-9 ' : ; < = > ? @ dnum2 DATA $B5,$B4,$D2,$C4,$D3,$B2,$64 'The hi nibble is the row 'The lo nibble is the column 'So, to press the A key, the table returns a value 'of $95. This sets pins 9 and 5 to HI. Pin 9 is 'connected to ROW 4 and pin 5 is connected to COLUMN 0, 'which intersect at A in the keyboard matrix. ' 0 1 2 3 4 - key column ' 5 4 3 2 1 - BS2 pin ' '1 6 1 2 3 4 5 '2 7 Q W E R T '3 8 0 9 8 7 6 '4 9 A S D F G '5 A P O I U Y '6 B shift Z X C V '7 C enter L K J H '8 D space . M N B '| | '| | '| +-BS2 pin '| '+---key row