Stamp
RX_DEC2:
temp3 = 0
FOR temp4 = 1 TO 2
temp5 = RX_BYTE
IF temp5 >= “0” THEN
IF temp5 <= “9” THEN
temp3 = temp3 * 10
temp5 = temp5 - “0”
temp3 = temp3 + temp5
ELSE
EXIT
ENDIF
ELSE
EXIT
ENDIF
NEXT
RETURN temp3
While it may not seem so at first, this code is identical
to the RX_BIN8 subroutine. The difference, of course, is in
the decimal base. To “shift” digits in this code, we need to
multiply by 10, and then add the new value (after it’s converted from its ASCII code) to the result. Since we’re dealing in decimal and don’t want to overrun the limitations of
a byte, the subroutine allows a maximum of two digits.
And now it gets a little hairy — but just a little.
Set_OnePort:
TX_STR Pad
idx = RX_DEC2
TX_BYTE “ “
cmd = RX_BYTE
IF idx >= 1 THEN
IF idx <= 8 THEN
DEC idx
temp1 = 1 << idx
IF cmd = “1” THEN
PortLo = PortLo | temp1
ENDIF
IF cmd = “0” THEN
temp1 = ~temp1
PortLo = PortLo & temp1
ENDIF
ENDIF
ENDIF
IF idx >= 9 THEN
IF idx <= 16 THEN
idx = idx - 9
temp1 = 1 << idx
IF cmd = “1” THEN
PortHi = PortHi | temp1
ENDIF
IF cmd = “0” THEN
temp1 = ~temp1
PortHi = PortHi & temp1
ENDIF
ENDIF
ENDIF
TX_STR CRLF
GOTO Main
This code is not as bad as it looks at first blush. What
we have to remember is that SX/B is very close to assembly language (many instructions are 1-for-1), so it gets a bit
verbose — certainly more than PBASIC.
The code waits for the port number, prints a space pad,
SEPTEMBER 2005
73