O
T
PL
I
S
G
E
H
H
T
A
T
O
G
N
M
N
I
T
B
T
A
T
S
U
I
P
C
P
S
S
A
T
A
P
M
P
P
P
R
L
O
I
J
E
C
C
T
S
,
A
H
T
I
I
N
T
S
O
&
T
N
I
P
S
S
■ BY JON WILLIAMS
WADING THE BS1 DEBUG STREAM
UNTIL RECENTLY, I HAD NEVER REALLY CONSIDERED USING A BS1 as a front-end to a PC program
— unlike the BS2, the BS1 doesn’t have the ability to
do SEROUT on its programming port. But then my
colleague, Chuck, had this idea about building a BS1
right into a USB connector. Well, that changes
things; now the BS1 is not just connected to the
PC, it’s nearly a part of it. With no SEROUT on the
programming port, it’s time to roll up the pant legs
and wade through the BS1’s DEBUG stream.
For those of you that have been around for a long time,
or have taken the time to go back through past issues of
this column, you may remember that Scott Edwards tackled
this subject back in October of 1996. Scott was able to
[correctly] deduce most of the aspects of the BS1 DEBUG
stream through empirical observation. I have the advantage
of working “on the inside” and, after spending an hour chatting with our compiler engineer, it’s my intent to show you
how to use the BS1’s DEBUG output in your PC projects.
If you typed
it in just like the
listing, you
should see that ■ FIGURE 1. BS1 Debug Viewer Program.
the last location
used is $EF, so the program consumes 17 bytes of
EEPROM. Okay, now modify the DEBUG line like this and
open the Memory Map again:
THE DIRT ON BS1 DEBUG
As Scott pointed out, any time you have a DEBUG
instruction in a BS1 program, everything (all variables) gets
sent to the PC. This may seem odd at first, and yet there is a
perfectly logical explanation: the BS1 only has 256 bytes of
program memory. As we all know, that’s not a lot of space and
anything that can be done to conserve it is important. Chip —
the BASIC Stamp’s inventor — came up with an interesting
solution that can be demonstrated with a simple program.
Enter this program in your BASIC Stamp IDE and check
the Memory Map:
‘ {$STAMP BS1}
‘ {$PBASIC 1.0}
SYMBOL count = B2
Main:
FOR count = 1 TO 10
DEBUG “The value of ‘count’ is: “, #count, CR
PAUSE 300
NEXT
GOTO Main
‘ {$STAMP BS1}
‘ {$PBASIC 1.0}
SYMBOL count = B2
Main:
FOR count = 1 TO 10
DEBUG #count, CR
PAUSE 300
NEXT
GOTO Main
Again, the last location used $EF for a program total of
17 bytes. Whatthe?... Interesting, isn’t it? Here’s the secret:
That big string of characters we added to the program does
not get stored inside the BS1, it’s actually stored in a table
inside the BASIC Stamp IDE. The reason for this is that we
normally use DEBUG when we’re connected to the IDE, so
it made more sense to store the strings there rather than
in the BS1 where they would very quickly eat through our
precious program memory.
When we compile and download a program to our BS1,
the editor creates a special table for all the occurrences
of DEBUG. The table is indexed by the program counter
(location) where the DEBUG instruction is placed. Part of
12
March 2006