Datasheet

Page 234· Applied Robotics with the SumoBot
#IF DEBUG_MODE = 1 OR DATALOG_MODE > 0 #THEN
' State constants.
ATL CON 0 ' Avoid_Tawara_Left
ATR CON 1 ' Avoid_Tawara_Right
GF CON 2 ' Go-Forward
.
.
.
#ENDIF
A constant named MaxBytes is declared to make it convenient to set the number of bytes
that can be used for storing data logged during a round. In this example,
MaxBytes is
$150. The
$ makes a number hexadecimal. A hexadecimal value is used because the
Memory Map uses hexadecimal values. This makes it convenient to view the Memory
Map and decide how much memory you have available for datalogging. $10 (decimal-
16) is subtracted from
MaxBytes because the DATA directives that set aside EEPROM for
storing records will begin at EEPROM address $10.
#IF DATALOG_MODE > 0 #THEN
' Datalogging constants
MaxBytes CON $150 - $10 ' Maximum number of bytes stored
#ENDIF
Recall from Chapter 2, Activity #1 that converting from hexadecimal to decimal involves
multiplying the rightmost digit by 16
0
= 1, the next digit by 16
1
= 16, then next digit by
16
2
=256, and the next by 16
3
= 4096, and so on. Add up all the products, and you'll have
the decimal equivalent. For example, the decimal equivalent of $150, is: (1 × 256) + (5 ×
16) + (0 × 1) = decimal 336.
It's more convenient to declare
MaxBytes in terms of hexadecimal values because that's
the way the EEPROM map displays all its addresses. Figure 5-4 shows the EEPROM
map for the next example program compiled with
DATALOG_MODE = 2. The highest
EEPROM value not occupied by PBASIC program tokens is $257. Since records will be
stored as word values, each record will take up 2 bytes, and
MaxBytes should be even.
Therefore,
MaxBytes could be declared as $256 - $10. This would use up all the
available EEPROM.