This repository has been archived on 2024-09-22. You can view files and clone it, but cannot push or open issues or pull requests.
pbi-ide/help/BasicStampHelp/Content/LanguageTopics/Commands/DEBUG.htm

620 lines
34 KiB
HTML
Raw Normal View History

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns:MadCap="http://www.madcapsoftware.com/Schemas/MadCap.xsd" MadCap:lastBlockDepth="6" MadCap:lastHeight="94" MadCap:lastWidth="853" MadCap:disableMasterStylesheet="true" MadCap:tocPath="" MadCap:InPreviewMode="false" MadCap:PreloadImages="false" MadCap:RuntimeFileType="Topic" MadCap:TargetType="WebHelp" lang="en-us" xml:lang="en-us" MadCap:PathToHelpSystem="../../../" MadCap:HelpSystemFileName="Default.xml" MadCap:SearchType="Stem">
<head><title>DEBUG</title>
<link href="../../SkinSupport/MadCap.css" rel="stylesheet" />
<link href="../../Resources/Stylesheets/BSE_Help.css" rel="stylesheet" />
<script src="../../SkinSupport/MadCapAll.js" type="text/javascript">
</script>
</head>
<body>
<h1 class="code">DEBUG</h1>
<div class="ImagePlusCaption">
<div class="Col2">
<p>
<img src="../../graphics/pgm_icon1.gif" border="0" alt="BS1 icon" title="BS1 icon" />
<img src="../../graphics/pgm_icon2.gif" border="0" alt="BS2 icon" title="BS2 icon" />
<img src="../../graphics/pgm_icon2e.gif" border="0" alt="BS2e icon" title="BS2e icon" />
<img src="../../graphics/pgm_icon2sx.gif" border="0" alt="BS2sx icon" title="BS2sx icon" />
<img src="../../graphics/pgm_icon2p.gif" border="0" alt="BS2p icon" title="BS2p icon" />
<img src="../../graphics/pgm_icon2pe.gif" border="0" alt="BS2pe icon" title="BS2pe icon" />
<img src="../../graphics/pgm_icon2px.gif" border="0" alt="BS2px icon" title="BS2px icon" />
</p>
</div>
<p style="text-align: right;"><a href="../ExampleTopics/DebugEx.htm" target="" title="" alt="" class="MCXref_0">DEBUG Examples</a>
</p>
<p>&#160;</p>
</div>
<p class="clear">&#160;</p>
<p>&#160;</p>
<p class="PlainText">Syntax: <span class="keyword_in_text">DEBUG</span> <![CDATA[ ]]><i>OutputData </i>{, <i>OutputData</i>}</p>
<h2>Function</h2>
<p class="PlainText">Display information on the PC screen within the BASIC Stamp editor program. This
command can be used to display text or numbers in various formats on the PC screen
in order to follow program flow (called debugging) or as part of the functionality
of the BASIC Stamp application.
</p>
<ul>
<li value="1"><b><i>OutputData</i></b> is a variable/constant/expression* (0 - 65535) that
specifies the information to output. Valid data can be ASCII characters (text
strings and control characters), decimal numbers (0 - 65535), hexadecimal numbers
($0000 - $FFFF) or binary numbers (up to %1111111111111111). Data can be
modified with special formatters as explained below.</li>
</ul>
<p>*<img align="absmiddle" src="../../graphics/bs1note.gif" style="vertical-align: super;" /> Note: Expressions are not allowed as arguments on the BS1. The only
constant allowed for the BS1 <span class="keyword_in_text">DEBUG</span> command is a text string.</p>
<h2>Quick Facts<br /></h2>
<table width="100%" cellpadding="4" cellspacing="0" border="1">
<tr bgcolor="#CFCFCF">
<td width="16%" align="center">&#160;</td>
<td width="28%" align="center">BS1</td>
<td width="28%" align="center">BS2, BS2e, BS2sx, BS2p, and BS2pe</td>
<td width="28%" align="center">BS2px</td>
</tr>
<tr>
<td align="center" bgcolor="#CFCFCF">Serial Protocol</td>
<td align="center">Asychronous 4800 baud, N, 8, 1<br></br>Inverted polarity,
Raw Data<br></br>Custom packetized format</td>
<td align="center">Asychronous 9600 baud, N, 8, 1<br></br>Inverted polarity,
Raw Data</td>
<td align="center">Asychronous 19.2 kBaud, N, 8, 1<br></br>Inverted polarity,
Raw Data</td>
</tr>
<tr>
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
<td align="center" colspan="3">
<p colspan="3" align="center"><a href="DEBUGIN.htm" target="" title="" alt="" class="MCXref_0">DEBUGIN</a>, <a href="SEROUT.htm" target="" title="" alt="" class="MCXref_0">SEROUT</a></p>
</td>
</tr>
</table>
<h2>Explanation</h2>
<p class="PlainText"><span class="keyword_in_text">DEBUG</span> provides a convenient way for your BASIC Stamp to send messages to
the PC screen while running. The name "debug" suggests its most popular use;
debugging programs by showing you the value of a variable or expression, or by
indicating what portion of a program is currently executing. <span class="keyword_in_text">DEBUG</span> is also
a great way to rehearse programming techniques. Throughout this manual, we use
<span class="keyword_in_text">DEBUG</span> to give you immediate feedback on the effects of instructions. The
following example demonstrates using the <span class="keyword_in_text">DEBUG</span> command to send the text
string message "Hello World!". </p><pre class="BScode" xml:space="preserve">
DEBUG "Hello, World!" ' test Message
</pre>
<p class="PlainText">After you download this one-line program, the BASIC Stamp Editor will open a
Debug terminal on your PC screen and wait for a response from the BASIC Stamp.
A moment later, the phrase "Hello World!" will appear. Note that if you close the
Debug terminal, your program keeps executing, but you can't see the <span class="keyword_in_text">DEBUG</span>
data anymore.</p>
<p class="PlainText">Multiple pieces of data can be sent with one <span class="keyword_in_text">DEBUG</span> command by separating
the data with commas (,). The following example produces exactly the same results
as the example above.</p><pre class="BScode" xml:space="preserve">
DEBUG "Hello, ", "World!" ' test Message
</pre>
<p class="PlainText"><span class="keyword_in_text">DEBUG</span> can also print and format numbers (values) from both constants
and variables. Please note that formatting the <span class="keyword_in_text">DEBUG</span> output with the BS1
differs significantly from formatting the <span class="keyword_in_text">DEBUG</span> output with the BS2 family.
Please read the appropriate sections that follow carefully.</p>
<p class="Tip" MadCap:autonum="Tip: &#160;"><span class="autonumber"><span class="TipSpan">Tip: &#160;</span></span><b>Don't let your BASIC Stamp be mistaken for a mouse! </b>
<br />
<br />Connecting USB-based boards to your PC may cause the BASIC Stamp to reset. If your BASIC Stamp program immediately starts sending serial data to the computer via a <span class="keyword_in_text">DEBUG</span> or <span class="keyword_in_text">SEROUT</span> command, your computer's operating system may mistake it for a mouse or other serial plug-and-play device. To avoid this, place a 1-second pause at the beginning of the program. </p>
<h2>
<img align="absmiddle" src="../../graphics/bs1_inline.gif" border="0" />&#160; BASIC Stamp 1 Formatting</h2>
<p class="PlainText">On the BS1, the <span class="keyword_in_text">DEBUG</span> command, by default, displays numbers in the format
"symbol = value" (followed by a carriage return), using the decimal number system.
For example: </p><pre class="BScode" xml:space="preserve">
SYMBOL x = B2
Init:
x = 75
Main:
DEBUG x
END
</pre>
<p class="PlainText">...displays "x = 75" on the screen. To display the value, in decimal, without
the "x =" text, use the decimal formatter (#) before the variable name. For
example, the following code displays "75" on the screen:</p><pre class="BScode" xml:space="preserve">
SYMBOL x = B2
Init:
x = 75
Main:
DEBUG #x
END
</pre>
<p class="PlainText">To display numbers in hexadecimal or binary form, use the $ or % formatter,
respectively. The code below displays the same number in its hexadecimal and binary
forms.</p><pre class="BScode" xml:space="preserve">
SYMBOL x = B2
Init:
x = 75
Main:
DEBUG $x, %x
END
</pre>
<p class="PlainText">After running the above code, "X = $4B" and "X = %01001011" should appear on the
screen. To display hexadecimal ($) or binary (%) values without the "symbol = "
preface, use the # modifier as shown below:</p><pre class="BScode" xml:space="preserve">
SYMBOL x = B2
x = 75
DEBUG #x, "as HEX is ", #$x ' displays "75 as HEX is $4B"
</pre>
<p class="PlainText">To display a number as its ASCII character equivalent, use the ASCII formatter
(@). Typing <span class="keyword_in_text">DEBUG</span> @x (in place of the <span class="keyword_in_text">DEBUG</span> statement in the code
above) would display "x = 'K'" on the screen.</p>
<p class="PlainText">Two pre-defined symbols, CR and CLS, can be used to send a carriage-return or
clear-screen command to the Debug Terminal. The CR symbol will cause the Debug
Terminal to start a new line and the CLS symbol will cause the Debug Terminal to
clear itself and place the cursor at the top-left corner of the screen. The
following code demonstrates this.</p><pre class="BScode" xml:space="preserve">
DEBUG "You can not see this.", CLS, "Here is line 1", CR, "Here is line 2"
</pre>
<p class="PlainText">When the above is run, the final result is "Here is line 1" on the first line
of the screen and "Here is line 2" on the second line. You may or may not have
seen "You can not see this." appear first. This is because it was immediately
followed by a clear-screen symbol, CLS, which caused the display to clear the
screen before displaying the rest of the information.</p>
<p class="Tip" MadCap:autonum="Tip: &#160;"><span class="autonumber"><span class="TipSpan">Tip: &#160;</span></span><b>The rest of this discussion does not apply to the BASIC Stamp
1.</b>
</p>
<h2>
<img align="absmiddle" src="../../graphics/bsall_inline.gif" border="0" />&#160; BASIC Stamp 2 Series Formatting</h2>
<p class="PlainText">On the all BASIC Stamp models except the BS1, the <span class="keyword_in_text">DEBUG</span> command, by default,
displays everything as ASCII characters. What if you want to display a number?
You might think the following example would do this:</p><pre class="BScode" xml:space="preserve">
x VAR Byte
Init:
x = 65
Main:
DEBUG x ' show value of x
END
</pre>
<p class="PlainText">Since we set x equal to 65 (in line 2), you might expect the <span class="keyword_in_text">DEBUG</span> line
to display "65" on the screen. Instead of "65", however, you'll see the letter
"A" if you run this example. The problem is that we never told the BASIC Stamp
how to output x, and it defaults to ASCII (the ASCII character at position 65 is
"A"). Instead, we need to tell it to display the "decimal form" of the number in
X. We can do this by using the decimal formatter (DEC) before the variable. The
example below will display "65" on the screen.</p><pre class="BScode" xml:space="preserve">
x VAR Byte
Init:
x = 65
Main:
DEBUG DEC x ' show decimal value of x
END
</pre>
<p class="PlainText">In addition to decimal (DEC), <span class="keyword_in_text">DEBUG</span> can display numbers in hexadecimal
(HEX) and binary (BIN). See the table below for a complete list of formatters.</p>
<p>Expressions are allowed within the <span class="keyword_in_text">DEBUG</span> command arguments as well. In
the above code, <span class="keyword_in_text">DEBUG</span> DEC x+25 would yield "90" and <span class="keyword_in_text">DEBUG</span> DEC
x*10/2-3 would yield "322".</p>
<p>&#160;</p>
<table width="100%" cellpadding="4" cellspacing="0" border="1">
<tr bgcolor="#CFCFCF" align="center" valign="top">
<td width="150">Formatter</td>
<td width="80%">Description</td>
</tr>
<tr valign="top">
<td>?</td>
<td>Displays "symbol = x' + carriage return; where x is a number. Default
format is decimal, but may be combined with conversion formatters (ex:
BIN ? x to display "x = binary_number").</td>
</tr>
<tr valign="top">
<td>ASC ?</td>
<td>Displays "symbol = 'x'" + carriage return; where x is an ASCII character.</td>
</tr>
<tr valign="top">
<td>DEC{1..5}</td>
<td>Decimal, optionally fixed to 1 - 5 digits</td>
</tr>
<tr valign="top">
<td>SDEC{1..5}</td>
<td>Signed decimal, optionally fixed to 1 - 5 digits</td>
</tr>
<tr valign="top">
<td>HEX{1..4}</td>
<td>Hexadecimal, optionally fixed to 1 - 4 digits</td>
</tr>
<tr valign="top">
<td>SHEX{1..4}</td>
<td>Signed hexadecimal, optionally fixed to 1 - 4 digits </td>
</tr>
<tr valign="top">
<td>IHEX{1..4}</td>
<td>Indicated hexadecimal, optionally fixed to 1 - 4 digits</td>
</tr>
<tr valign="top">
<td>ISHEX{1..4}</td>
<td>Signed, indicated hexadecimal, optionally fixed to 1 - 4 digits ($ prefix)</td>
</tr>
<tr valign="top">
<td>BIN{1..16}</td>
<td>Binary, optionally fixed to 1 - 16 digits</td>
</tr>
<tr valign="top">
<td>SBIN{1..16}</td>
<td>Signed binary, optionally fixed to 1 - 16 digits</td>
</tr>
<tr valign="top">
<td>IBIN{1..16}</td>
<td>Indicated binary, optionally fixed to 1 - 16 digits</td>
</tr>
<tr valign="top">
<td>ISBIN{1..16}</td>
<td>Signed, indicated binary, optionally fixed to 1 - 16 digits</td>
</tr>
<tr valign="top">
<td>STR ByteArray</td>
<td>ASCII string from bytearray until byte = 0.</td>
</tr>
<tr valign="top">
<td>STR ByteArray {\L}</td>
<td>ASCII string consisting of n bytes from bytearray.</td>
</tr>
<tr valign="top">
<td>REP Byte\L</td>
<td>Display ASCII character n times.</td>
</tr>
</table>
<p class="PlainText">As seen above, special versions of the DEC, HEX and BIN formatters allow for
the display of indicated, signed and fixed-width numbers. The term "indicated"
simply means that a special symbol is displayed, before the number, indicating
what number system it belongs to. For example:</p><pre class="BScode" xml:space="preserve">
x VAR Byte
Init:
x = 65
Main:
DEBUG HEX x ' show hexadecimal value of x
END
</pre>
<p class="PlainText">...displays "41" (65, in decimal, is 41, in hexadecimal). You might see a problem
here... unless you knew the number was supposed to be hexadecimal, you might think
it was 41, in decimal... a totally different number. To help avoid this, use the
IHEX formatter (the "I" stands for indicated). Changing the <span class="keyword_in_text">DEBUG</span> line to
read: <span class="keyword_in_text">DEBUG</span> IHEX x would print "$41" on the screen. A similar formatter
for binary also exists, IBIN, which prints a "%" before the number.</p>
<p class="PlainText">Signed numbers are preceded with a space ( ) or a minus sign (-) to indicate a
positive or negative number, respectively. Normally, any number displayed by the
BASIC Stamp is shown in its unsigned (positive) form without any indicator. The
signed formatters allow
you to display the number as a signed (rather than unsigned) value.</p>
<p class="Tip" MadCap:autonum="Tip: &#160;"><span class="autonumber"><span class="TipSpan">Tip: &#160;</span></span><b>Only
Word-sized variables can be used for signed number display. </b>
</p>
<p class="PlainText">The code below
demonstrates the difference in all three numbering schemes.</p><pre class="BScode" xml:space="preserve">
x VAR Word
Init:
x = -65
Main:
DEBUG "Signed: ", SDEC x, " ", ISHEX x, " ", ISBIN x, CR
DEBUG "Unsigned: ", DEC x, " ", IHEX x, " ", IBIN x
END
</pre>
<p class="PlainText">This code will generate the display shown below:</p><pre>Signed: -65 -$41 -%1000001<br />Unsigned: 65471 $FFBF %1111111110111111
</pre>
<p class="PlainText">The signed form of the number -65 is shown in decimal, hexadecimal and then in
binary on the top line. The unsigned form, in all three number systems, is shown
on the bottom line. If the unsigned form looks strange to you, it's because negative
numbers are stored in twos-compliment format within the BASIC Stamp. </p>
<p class="PlainText">Suppose that your program contained several <span class="keyword_in_text">DEBUG</span> instructions showing
the contents of different variables. You would want some way to tell them apart.
One possible way is to do the following:</p><pre class="BScode" xml:space="preserve">
x VAR Byte
y VAR Byte
Init:
x = 100
y = 250
Main:
DEBUG "X = ", DEC x, CR ' show decimal value of x
DEBUG "Y = ", DEC y, CR ' show decimal value of y
END
</pre>
<p class="PlainText">...but typing the name of the variables in quotes (for the display) can get a
little tedious. A special formatter, the question mark (?), can save you a lot
of time. The code below does exactly the same thing (with less typing):</p><pre class="BScode" xml:space="preserve">
x VAR Byte
y VAR Byte
Init:
x = 100
y = 250
Main:
DEBUG DEC ? x ' show decimal value of x
DEBUG DEC ? y ' show decimal value of y
END
</pre>
<p class="PlainText">The display would look something like this:</p><pre>x = 100<br />y = 250
</pre>
<p class="PlainText">The ? formatter always displays data in the form "symbol = value" (followed by
a carriage return). In addition, it defaults to displaying in decimal, so we really
only needed to type: <span class="keyword_in_text">DEBUG</span> ? x for the above code. You can, of course,
use any of the three number systems. For example: <span class="keyword_in_text">DEBUG</span> HEX ? x or
<span class="keyword_in_text">DEBUG</span> BIN ? y. </p>
<p class="PlainText">It's important to note that the "symbol" it displays is taken directly from what
appears to the right of the ?. If you were to use an expression, for example:
<span class="keyword_in_text">DEBUG</span> ? x*10/2+3 in the above code, the display would show: "x*10/2+3
= 503". </p>
<p class="PlainText">A special formatter, ASC, is also available for use only with the ? formatter
to display ASCII characters, as in: <span class="keyword_in_text">DEBUG</span> ASC ? x.</p>
<p class="PlainText">What if you need to display a table of data; multiple rows and columns? The
Signed/Unsigned code (above) approaches this but, if you notice, the columns don't
line up. The number formatters (DEC, HEX and BIN) have some useful variations to
make the display fixed-width. Up to 5 digits can be displayed for decimal numbers.
To fix the value to a specific number of decimal digits, you can use DEC1, DEC2,
DEC3, DEC4 or DEC5. For example:</p><pre class="BScode" xml:space="preserve">
x VAR Byte
Init:
x = 165
Main:
DEBUG DEC5 x ' show decimal value of x
END ' in 5 digits
</pre>
<p class="PlainText">...displays "00165". Notice that leading zeros? The display is "fixed" to 5 digits,
no more and no less. Any unused digits will be filled with zeros.</p>
<p class="PlainText">Using DEC4 in the same code would display "0165". DEC3 would display "165".
What would happen if we used DEC2? Regardless of the number, the BASIC Stamp will
ensure that it is always the exact number of digits you specified. In this case,
it would truncate the "1" and only display "65". </p>
<p class="PlainText">Using the fixed-width version of the formatters in the Signed/Unsigned code
above, may result in the following code:</p><pre class="BScode" xml:space="preserve">
x VAR Word
Init:
x = -65
Main:
DEBUG "Signed: ", SDEC5 x, " ", ISHEX4 x, " ", ISBIN16 x, CR
DEBUG "Unsigned: ", DEC5 x, " ", IHEX4 x, " ", IBIN16 x
END
</pre>
<p>...and displays:</p><pre>Signed: -00065 -$0041 -%0000000001000001<br />Unsigned: 65471 $FFBF %1111111110111111
</pre>
<p class="PlainText">Note that the columns don't line up exactly (due to the extra "sign" characters
in the first row), but it certainly looks better than the alternative.</p>
<h3><a name="Displayi"></a>Displaying Strings (Byte Arrays)</h3>
<p class="PlainText">If you have a string of characters to display (a byte array), you can use the
STR formatter to do so. The STR formatter has two forms (as shown in the table above)
for variable-width and fixed-width data. The example below is the variable-width
form.</p><pre class="BScode" xml:space="preserve">
alpha VAR Byte(5)
Init:
alpha(0) = "A"
alpha(1) = "B"
alpha(2) = "C"
alpha(3) = "D"
alpha(4) = 0
Main:
DEBUG STR alpha, CR ' display "ABCD"
END
</pre>
<p class="PlainText">This code displays "ABCD" on the screen. In this form, the STR formatter displays
each character contained in the byte array until it finds a character that is equal
to 0 (value 0, not "0"). This is convenient for use with the <a href="SERIN.htm" target="" title="" alt="" class="MCXref_0">SERIN</a> command's STR
formatter, which appends 0's to the end of variable-width character string inputs.
NOTE: If your byte array doesn't end with 0, the BASIC Stamp will read and output
all RAM register contents until it finds a 0 or until it cycles through all RAM
locations.</p>
<p class="PlainText">To specify a fixed-width format for the STR formatter, use the form STR alpha\n;
where alpha is the byte array and n is the number of characters to print. Changing
the <span class="keyword_in_text">DEBUG</span> line in the example above to: <span class="code_in_text">DEBUG STR alpha\2</span> would display
"AB" on the screen.</p>
<p class="PlainText">If you need to display the same ASCII character multiple times, the REP (repeat)
formatter can help. REP takes the form: REP x\n ;where x is the character and
n is the number of times to repeat it. For example:</p><pre class="BScode" xml:space="preserve">
DEBUG REP "-"\10
</pre>
<p class="PlainText">...would display 10 hyphens on the screen, "<tt>----------</tt>". </p>
<p class="PlainText">Since individual <span class="keyword_in_text">DEBUG</span> instructions can grow to be fairly complicated,
and since a program can contain many <span class="keyword_in_text">DEBUG</span>s, you'll probably want to control
the character positioning of the Debug Terminal screen. <span class="keyword_in_text">DEBUG</span> supports a
number of different control characters, some with pre-defined symbols. The Debug
Terminal in the Windows<sup>®</sup> version of the editor supports all the
control characters shown below, while the DOS version only supports a few of them.</p>
<p class="PlainText">Some of the control characters have pre-defined symbols associated with them.
In your <span class="keyword_in_text">DEBUG</span> commands, you can use those symbols, for example: <span class="keyword_in_text">DEBUG</span>"Hello", CR displays "Hello" followed by a carriage return. You can always use
the ASCII value for any of the control characters, however. For example: <span class="keyword_in_text">DEBUG</span>"Hello", 13 is exactly the same as the code above.</p>
<p class="PlainText">The Move To control character is perhaps the most unique of the set. If the
Debug Terminal receives this character, it expects to see an x and y position value
to follow (in the next two characters received). The following line moves the
cursor to column number 4 in row number 5 and displays "Hello":</p><pre class="BScode" xml:space="preserve">
DEBUG CRSRXY, 4, 5, "Hello"
</pre>
<p class="PlainText">The upper-left cursor position is 0, 0 (that is column 0, line 0). The right-most
cursor positions depend on the size of the Debug Terminal window (which is user
adjustable). If a character position that is out of range is received, the Debug
Terminal wraps back around to the opposite side of the screen.</p>
<p class="PlainText">The Clear EOL (end of line) control character clears the characters that appear
to the right of, and on, the cursor's current position. The cursor is not moved
by this action.</p>
<p class="PlainText">The Clear Down control character clears the characters that appear below, and
on, the cursor's current line. The cursor is not moved by this action.</p>
<table width="100%" cellpadding="4" cellspacing="0" border="1">
<tr bgcolor="#CFCFCF" align="center" valign="top">
<td width="150">Name</td>
<td width="75">Symbol</td>
<td width="75">ASCII<br></br>Value</td>
<td width="1000">Description</td>
</tr>
<tr valign="top">
<td width="150">Clear Screen</td>
<td width="75" align="center">CLS <sup>1</sup></td>
<td width="75" align="center">0</td>
<td width="1000">Clear the screen and place cursor at home position.</td>
</tr>
<tr valign="top">
<td width="150">Home</td>
<td width="75" align="center">HOME</td>
<td width="75" align="center">1</td>
<td width="1000">Place cursor at home in upper-left corner of the screen.</td>
</tr>
<tr valign="top">
<td width="150">Move To (x, y)</td>
<td width="75" align="center">CRSRXY <sup>2</sup></td>
<td width="75" align="center">2</td>
<td width="1000">Move cursor to specified location (column, line). Must be
followed by two values (x and then y)</td>
</tr>
<tr valign="top">
<td width="150">Cursor Left</td>
<td width="75" align="center">CRSRLF <sup>2</sup></td>
<td width="75" align="center">3</td>
<td width="1000">Move cursor one character to left.</td>
</tr>
<tr valign="top">
<td width="150">Cursor Right</td>
<td width="75" align="center">CRSRRT <sup>2</sup></td>
<td width="75" align="center">4</td>
<td width="1000">Move cursor one character to right.</td>
</tr>
<tr valign="top">
<td width="150">Cursor Up</td>
<td width="75" align="center">CRSRUP <sup>2</sup></td>
<td width="75" align="center">5</td>
<td width="1000">Move cursor one character up.</td>
</tr>
<tr valign="top">
<td width="150">Cursor Down</td>
<td width="75" align="center">CRSRDN <sup>2</sup></td>
<td width="75" align="center">6</td>
<td width="1000">Move cursor one character down.</td>
</tr>
<tr valign="top">
<td width="150">Bell</td>
<td width="75" align="center">BELL</td>
<td width="75" align="center">7</td>
<td width="1000">Beep the PC speaker.</td>
</tr>
<tr valign="top">
<td width="150">Backspace</td>
<td width="75" align="center">BKSP</td>
<td width="75" align="center">8</td>
<td width="1000">Back up cursor to left one space.</td>
</tr>
<tr valign="top">
<td width="150">Tab</td>
<td width="75" align="center">TAB</td>
<td width="75" align="center">9</td>
<td width="1000">Tab to the next column.</td>
</tr>
<tr valign="top">
<td width="150">Line Feed</td>
<td width="75" align="center">LF</td>
<td width="75" align="center">10</td>
<td width="1000">Move cursor down one line.</td>
</tr>
<tr valign="top">
<td width="150">Clear to End of Line</td>
<td width="75" align="center">CLREOL <sup>2</sup></td>
<td width="75" align="center">11</td>
<td width="1000">Clear line contents to the right of cursor.</td>
</tr>
<tr valign="top">
<td width="150">Clear Down</td>
<td width="75" align="center">CLRDN <sup>2</sup></td>
<td width="75" align="center">12</td>
<td width="1000">Clear screen contents below cursor.</td>
</tr>
<tr valign="top">
<td width="150">Carriage Return</td>
<td width="75" align="center">CR <sup>1</sup></td>
<td width="75" align="center">13</td>
<td width="1000">Move cursor to the first column of the next line (shift any
data on the right down to that line as well)</td>
</tr>
<tr valign="top">
<td width="150">Move To Column X</td>
<td width="75" align="center">CRSRX <sup>2</sup></td>
<td width="75" align="center">14</td>
<td width="1000">Move cursor to specified column. Must be followed by byte
value (x) for the column (0 is the left-most column)</td>
</tr>
<tr valign="top">
<td width="150">Move To Line Y</td>
<td width="75" align="center">CRSRY <sup>2</sup></td>
<td width="75" align="center">15</td>
<td width="1000">Move cursor to specified line. Must be followed by byte
value (y) for the line (0 is the top-most line)</td>
</tr>
</table>
<p><sup>1</sup> Supported by BS1 <span class="keyword_in_text">DEBUG </span>command (others not supported).<br /><sup>2</sup> This control character only works with the Windows<sup>®</sup>
version of the editor software.</p>
<p class="PlainText">&#160;</p>
<p class="PlainText">In the BS2 family, <span class="keyword_in_text">DEBUG</span> is actually a special case of the <span class="keyword_in_text">SEROUT</span>instruction. It is set for inverted (RS-232-compatible) serial output through the
programming connector (the SOUT pin) at 9600 baud (BS2, BS2e, BS2sx, BS2p, and
BS2pe) or 19.2 kBaud (BS2px), no parity, 8 data bits, and 1 stop bit.
For example,</p><pre class="BScode" xml:space="preserve">
DEBUG "Hello"
</pre>
<p class="PlainText">...is exactly like:</p><pre class="BScode" xml:space="preserve">
SEROUT 16, $4054, ["Hello"]
</pre>
<p class="PlainText">in terms of function (on a BS2). The <span class="keyword_in_text">DEBUG</span> line actually takes less
program space, and is obviously easier to type.</p>
<p class="PlainText">You may view <span class="keyword_in_text">DEBUG</span>'s output using a terminal program set to the above
parameters, but you may have to modify either your carrier board or the serial
cable to temporarily disconnect pin 3 of the BASIC Stamp (pin 4 of the DB-9
connector). See the <a href="SEROUT.htm" target="" title="" alt="" class="MCXref_0">SEROUT</a> command for more detail. </p>
<p class="PlainText">Another method to decrease program space is to reduce the number of <span class="keyword_in_text">DEBUG</span>
instructions by spreading <span class="keyword_in_text">DEBUG</span> data across multiple lines. To do this,
each line that wraps around must end with a comma as in the example below:
</p><pre class="BScode" xml:space="preserve">
DEBUG "This is line 1", CR,
"This is line 2"
</pre>
<p class="PlainText">The example above works identically to, but uses less program space than, this version:</p><pre class="BScode" xml:space="preserve">
DEBUG "This is line 1", CR
DEBUG "This is line 2"
</pre>
<p class="Tip" MadCap:autonum="Tip: &#160;"><span class="autonumber"><span class="TipSpan">Tip: &#160;</span></span>Note that spreading a <span class="keyword_in_text">DEBUG</span> statement across multiple lines requires the
declaration of PBASIC 2.5 syntax.</p>
<div class="Col2">
<div class="MasterFoot">
<p MadCap:conditions="BSEconditions.BSEWebHelp (Primary)-INCLUDE"><a href="../../HomeTopics/HomePage.htm">Go to Welcome page</a>
</p>
</div>
</div>
<div class="Col2">
<div class="MasterFoot">
<p style="text-align: right;"><span class="ContactInfoProjectName">BASIC Stamp Help</span> <![CDATA[ ]]><span class="ContactInfoVersion#">Version 2.5.4</span> <![CDATA[ ]]></p>
<p style="text-align: right;">Copyright ©&#160;<span class="ContactInfoCompanyName">Parallax Inc.</span></p>
<p style="text-align: right;"><span class="SystemShortDate">8/8/2012</span>
</p>
</div>
</div>
<script type="text/javascript">/* <![CDATA[ */
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-285614-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
/* ]]> */</script>
<script type="text/javascript" src="../../SkinSupport/MadCapBodyEnd.js">
</script>
</body>
</html>