'--------------------------------------------------------------------- ' Name: TEC2200_INPUT_ECHO.TIG ' Date: 17-Nov-2004 ' Purpose: Enter a string through the TEC 2200 keyboard. Keys with ' multiple character layout must be pressed repeatetly within ' 500ms to scroll through the characters. ' Entering the string is done in subroutine INPUT_ECHO. '--------------------------------------------------------------------- USER_VAR_STRICT ' variables must be declared #INCLUDE DEFINE_A.INC ' general defines #INCLUDE UFUNC3.INC ' user function codes USER_EPORT ACT, NOACTIVE ' disable eport system LONG FLAG,COUNT,X,N,A ' declare LONG variables TASK MAIN ' begin task MAIN STRING S$ ' for input DIR_PIN 3,3,0 ' Port 3 Bit 3 (L33) = Output = ACLK DIR_PIN 3,4,0 ' Port 3 Bit 4 (L34) = Output = DCLK DIR_PIN 3,5,0 ' Port 3 Bit 5 (L35) = Output = -INE OUT 3, 00100000B, 0FFH ' set bits to "1": L33, L34, L35 XOUT (0,FILL$("<0>",256)) ' set all 256 possible xPort channels to 00 INSTALL_DEVICE #1,"LCD1.TDD",& ' install LCD1 with keyboard + Shift-LED + beeper 0,& ' 1 - 0 LCD display type (1...nn) 0,& ' 2 - 0 L BUS addr LCD / keyb. 0,& ' 3 - 0 Bit-MASK 0,& ' 4 - 0 L ADDR 0,& ' 5 - 0 Bit-MASK 0,& ' 6 - 0 L ADDR 0EEh,& ' 7 - EE BIT-Mask BELL-Beeper 00 -> no BELL ! 0,& ' 8 - 0 L Addr BELL-Beeper (iPort) 0EEH,& ' 9 - EE TRUE(=00) / false(=FF) FLAG 10H,& '10 - EE S-LED Bit-MASK <====== 0F9h,& '11 - 0 L S-LED (LOG-)Port-ADDR <====== 0FFH,& '12 - EE S-LED Flag: 00=TRUE / FF=FALSE <====== 0EEH,& '13 - EE Keyboard Scan Columns: 0=NO Keyboard, otherwise = 1...16 Columns 0EEH,& '14 - EE LCD available: 0=YES / FF=NO 3,& '15 - EE CTRL-Port ADDR: 3 08h,& '16 - EE ACLK Mask: 0000 1000B / 2 Masks for INPUT from XPort <====== 20H,& '17 - EE -INE Mask: 0010 0000B / <====== 10H '18 - EE -DCLK Mask: 0001 0000B --> Data-Clock for Shift-LED <====== ' ! ! ' ! !<--- This parameter value used to NOT change the default in this parameter position ' ! ' !<--- Parameter No. ' <----- define addresses for keyboard scan columns -----> PRINT #1, "<1Bh>k<08h><09h><0Ah><0Bh><0Ch><0Dh><0Eh><0Fh>& <08h><09h><0Ah><0Bh><0Ch><0Dh><0Eh><0Fh><0F0h>"; ' <----- define what columns are for keyboard and what are digital inputs -----> PUT #1,"<1Bh>D<16><1><1><1><1><1><1><0><0><0><0><0><0><0><0><0><0><0F0h>" FLAG = XSETUP (6, 3, 3, 4, 5, 7, 1) ' setup XBus XOUT(0F9H, 01110000B) ' F9 is control port on CPU board: XOUT(0F9H, 11111100B) ' 0..2=LCD-contrast, 3=(1)LCD-Light, ' 4=KB-LED, 6=SMC-LED, 7=-LCD-reset PUT #1, #0, #UFCO_IBU_ERASE, 0 ' erase keyboard input buffer '---------------------------------------------------------------------------------------- ' sample for input of STRING value S$ = "" ' initialize input string PRINT #1, "<27>A<1><3>"; ' position cursor at line 3, column 1 PRINT #1, "Enter S$ ="; ' CALL INPUT_ECHO (3, 12, S$) ' call input routine at line 3, column 12 PRINT #1, "<27>A<0><0>"; ' position cursor PRINT #1, "S$ is = "; S$; " " ' display entered string END ' ende of task MAIN '---------------------------------------------------------------------------------------- ' Subroutine INPUT_ECHO reads input from TEC2200 keyboard (printed layout) with echo ' ' Parameters: X starting line on LCD ' Y starting column on LCD ' IN$ preset value '---------------------------------------------------------------------------------------- SUB INPUT_ECHO (BYTE X,Y; VAR STRING IN$) STRING CH$ ' LONG KEYTIME, N, EXIT ' BYTE NEWPOS, NEWKEY, IDX, SC, OLDSC ' EXIT = 0 ' initialize exit flag CH$ = " " ' initialize string KEYTIME = 0 ' time of last key pressed NEWPOS = 1 ' new position reached? 1=YES OLDSC = 255 ' last scancode PRINT #1, "<27>c<1>"; ' switch cursor on WHILE NOT EXIT = 1 ' while not or PRINT #1, "<27>A";CHR$(Y);CHR$(X);""; ' position cursor PRINT #1, IN$+CH$;" <8><8>"; ' print current string N = 0 ' preset buffer filling with 0 WHILE (N=0) AND (DIFF_TICKS(KEYTIME)<500) ' while no key pressed and less than 500ms since last key GET #1, #0, #1, 1, N ' N = no. of chars in keyboard buffer ENDWHILE ' IF N > 0 THEN ' if key in keyboard buffer GET #1, 1, SC ' read 1 char from keyboard buffer KEYTIME = TICKS() ' time when key was pressed IF SC = OLDSC THEN ' if same key pressed again NEWKEY = 0 ' newkey = FALSE ELSE ' if other key was pressed NEWKEY = 1 ' newkey = TRUE ENDIF ' OLDSC = SC ' save scancode (key no.) SWITCHI SC ' evaluate key CASE 0: ' SCANCODE: 00h NEWPOS = 0 ' if not already, we now entered char at new pos IF NEWKEY = 1 THEN ' if pressed for first time IDX = 0 ' start index ELSE ' if pressed again IDX = MODULO_INC(IDX,0,3,1) ' increase index within limits ENDIF ' CH$ = MID$("1abc",IDX,1) ' assign current character CASE 1: ' SCANCODE: 01h NEWPOS = 0 ' if not already, we now entered char at new pos IF NEWKEY = 1 THEN ' if pressed for first time IDX = 0 ' start index ELSE ' if pressed again IDX = MODULO_INC(IDX,0,3,1) ' increase index within limits ENDIF ' CH$ = MID$("4jkl",IDX,1) ' assign current character CASE 2: ' SCANCODE: 02h NEWPOS = 0 ' if not already, we now entered char at new pos IF NEWKEY = 1 THEN ' if pressed for first time IDX = 0 ' start index ELSE ' if pressed again IDX = MODULO_INC(IDX,0,3,1) ' increase index within limits ENDIF ' CH$ = MID$("7stu",IDX,1) ' assign current character CASE 3: ' SCANCODE: 03h NEWPOS = 0 ' if not already, we now entered char at new pos IF NEWKEY = 1 THEN ' if pressed for first time IDX = 0 ' start index ELSE ' if pressed again IDX = MODULO_INC(IDX,0,3,1) ' increase index within limits ENDIF ' CH$ = MID$("* ()",IDX,1) ' assign current character CASE 8: ' SCANCODE: 08h NEWPOS = 0 ' if not already, we now entered char at new pos IF NEWKEY = 1 THEN ' if pressed for first time IDX = 0 ' start index ELSE ' if pressed again IDX = MODULO_INC(IDX,0,3,1) ' increase index within limits ENDIF ' CH$ = MID$("2def",IDX,1) ' assign current character CASE 9: ' SCANCODE: 09h NEWPOS = 0 ' if not already, we now entered char at new pos IF NEWKEY = 1 THEN ' if pressed for first time IDX = 0 ' start index ELSE ' if pressed again IDX = MODULO_INC(IDX,0,3,1) ' increase index within limits ENDIF ' CH$ = MID$("5mno",IDX,1) ' assign current character CASE 10: ' SCANCODE: 0Ah NEWPOS = 0 ' if not already, we now entered char at new pos IF NEWKEY = 1 THEN ' if pressed for first time IDX = 0 ' start index ELSE ' if pressed again IDX = MODULO_INC(IDX,0,2,1) ' increase index within limits ENDIF ' CH$ = MID$("8vw",IDX,1) ' assign current character CASE 11: ' SCANCODE: 0Bh NEWPOS = 0 ' if not already, we now entered char at new pos IF NEWKEY = 1 THEN ' if pressed for first time IDX = 0 ' start index ELSE ' if pressed again IDX = MODULO_INC(IDX,0,3,1) ' increase index within limits ENDIF ' CH$ = MID$("0,.:",IDX,1) ' assign current character CASE 16: ' SCANCODE: 10h NEWPOS = 0 ' if not already, we now entered char at new pos IF NEWKEY = 1 THEN ' if pressed for first time IDX = 0 ' start index ELSE ' if pressed again IDX = MODULO_INC(IDX,0,3,1) ' increase index within limits ENDIF ' CH$ = MID$("3ghi",IDX,1) ' assign current character CASE 17: ' SCANCODE: 11h NEWPOS = 0 ' if not already, we now entered char at new pos IF NEWKEY = 1 THEN ' if pressed for first time IDX = 0 ' start index ELSE ' if pressed again IDX = MODULO_INC(IDX,0,3,1) ' increase index within limits ENDIF ' CH$ = MID$("6pqr",IDX,1) ' assign current character CASE 18: ' SCANCODE: 12h NEWPOS = 0 ' if not already, we now entered char at new pos IF NEWKEY = 1 THEN ' if pressed for first time IDX = 0 ' start index ELSE ' if pressed again IDX = MODULO_INC(IDX,0,3,1) ' increase index within limits ENDIF ' CH$ = MID$("9xyz",IDX,1) ' assign current character CASE 19: ' SCANCODE: 13h NEWPOS = 0 ' if not already, we now entered char at new pos IF NEWKEY = 1 THEN ' if pressed for first time IDX = 0 ' start index ELSE ' if pressed again IDX = MODULO_INC(IDX,0,3,1) ' increase index within limits ENDIF ' CH$ = MID$("#+-/",IDX,1) ' assign current character CASE 32: ' SCANCODE: 20h IN$ = LEFT$(IN$, LEN(IN$)-1) ' delete last char from string CH$ = " " ' preset with SPC for next position CASE 43: ' SCANCODE: 2Bh EXIT = 1 ' set exit flag ' ----- ENTER MORE CASES IF OTHER KEYS ARE NEEDED TOO ----- ENDSWITCH ' ELSE ' timeout was reached IF NEWPOS = 1 THEN ' if new at position KEYTIME = TICKS() ' restart waiting time ELSE ' if already key pressed at position IN$ = IN$ + CH$ ' append character to input string NEWPOS = 1 ' set flag for new position CH$ = " " ' preset with SPC for next position ENDIF ' ENDIF ' ENDWHILE ' PRINT #1, "<27>c<0>"; ' switch cursor off END ' end of task INPUT_ECHO