Rpbasic-52 programming guide, On keypad – Remote Processing BASIC 52 User Manual

Page 93

Advertising
background image

RPBASIC-52 PROGRAMMING GUIDE

2-74

ON KEYPAD

Syntax:

O N K E Y P A D subroutine line
O N K E Y P A D
Where: subroutine line = program to execute

Function:

Branches to a subroutine when a keypad switch is pressed.

Mode:

R U N

Use:

ON KE YPAD 1000

Cards:

RPC-320, RPC-330

D E S C R IP T I ON

Program branches when any key is pressed on the keypad. Use the routine below to build a string.

R e v ie w HARDWAR E AND SOFTWARE INTERRU PTS in the first part of this manual for interrupt
handling and multitasking information.

RELATED

K E Y P A D , C LE A R K E Y P A D

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. Keyp ad position 16 is de signated as ente r while 12 is clea r.

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

Advertising