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

Page 146

Advertising
background image

RPBASIC-52 PROGRAMMING GUIDE

A-2

rem 130 CONFIG BAUD 1,1,2

rem set the display type for command D

140 config display 1

rem Read lines 0-3 to determine card address.
rem Card number starts from ASCII '0' and goes up from there.

rem 150 ASC($(0),3) = (lineb(5,2) .AND. 15)+48

REM declare tasking and define conditions
REM To 1000 when either 40 characters are in or a <cr> received

rem 160 ON COM$1,40,13,1000
160 on com$0,40,13,1000

300 GOTO 300 :REM hang out here

REM Handle interrupt here
REM Since all variables are global, local variables used here start
REM with the letter 'o'. This helps prevent inadvertent value changes
REM to other parts of the program

rem 1000 $(1) = COM$(1) :REM get data
1000 $(1) = com$(0)

rem Check for emergency safety mode code

1005 if str(8,$(1),$(3)) = 1 then 5000

REM see if card ID is in this packet
REM If 0 returned, is not this card

1010 IF STR(8,$(1),$(0)) <> 1 THEN RETURN

REM Parse out command. For this demo, assume
REM it is only 1 letter long and starts with
REM capital letter A. If command is negative
REM can return a NAK (negative acknowledge)
REM to sender or ignore it.

1020 OA = ASC($(1),4)-65
1030 IF OA < 0 then 1500

REM Make sure checksum is OK
REM Add up values in string for length - 2

1040 ocksum = 0
1050 ole = str(0,$(1))
1060 for oc = 1 to ole-2
1070 ocksum = asc($(1),oc) + cksum
1080 next

rem strip off excess

1090 ocksum = ocksum .and. 0ffH

REM Get checksum values
REM IF second to last character is a ?, then don't check checksum
REM convert last two characters into decimal

1100 oc = asc($(1),ole-1):REM get first digit
1110 if oc = 63 then 1200:rem if ?, skip rest of checksum test
1120 gosub 1600

:rem convert ASCII to number

1130 och = oc*16

:REM assign high byte first

1140 oc = asc($(1),ole)

:rem get last hex digit

1150 gosub 1600
1160 oc = oc+och

:rem make checksum value

Advertising