Rpbasic-52 programming guide – Remote Processing BASIC 52 User Manual

Page 147

Advertising
background image

RPBASIC-52 PROGRAMMING GUIDE

A-3

rem if last two digits don't sum to message, then return a negative
rem acknowledge error and bail out

1170 if oc <> ocksum then $(2) = "N2" : goto 1510

rem Checksum is good

REM If status command, go process it

1200 IF oa = 4 THEN 4000
1210 if oa > 5 then 1500

:REM if not in command, is error

REM Check for valid power up acknowledge
REM if not acknowledged, then state so

1220 if oflag = 0 then $(2) = "N3" : goto 1510

rem process command
rem GOSUB's could also be used here. However, goto's are faster as
rem exiting the routine makes a direct branch to the condition

rem Cmdn letter A B C D E F

1240 on oa goto 2000,2500,3000,3500,4000,4500

rem If more commands, check for limit. If over, then subtract command
rem and make another ON GOTO

REM Common return point for successful completion of a command

REM Return acknowledge to sender.
REM Used for commands

1400 $(2)="A"
1410 GOTO 1510 :REM to common output & exit

REM Return negative acknowledge to sender.
REM N1 = unrecognized command
REM N2 = checksum bad
REM N3 = power up not acknowledged. Needs command 5.
REM N4 = bad data
REM N5 = something is wrong. Can add error conditions as needed

1500 $(2)="N1"
1510 rem UO1
1520 PRINT $(2)
rem 1530 UO0 :REM back to main port
1540 RETURN

REM convert ASCII HEX number into a number 0 - 15
REM Enter with oc = ASCII value of number (0-9 or A-F which is 48-
REM 58 or 65 to 70)
REM If problem, oc returns -1. If OK, returns number 0 to 15

1600 if (oc < 48) .or. (oc > 70) then oc = -1 : return
1610 if oc > 58 then 1640

rem value between 0 and 9. Simply subtract 48 and exit

1620 oc = oc-48
1630 return

rem Value should be between A-F

1640 if oc < 65 then oc = -1 : return
1650 oc = oc - 55
1660 return

REM Send back acknowledge

Advertising