
RPBASIC-52 PROGRAMMING GUIDE
2-74
ON KEYPAD
Syntax: ON KEYPAD subroutine line
ON KEYPAD
Where: subroutine line = program to execute
Function: Branches to a subroutine when a keypad switch is pressed.
Mode: RUN
Use: ON KEYPAD 1000
Cards: RPC-320, RPC-330
DESCRIPTION
Program branches when any key is pressed on the keypad. Use the routine below to build a string.
Review HARDWAR E AND SOFTWARE INTERRU PTS in the first part of this manual for interrupt
handling and multitasking information.
RELATED
KEYPAD, CLEAR KEYPAD
ERRORS
none
EXAMPLE
The following program sets up a string array and keypad multi-tasking. When the enter key is pressed, the
string is printed. Keypad position 16 is designated as enter while 12 is clear.
10 STRING 200,20 Initialize string area
20 $(0) = "123A456B789C*0#D" Initialize keypad string
30 P = 1 String position pointer
40 ON KEYPAD 500 Declare interrupt
50 PRINT "Enter a number from the keypad",
REM Rest of program continues
REM Scan keypad flag
210 IF PF = 0 THEN 210 Check flag. Prints string
220 PRINT when 'enter' is pressed.
230 PRINT "Entered string is: ",$(2)
240 PF = 0
250 GOTO 210
500 A = KEYPAD(0) Get keypad character
520 IF A = 12 THEN 600 : REM Process clear Add other traps as needed
530 IF A = 16 then 700 : REM process enter
540 A=ASC($(0),A) Get ASCII equivalent
550 PRINT CHR(A),
560 ASC($(2),P) = A Put into keypad input $
570 P = P + 1 Update position pointer
580 ASC($(2),P) = 13 Set CR as end of string
590 RETURN
600 REM Clear input string
610 $(2) = ""
620 P = 1
630 RETURN
700 REM 'Enter' processing
710 P = 1
720 PF = 1
730 RETURN
Komentáře k této Příručce