Datasheet

Page 56ยท Applied Robotics with the SumoBot
temp is even, it displays "Program running..." and returns the program to initialization
and onward from there.
' -----[ Subroutine - Reset ]-------------------------------------------------
Reset:
READ RunStatus, temp ' Byte @RunStatus -> temp
temp = temp + 1 ' Increment temp
WRITE RunStatus, temp ' Store new value for next time
IF (temp.BIT0 = 1) THEN ' Examine temp.BIT0
DEBUG CLS, "Press/release Reset", CR, ' 1 -> end, 0 -> keep going
"button..."
END
ELSE
DEBUG CR, "Program running..."
ENDIF
RETURN
If the program has just been downloaded, the DATA directive causes a 0 to be written to
the
RunStatus address. Then, READ RunStatus, temp copies the value 0 from the
EEPROM byte at the RunStatus address to the
temp variable. temp = temp + 1 adds 1
to
temp. The command WRITE RunStatus, temp stores this 1 back to the EEPROM
byte at the
RunStatus address. Since temp.BIT0 is 1, the subroutine displays the
message "Press/release Reset button...". Then, the program ends, which in turn causes
the BASIC Stamp goes into low power mode.
At this point, there is a 1 in the EEPROM byte at the
RunStatus address. When you
press and release the Reset button,
READ RunStatus, temp fetches that 1 and copies it
to the
temp variable. temp = temp + 1 changes that 1 to a 2, and WRITE RunStatus,
temp
writes that 2 back to EEPROM. The IF...THEN statement does not end the
program this time. Since
temp is now an even number, temp.BIT0 stores a 0. As a
result, the
IF...THEN statement instead displays the message "Program running...".
After that, the
RETURN statement sends the program back to the Initialization routine,
where it calls the next subroutine, then moves on to the Main Routine.
If you press/release the Reset button a third time, it starts again by fetching the 2 from the
RunStatus EEPROM byte, adds 1 to make it 3, then stores it back to EEPROM, and
ends the program with the "Press/release Reset button..." message. If you press/release
the Reset button a fourth time, it fetches the 3, adds 1 to make it 4, stores it, and