Initial commit after migrating repo and assuring the product launches
This commit is contained in:
272
help/BasicStampHelp/Content/LanguageTopics/Reference/Adapt.htm
Normal file
272
help/BasicStampHelp/Content/LanguageTopics/Reference/Adapt.htm
Normal file
@ -0,0 +1,272 @@
|
||||
<?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="PBASIC Language Reference" 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>Adapt BS2 Code to Other Models</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>
|
||||
<div class="MCBreadcrumbsBox_0"><span class="MCBreadcrumbsPrefix">You are here: </span><a class="MCBreadcrumbsLink" href="AlphaRef.htm">PBASIC Language Reference</a><span class="MCBreadcrumbsDivider"> > </span><span class="MCBreadcrumbs">Adapt BS2 Code to other Models</span>
|
||||
</div>
|
||||
<h1>Adapt BS2 Code to Other Models</h1>
|
||||
<p>Parallax provides PBASIC code examples for many applications and devices, and many more examples can be found on the <a href="http://forums.parallax.com/forums/" target="_blank" title="Open website in new window" alt="Open website in new window">Parallax forums</a> and other web sites. While some code examples include compiler directives that make them compatible with any 24-pin BASIC Stamp model, others are written for a single model, most often the BS2. If your BASIC Stamp model is different from the one the code is written for, portions of the program may need to be adjusted to accommodate differences in processor speed. This page provides some tips and examples of how to do this.</p>
|
||||
<h2>About Time-Sensitive Commands</h2>
|
||||
<p class="PlainText">Many BASIC Stamp 2 application examples make use of time-sensitive commands, those which have one or more arguments that depend on some attribute of time such as frequency, duration, baud rate, decay time, or pulse duration. If the command generates a signal, one or more of its arguments may contain values that affect the signal’s timing. Likewise, if the command measures a signal, one or more of its arguments may affect the result. When executed by different BASIC Stamp 2 models, the units for each time-sensitive argument may differ, so if the program is not adjusted to account for these differences, signals may be generated or measured at different rates. </p>
|
||||
<h3>Adjustable Time-sensitive Commands </h3>
|
||||
<table cellpadding="4" cellspacing="0" border="0">
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/COUNT.htm" target="" title="" alt="" class="MCXref_0">COUNT</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_2family.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">COUNT</span><i> Pin, Duration, Variable</i>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/DTMFOUT.htm" target="" title="" alt="" class="MCXref_0">DTMFOUT</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_2family.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">DTMFOUT</span> Pin, {<i>OnTime, OffTime,</i> } [<i>Tone</i>
|
||||
{<i>, Tone,</i> ...}]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/FREQOUT.htm" target="" title="" alt="" class="MCXref_0">FREQOUT</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_2family.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">FREQOUT</span><i> Pin, Duration, Freq1</i> {, <i>Freq2</i> }</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/POLLWAIT.htm" target="" title="" alt="" class="MCXref_0">POLLWAIT</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_ppepx.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">POLLWAIT </span><i>Duration</i>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/PULSIN.htm" target="" title="" alt="" class="MCXref_0">PULSIN</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">PULSIN</span><i> Pin, State, Variable</i>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/PULSOUT.htm" target="" title="" alt="" class="MCXref_0">PULSOUT</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">PULSOUT </span><i>Pin, Duration</i>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/PWM.htm" target="" title="" alt="" class="MCXref_0">PWM</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">PWM </span><i>Pin, Duty, Duration</i>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/RCTIME.htm" target="" title="" alt="" class="MCXref_0">RCTIME</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_2family.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">RCTIME</span><i> Pin, State, Variable</i>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/SERIN.htm" target="" title="" alt="" class="MCXref_0">SERIN</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">SERIN</span><i> Rpin</i> {\<i>Fpin</i>}, <i>Baudmode</i>,
|
||||
{<i>Plabel</i>,} {<i>Timeout</i>, <i>Tlabel</i>, } [<i>InputData</i>]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/SEROUT.htm" target="" title="" alt="" class="MCXref_0">SEROUT</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">SEROUT</span><i> Tpin</i> {\<i>Fpin</i>}, <i>Baudmode</i>,
|
||||
{<i>Pace</i>,} {<i>Timeout</i>, <i>Tlabel</i>,} [<i>OutputData</i>]</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p> </p>
|
||||
<h2>Adapting Code with No Time-sensitive Commands</h2>
|
||||
<p class="PlainText">If the BS2 application does not utilize any of the time-sensitive commands listed above, all that needs to change is the $STAMP directive. Here is an example BASIC Stamp 2 program that has no time-sensitive commands.</p><pre class="BScode" xml:space="preserve">' Hello World.bs2
|
||||
' {$STAMP BS2}
|
||||
' {$PBASIC 2.5}
|
||||
|
||||
DEBUG "Hello world!"
|
||||
|
||||
END</pre>
|
||||
<p class="PlainText">With this program, the only change that would need to be made to get this program to run properly with a BS2sx (for example), would be to update the $STAMP directive from BS2 to BS2sx. You can either manually modify the $STAMP directive,  or click the BS2sx button on the BASIC Stamp Editor’s toolbar (recommended).</p>
|
||||
<p class="PlainText">
|
||||
<img src="../../Resources/Images/BS2xsbutton.png" />
|
||||
</p>
|
||||
<p class="Tip" MadCap:autonum="Tip:  "><span class="autonumber"><span class="TipSpan">Tip:  </span></span>The BASIC Stamp Editor can detect if you are trying to load a program into a BASIC Stamp model that’s different from the one indicated in the program’s $STAMP directive. When this happens, it will ask you if you want it to automatically update the directive. Keep in mind that this directive update does not automatically update any time-sensitive command arguments.</p>
|
||||
<h2>Adapting Code that has Time-sensitive Commands</h2>
|
||||
<p class="PlainText">In addition to updating the $STAMP directive, each line of code that uses a time-sensitive command will need to be examined and possibly adjusted. The <a href="AlphaRef.htm" target="" title="" alt="" class="MCXref_0">PBASIC Command Reference</a> has links to the documentation for each command, including Quick Facts tables with the units of time-based attributes for each BASIC Stamp model. In most cases, you can use the units for the model the code is written for along with the units for the new target model to make a fraction for converting a given time-sensitive command argument. The units value for the “Convert from” model should be in the numerator, and the units for the “Convert to” model should be in the denominator. Make sure to round the “New Argument Value” to the nearest integer before using it as a command argument in a time-sensitive PBASIC command. </p>
|
||||
<p>
|
||||
<img src="../../Resources/Images/AdaptMath.png" />
|
||||
</p>
|
||||
<p class="Tip" MadCap:autonum="Tip:  "><span class="autonumber"><span class="TipSpan">Tip:  </span></span>The SERIN and SEROUT commands have baud rate arguments that don't use this adjustment method. The Quick Facts tables for SERIN and SEROUT have common baud rates listed, and the documentation also provides directions for calculating custom baud rates for all BASIC Stamp 2 models.</p>
|
||||
<p class="PlainText">The “Old Argument Value” to “New Argument Value” calculation can be used in three different approaches for updating your code:</p>
|
||||
<ol>
|
||||
<li value="1">Update time-sensitive command argument constants, and/or constants that are compared to results stored in variables by time-sensitive commands.</li>
|
||||
<li value="2">Calculate a re-usable multiplier for all instances of a command's argument.</li>
|
||||
<li value="3">Use the results of #1 and/or #2 to set up conditional compilation directives, so the program can be run on whichever BASIC Stamp models you choose to make compatible code for.</li>
|
||||
</ol>
|
||||
<p class="PlainText">Let’s take a look at how each approach can be used with the time-sensitive <span class="keyword_in_text">FREQOUT </span>command as an example, with the BS2 as the “Convert From” model and the BS2sx as the “Convert To” model.</p>
|
||||
<h3>Approach 1- Update Time Sensitive Argument Constants</h3>
|
||||
<p class="PlainText">Let’s say a speaker circuit is connected to BASIC Stamp I/O pin P6. If the BS2 executes the command:</p><pre class="snippet">FREQOUT 6, 100, 4500</pre>
|
||||
<p class="PlainText">... it sends a high-pitched alarm tone to the speaker for 100 ms at a frequency of 4500 Hz. A <span class="keyword_in_text">FREQOUT </span>command with the same arguments executed by the BS2sx sends a tone that only last 40 ms at a frequency of 11,250 Hz. That’s a much shorter duration tone with a much higher pitch!</p>
|
||||
<p class="PlainText">The <span class="keyword_in_text">FREQOUT </span>command’s Quick Facts table indicates that the <span class="keyword_in_text">FREQOUT</span> <![CDATA[ ]]><i>Duration</i> argument is in terms of 1 ms units for the BS2, and in terms of 0.4 ms units for the BS2sx. Likewise, the BS2 units for <i>Freq1</i> are 1 Hz, while the BS2sx <i>Freq1</i> units are 2.5 Hz. You can use those values and the “Old Argument Value” to “New Argument Value” equation to convert a BS2 command like:</p><pre class="snippet">FREQOUT 6, 100, 4500 </pre>
|
||||
<p class="PlainText">...for use with a BS2sx. In the figure below, the existing <i>Duration</i> argument of 100 gets multiplied by 1.0/0.4 with a result of 250. Likewise, the 4500 <i>Freq1</i> argument gets multiplied by 1.0/2.5 with a nearest integer result of 1800. With these new values, the BS2sx version of the <span class="keyword_in_text">FREQOUT</span> command is:</p><pre class="snippet" xml:space="preserve">FREQOUT 6, 250, 1800</pre>
|
||||
<p class="PlainText">This command is now updated to make the BS2sx deliver a 4.5 kHz tone for 100 ms.</p>
|
||||
<p class="PlainText">
|
||||
<img src="../../Resources/Images/AdaptFreqoutBS2sx.png" />
|
||||
</p>
|
||||
<h3>Approach 2 - Calculate a Re-usable Multiplier</h3>
|
||||
<p class="PlainText">You can incorporate expressions with <span class="keyword_in_text">*/</span> (<a href="Ops_bi.htm#multi-mid">Multiply Middle</a>) operators to perform the conversions from approach 1 right inside a PBASIC program. The <span class="keyword_in_text">*/</span> operator allows you to multiply a constant, variable or expression result by a number of 256ths. For example, 1/4 is the same as 64/256ths, so value <span class="code_in_text">*/ 64</span> is the same as multiplying a value by 1/4. </p>
|
||||
<p class="PlainText"> Each of the fractions determined with the Quick Facts table above can also be expressed as a number of 256ths. The result is “<span class="keyword_in_text">*/</span>Constant” that you can use to scale a constant, variable or expression result to adjust a command's argument for a different BASIC Stamp model.</p>
|
||||
<p class="PlainTextIndent" style="font-style: normal;"><span class="keyword_in_text">*/</span>Constant = Integer(256 x (Units in “Convert From” Model / Units in “Convert To” model))</p>
|
||||
<p class="PlainText">Continuing the <span class="keyword_in_text">FREQOUT </span>command example, the “<span class="keyword_in_text">*/</span>Constant” to convert <i>Duration</i> from BS2 to BS2sx units would be Integer(256 x (1/0.4)) = 640. So, a BS2 <i>Duration</i> value <span class="code_in_text">*/ 640</span> results in an approximate BS2sx <i>Duration</i> value. </p>
|
||||
<p class="PlainText">Likewise, the“<span class="keyword_in_text">*/</span>Constant” for converting <i>Freq1</i> from BS2 to BS2sx is Integer(256 x (1/2.5)) = 102, and a BS2 <i>Freq1</i> <![CDATA[ ]]><span class="code_in_text">*/ 102</span> results in an approximate BS2sx <i>Freq1</i> value. You can incorporate these <span class="keyword_in_text">*/ </span>operations directly into a <span class="keyword_in_text">FREQOUT </span>command’s <i>Duration</i> and <i>Freq1</i> arguments like this:</p><pre class="snippet" xml:space="preserve">FREQOUT 6, 100 */ 640, 4500 */ 102</pre>
|
||||
<p class="PlainText">Keep in mind that this approach works with constants (like 100 and 4500), and it also works with variables and expression results. The only caveat is that it does take a little extra code space and execution time for each added <span class="keyword_in_text">*/</span> operation. A test program for the BS2sx with the updated <span class="keyword_in_text">FREQOUT </span>command might look like this:</p><pre xml:space="preserve" class="BScode">' Tenth Second 4.5 kHz Tone StarSlash.bsx
|
||||
' {$STAMP BS2sx}
|
||||
' {$PBASIC 2.5}
|
||||
|
||||
FREQOUT 6, 100 */ 640, 4500 */ 102
|
||||
|
||||
END</pre>
|
||||
<p class="PlainText">Declaring constants for each of these <span class="keyword_in_text">*/</span> multipliers makes it possible to update values once at the beginning for the program for multiple <span class="keyword_in_text">FREQOUT </span>commands. With the constant declaration approach, our example program would looks like this:</p><pre class="BScode" xml:space="preserve">' Tenth Second 4.5 kHz Tone StarSlash With Constants.bsx
|
||||
' {$STAMP BS2sx}
|
||||
' {$PBASIC 2.5}
|
||||
|
||||
DurFactr CON 640
|
||||
FreqFactr CON 102
|
||||
|
||||
FREQOUT 6, 100*/DurFactr, 4500*/FreqFactr
|
||||
|
||||
END</pre>
|
||||
<p> </p>
|
||||
<h4>Use the ** Operator for Greater Precision</h4>
|
||||
<p class="PlainText">The <span class="keyword_in_text">**</span> (<a href="Ops_bi.htm#multi-high">Multiply High</a>) operator multiplies a constant, variable or expression by a number of 65536ths, up to 65535. For fractional values less than one, it provides higher resolution than the <span class="keyword_in_text">*/</span> operator. Since the fractional value for converting the <span class="keyword_in_text">FREQOUT </span>command’s <i>Freq1</i> argument is less than 1, the <span class="keyword_in_text">**</span> operator can provide a more precise conversion. <br /></p>
|
||||
<p class="PlainTextIndent" style="font-style: normal;">** Constant = Integer(65536 x (Units in “Convert From” Model / Units in “Convert To” model))</p>
|
||||
<p class="PlainText">We can apply this to our BS2 to BS2sx <i>Freq1</i> argument conversion with:</p>
|
||||
<p class="PlainTextIndent" style="font-style: normal;">** Constant = Integer(65536 x (1 / 2.5)) = 26214</p>
|
||||
<p class="PlainText">Now, the <span class="keyword_in_text">FREQOUT </span>command with a more precise <i>Freq1</i> argument conversion is:</p><pre class="snippet" xml:space="preserve">FREQOUT 6, 100 */ 640, 4500 ** 26214</pre>
|
||||
<p class="PlainText">How much more precise is it? The BASIC Stamp always truncates to the integer in a calculation, so </p>
|
||||
<p class="PlainTextIndent">4500 */ 102 = 4500 x 102 ÷ 256 = 1792 </p>
|
||||
<p class="PlainText">...truncated to the integer. For the BS2sx, that results in a frequency of 1792 x 2.5 Hz = 4480 Hz. That’s an error of 20 Hz, which is enough to be audible to sensitive ears or equipment. In contrast,</p>
|
||||
<p class="PlainTextIndent"> 4500 ** 26214 = 4500 x 26214 ÷ 65536 = 1799 <![CDATA[ ]]></p>
|
||||
<p class="PlainText">...truncated to the integer. This time, the BS2sx transmits a frequency of 1799 x 2.5 Hz = 4497.5 Hz, so the propagated error is now only 2.5 Hz! Here is a program that compares the tones:</p><pre class="BScode" xml:space="preserve">' Tenth Second 4.5 kHz Tone Compare StarSlash and StarStar.bsx
|
||||
' {$STAMP BS2sx}
|
||||
' {$PBASIC 2.5}
|
||||
|
||||
DurFactr CON 640
|
||||
FreqFactr VAR Word
|
||||
|
||||
|
||||
FREQOUT 6, 250, 1800 ' Calculated by hand
|
||||
PAUSE 100
|
||||
|
||||
FreqFactr = 102 ' Multiplier for */
|
||||
FREQOUT 6, 100*/DurFactr, 4500*/FreqFactr
|
||||
PAUSE 100
|
||||
|
||||
FreqFactr = 26214 ' Multiplier for **
|
||||
FREQOUT 6, 100*/DurFactr, 4500**FreqFactr
|
||||
|
||||
END</pre>
|
||||
<p class="Tip" MadCap:autonum="Tip:  "><span class="autonumber"><span class="TipSpan">Tip:  </span></span>If you can't hear the difference in the tones, try multiplying each <i>Duration</i> argument by 4 with "<span class="code_in_text">4*</span>" to increase the length time you hear each tone.</p>
|
||||
<h3>Approach 3 - Use Results from 1 or 2 to Set up Conditional Compilation</h3>
|
||||
<p class="PlainText">The results from approaches 1 and 2 can be incorporated into <a href="ConditionalCompile.htm" target="" title="" alt="" class="MCXref_0"> Conditional Compilation</a> directives. Especially when the target BASIC Stamp module could be one of several different models, conditional compilation makes it possible to use the $STAMP directive to select which segments of code get compiled and downloaded to the BASIC Stamp. For example, code from approaches 1 and 2 can be nested into conditional compilation directives. Then, the code can be set to run in a BS2 and BS2sx by simply updating the $STAMP directive.</p>
|
||||
<p class="PlainText">In this first example, the $STAMP directive identifies which BASIC Stamp model is being used at compile time, and then only the <span class="keyword_in_text">FREQOUT </span>command for the model identified gets downloaded. Note that the <span class="keyword_in_text">FREQOUT </span>command for the BS2sx uses the <i>Duration</i> and <i>Freq1</i> argument values we determined earlier in approach 1.</p><pre class="BScode" xml:space="preserve">' Tenth Second 4.5 kHz Tone Select Case.bs2
|
||||
' {$STAMP BS2}
|
||||
' {$PBASIC 2.5}
|
||||
|
||||
#SELECT $STAMP
|
||||
  #CASE BS2
|
||||
    FREQOUT 6, 100, 4500
|
||||
  #CASE BS2sx
|
||||
    FREQOUT 6, 250, 1800
|
||||
#ENDSELECT
|
||||
|
||||
END</pre>
|
||||
<p class="PlainText">In this second example (below), the <span class="keyword_in_text">*/ </span>operator is used to define constants as multipliers to apply to the <i>Duration</i> and <i>Freq1</i> arguments. These same constant symbols could be applied to any other <span class="keyword_in_text">FREQOUT </span>commands added to the program, regardless of the <![CDATA[ ]]><i>Duration</i> and <i>Freq1</i> arguments used, which could be variables, constants, or even expressions.</p><pre class="BScode" xml:space="preserve">
|
||||
' Tenth Second 4.5 kHz Tone Select Case With Constants.bs2
|
||||
' {$STAMP BS2sx}
|
||||
' {$PBASIC 2.5}
|
||||
|
||||
#SELECT $STAMP
|
||||
#CASE BS2
|
||||
DurFactr CON 256
|
||||
FreqFactr CON 256
|
||||
#CASE BS2sx
|
||||
DurFactr CON 640
|
||||
FreqFactr CON 102
|
||||
#ENDSELECT
|
||||
|
||||
FREQOUT 6, 100*/DurFactr, 4500*/FreqFactr
|
||||
|
||||
END</pre>
|
||||
<p class="PlainText" xml:space="preserve">More example PBASIC programs that demonstrate conditional compilation for time-sensitive commands are included with the BASIC Stamp Editor. Just click File -> Open From -> Default BS2 directory, and select a program with a name like <span class="keyword_in_text">FREQOUT</span>, <span class="keyword_in_text">PULSIN</span>, or any of the other time-sensitive commands listed earlier.
|
||||
</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 © <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>
|
@ -0,0 +1,770 @@
|
||||
<?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>Commands (Alphabetical)</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>
|
||||
<div class="MCBreadcrumbsBox_0"><span class="MCBreadcrumbsPrefix">You are here: </span><span class="MCBreadcrumbs">Commands (Alphabetical)</span>
|
||||
</div>
|
||||
<h1>PBASIC Command Reference</h1>
|
||||
<h2>For all BASIC Stamp models</h2>
|
||||
<p>(Alphabetical Listing)</p>
|
||||
<p> </p>
|
||||
<p>
|
||||
<img src="../../graphics/pgm_icon1.gif" border="0" alt="">
|
||||
</img>
|
||||
<img src="../../graphics/pgm_icon2.gif" border="0" alt="">
|
||||
</img>
|
||||
<img src="../../graphics/pgm_icon2e.gif" border="0" alt="">
|
||||
</img>
|
||||
<img src="../../graphics/pgm_icon2sx.gif" border="0" alt="">
|
||||
</img>
|
||||
<img src="../../graphics/pgm_icon2p.gif" border="0" alt="">
|
||||
</img>
|
||||
<img src="../../graphics/pgm_icon2pe.gif" border="0" alt="">
|
||||
</img>
|
||||
<img src="../../graphics/pgm_icon2px.gif" border="0" alt="">
|
||||
</img>
|
||||
</p>
|
||||
<p> </p>
|
||||
<table width="100%" cellpadding="0" cellspacing="0" border="0">
|
||||
<tr>
|
||||
<td width="25" valign="Top"><sup>2</sup>
|
||||
</td>
|
||||
<td><b>Note</b>: For BS1/BS2-compatible commands, syntax shown below is in BS2
|
||||
format. Some commands may use slightly different formatting with the BS1.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="Top"><sup>2.5</sup>
|
||||
</td>
|
||||
<td><b>Note</b>: Requires <span class="code_in_text">{$PBASIC 2.5}</span> directive.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="Top"><sup>†</sup>
|
||||
</td>
|
||||
<td><b>Note</b>: Compound, multi-line command; syntax not shown.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="Top"><sup>‡</sup>
|
||||
</td>
|
||||
<td><b>Note</b>: Command is accepted by the 24-pin BS2p, BS2pe, and BS2px, but only the 40-pin BS2p40 gives access to the auxiliary I/O pins.</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p> </p>
|
||||
<table cellpadding="4" cellspacing="0" border="0">
|
||||
<tr>
|
||||
<td width="10"> </td>
|
||||
<td width="150">• <a href="../Commands/AUXIO.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">AUXIO</a><sup>‡</sup></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_p_only.gif" />
|
||||
</td>
|
||||
<td width="15"> </td>
|
||||
<td><span class="keyword_in_text">AUXIO</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/BRANCH.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">BRANCH</a><sup>2</sup></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">BRANCH</span><i> Offset,</i> [<i>Address1, Address2, ...AddressN</i>]
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/BUTTON.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">BUTTON</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">BUTTON </span><i>Pin, DownState, Delay, Rate, Workspace, TargetState,
|
||||
Address</i>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/COMPARE.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">COMPARE</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_px.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">COMPARE</span><i> Mode, Result</i>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/CONFIGPIN.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">CONFIGPIN</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_px.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">CONFIGPIN</span><i> Mode, PinMask</i>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/COUNT.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">COUNT</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_2family.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">COUNT</span><i> Pin, Duration, Variable</i>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/DATA.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">DATA</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_2family.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td>{<i>Symbol</i> } <span class="keyword_in_text">DATA </span><i>DataItem</i> {, <i>DataItem,</i> ...}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/DEBUG.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">DEBUG</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">DEBUG</span><i> OutputData</i> {, <i>OutputData</i>}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/DEBUGIN.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">DEBUGIN</a><sup>2.5</sup></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_2family.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">DEBUGIN</span><i> InputData</i>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/DO_LOOP.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">DO…LOOP</a><sup>2.5</sup></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_2family.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">DO</span> {<span class="keyword_in_text">WHILE</span> | <span class="keyword_in_text">UNTIL</span><i>Condition(s)</i> } ...
|
||||
<span class="keyword_in_text">LOOP</span> {<span class="keyword_in_text">UNTIL</span> | <span class="keyword_in_text">WHILE</span><i>Condition(s)</i> }</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/DTMFOUT.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">DTMFOUT</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_2family.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">DTMFOUT</span> Pin, {<i>OnTime, OffTime,</i> } [<i>Tone</i>
|
||||
{<i>, Tone,</i> ...}]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/EEPROM.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">EEPROM</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_1.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">EEPROM</span> {<i>Location</i>,} (<i>DataItem</i> {, <i>DataItem,</i> ...})</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/END.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">END</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">END</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/EXIT.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">EXIT</a><sup>2.5</sup></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_2family.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">EXIT</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/FOR_NEXT.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">FOR…NEXT</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">FOR</span><i> Counter = StartValue </i><span class="keyword_in_text">TO </span> EndValue {<span class="keyword_in_text">STEP </span><i>StepValue</i>} ... <span class="keyword_in_text">NEXT</span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/FREQOUT.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">FREQOUT</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_2family.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">FREQOUT</span><i> Pin, Duration, Freq1</i> {, <i>Freq2</i> }</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/GET.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">GET</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_esxppepx.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">GET</span><i> Location,</i> {Word<sup>2.5</sup>}
|
||||
<i>Variable</i> {, ...} <sup>2.5</sup></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/GOSUB.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">GOSUB</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">GOSUB</span><i> Address</i>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/GOTO.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">GOTO</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">GOTO</span><i> Address</i>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/HIGH.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">HIGH</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">HIGH</span><i> Pin</i>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/I2CIN.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">I2CIN</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_ppepx.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">I2CIN</span><i> Pin, SlaveID,</i> {<i>Address</i> {\<i>LowAddress</i> },}
|
||||
[<i>InputData</i>]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/I2COUT.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">I2COUT</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_ppepx.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">I2COUT</span><i> Pin, SlaveID,</i> {<i>Address</i> {\<i>LowAddress</i>},}
|
||||
[<i>OutputData</i>]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/IF_THEN.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">IF…THEN</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">IF</span> ><i>Condition</i><span class="keyword_in_text"> THEN</span><i> Address</i></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/IF_THEN_ELSE.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">IF…THEN…ELSE</a><sup>2.5, †</sup></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_2family.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/INPUT.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">INPUT</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">INPUT</span><i> Pin</i>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/IOTERM.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">IOTERM</a><sup>‡</sup></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_p_only.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">IOTERM</span><i> Port</i>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/LCDCMD.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">LCDCMD</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_ppepx.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">LCDCMD</span><i> Pin, Command</i>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/LCDIN.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">LCDIN</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_ppepx.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">LCDIN</span><i> Pin, Command, </i>[<i>InputData</i>]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/LCDOUT.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">LCDOUT</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_ppepx.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">LCDOUT</span><i> Pin, Command, </i>[<i>OutputData</i>]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/LET.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">LET</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_1.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td>{<span class="keyword_in_text">LET</span>}<i> Variable</i> = <i>Value</i></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/LOOKDOWN.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">LOOKDOWN</a><sup>2</sup></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">LOOKDOWN</span><i> Target,</i> {<i>ComparisonOp</i> }[<i>Value0, Value1, ...ValueN</i>],<i> Variable</i></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/LOOKUP.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">LOOKUP</a><sup>2</sup></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">LOOKUP</span><i> Index, </i>[<i>Value0, Value1, ...ValueN</i>]<i>, Variable</i></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/LOW.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">LOW</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">LOW</span><i> Pin</i>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/MAINIO.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">MAINIO</a><sup>‡</sup></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_p_only.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">MAINIO</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/NAP.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">NAP</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">NAP</span><i>Duration</i>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/ON_GOSUB.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">ON...GOSUB</a><sup>2.5</sup></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_2family.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">ON</span><i> Offset </i><span class="keyword_in_text"> GOSUB</span><i> Address1, Address2,
|
||||
...AddressN</i>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/ON_GOTO.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">ON...GOTO</a><sup>2.5</sup></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_2family.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">ON</span><i> Offset </i><span class="keyword_in_text">GOTO</span><i> Address1, Address2,
|
||||
...AddressN</i>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/OUTPUT.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">OUTPUT</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">OUTPUT</span><i> Pin</i>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/OWIN.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">OWIN</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_ppepx.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">OWIN</span><i> Pin, Mode,</i> [<i>InputData</i>]
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/OWOUT.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">OWOUT</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_ppepx.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">OWOUT</span><i> Pin, Mode, </i>[<i>OutputData</i>]
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/PAUSE.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">PAUSE</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">PAUSE</span><i> Duration</i>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/POLLIN.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">POLLIN</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_ppepx.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">POLLIN</span><i> Pin, State</i>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/POLLMODE.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">POLLMODE</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_ppepx.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">POLLMODE</span><i> Mode</i>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/POLLOUT.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">POLLOUT</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_ppepx.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">POLLOUT</span><i> Pin, State</i>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/POLLRUN.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">POLLRUN</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_ppepx.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">POLLRUN</span><i> ProgramSlot</i>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/POLLWAIT.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">POLLWAIT</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_ppepx.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">POLLWAIT </span><i>Duration</i>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/POT.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">POT</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_1.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">POT </span><i>Pin, Scale, Variable</i>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/PULSIN.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">PULSIN</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">PULSIN</span><i> Pin, State, Variable</i>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/PULSOUT.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">PULSOUT</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">PULSOUT </span><i>Pin, Duration</i>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/PUT.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">PUT</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_esxppepx.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">PUT</span><i> Location</i>, {Word<sup> 2.5</sup>}
|
||||
<i>Variable</i> {, ...} <sup>2.5</sup></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/PWM.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">PWM</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">PWM </span><i>Pin, Duty, Duration</i>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/RANDOM.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">RANDOM</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">RANDOM</span><i> Variable</i>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/RCTIME.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">RCTIME</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_2family.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">RCTIME</span><i> Pin, State, Variable</i>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/READ.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">READ</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">READ</span><i> Location,</i> {Word<sup> 2.5</sup>}
|
||||
<i>Variable</i> {, ...} <sup>2.5</sup></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/RETURN.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">RETURN</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">RETURN</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/REVERSE.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">REVERSE</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">REVERSE</span><i> Pin</i>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/RUN.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">RUN</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_esxppepx.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">RUN</span><i> ProgramSlot</i>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/SELECT_CASE.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">SELECT...CASE</a><sup>2.5, †</sup></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_2family.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/SERIN.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">SERIN</a><sup>2</sup></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">SERIN</span><i> Rpin</i> {\<i>Fpin</i>}, <i>Baudmode</i>,
|
||||
{<i>Plabel</i>,} {<i>Timeout</i>, <i>Tlabel</i>, } [<i>InputData</i>]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/SEROUT.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">SEROUT</a><sup>2</sup></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">SEROUT</span><i> Tpin</i> {\<i>Fpin</i>}, <i>Baudmode</i>,
|
||||
{<i>Pace</i>,} {<i>Timeout</i>, <i>Tlabel</i>,} [<i>OutputData</i>]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/SHIFTIN.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">SHIFTIN</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_2family.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">SHIFTIN</span><i> Dpin, Cpin, Mode,</i> [<i>Variable</i>{\<i>Bits</i>}
|
||||
{, <i>Variable</i>{\<i>Bits</i>}...}]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/SHIFTOUT.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">SHIFTOUT</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_2family.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">SHIFTOUT</span><i> Dpin, Cpin, Mode,</i> [<i>OutputData</i>{\<i>Bits</i>}
|
||||
{, <i>OutputData</i>{\<i>Bits</i>}...}]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/SLEEP.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">SLEEP</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">SLEEP</span><i> Duration</i>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/SOUND.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">SOUND</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_1.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">SOUND </span><i>Pin</i>, (<i>Note, Duration </i>{, <i>Note, Duration</i>...})</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/STOP.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">STOP</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_2family.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">STOP</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/STORE.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">STORE</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_ppepx.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">STORE </span><i>ProgramSlot</i>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/TOGGLE.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">TOGGLE</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">TOGGLE</span><i> Pin</i>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/WRITE.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">WRITE</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">WRITE</span><i> Location</i>, {Word<sup> 2.5</sup>}
|
||||
<i>Value</i> {, ...} <sup>2.5</sup></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/XOUT.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">XOUT</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_2family.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">XOUT</span><i> Mpin, Zpin,</i> [<i>House</i>\<i>Command</i> {\<i>Cycles</i>}
|
||||
{, <i>House</i>\<i>Command</i> {\<i>Cycles</i>}...}]</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p> </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 © <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>
|
1106
help/BasicStampHelp/Content/LanguageTopics/Reference/Ascii.htm
Normal file
1106
help/BasicStampHelp/Content/LanguageTopics/Reference/Ascii.htm
Normal file
File diff suppressed because it is too large
Load Diff
820
help/BasicStampHelp/Content/LanguageTopics/Reference/CatRef.htm
Normal file
820
help/BasicStampHelp/Content/LanguageTopics/Reference/CatRef.htm
Normal file
@ -0,0 +1,820 @@
|
||||
<?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="PBASIC Language Reference" 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>Commands (By Category)</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>
|
||||
<div class="MCBreadcrumbsBox_0"><span class="MCBreadcrumbsPrefix">You are here: </span><a class="MCBreadcrumbsLink" href="AlphaRef.htm">PBASIC Language Reference</a><span class="MCBreadcrumbsDivider"> > </span><span class="MCBreadcrumbs">Commands (By Category)</span>
|
||||
</div>
|
||||
<h1>PBASIC Command Reference</h1>
|
||||
<h2>For all BASIC Stamp models</h2>
|
||||
<p>(Categorical Listing)</p>
|
||||
<p> </p>
|
||||
<p>
|
||||
<img src="../../graphics/pgm_icon1.gif" border="0" alt="">
|
||||
</img>
|
||||
<img src="../../graphics/pgm_icon2.gif" border="0" alt="">
|
||||
</img>
|
||||
<img src="../../graphics/pgm_icon2e.gif" border="0" alt="">
|
||||
</img>
|
||||
<img src="../../graphics/pgm_icon2sx.gif" border="0" alt="">
|
||||
</img>
|
||||
<img src="../../graphics/pgm_icon2p.gif" border="0" alt="">
|
||||
</img>
|
||||
<img src="../../graphics/pgm_icon2pe.gif" border="0" alt="">
|
||||
</img>
|
||||
<img src="../../graphics/pgm_icon2px.gif" border="0" alt="">
|
||||
</img>
|
||||
</p>
|
||||
<p> </p>
|
||||
<table width="100%" cellpadding="0" cellspacing="0" border="0">
|
||||
<tr>
|
||||
<td width="25" valign="Top"><sup>2</sup>
|
||||
</td>
|
||||
<td><b>Note</b>: For BS1/BS2-compatible commands, syntax shown below is in BS2
|
||||
format. Some commands may use slightly different formatting with the BS1.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="Top"><sup>2.5</sup>
|
||||
</td>
|
||||
<td><b>Note</b>: Requires <span class="code_in_text">{$PBASIC 2.5}</span> directive.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="Top"><sup>†</sup>
|
||||
</td>
|
||||
<td><b>Note</b>: Compound, multi-line command; syntax not shown.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="Top"><sup>‡</sup>
|
||||
</td>
|
||||
<td><b>Note</b>: Command is accepted by the 24-pin BS2p, BS2pe, and BS2px, but only the 40-pin BS2p40 gives access to the auxiliary I/O pins.</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p> </p>
|
||||
<table cellpadding="4" cellspacing="0" border="0">
|
||||
<tr>
|
||||
<td colspan="5"><b>BRANCHING / PROGRAM CONTROL</b>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="10"> </td>
|
||||
<td width="150">• <a href="../Commands/GOTO.htm" class="MCXref_0">GOTO</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td width="15"> </td>
|
||||
<td><span class="keyword_in_text">GOTO</span> <![CDATA[ ]]><i>Address</i></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/IF_THEN.htm" target="" title="" alt="" class="MCXref_0">IF…THEN</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">IF</span> <![CDATA[ ]]><i>Condition</i> <![CDATA[ ]]><span class="keyword_in_text">THEN</span> <![CDATA[ ]]><i>Address</i></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/BRANCH.htm" class="MCXref_0">BRANCH</a> <![CDATA[ ]]><sup>2</sup></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">BRANCH</span> <![CDATA[ ]]><i>Offset, </i>[<i>Address1, Address2, ...AddressN</i>]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/ON_GOTO.htm" target="" title="" alt="" class="MCXref_0">ON...GOTO</a> <![CDATA[ ]]><sup>2.5</sup></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_2family.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">ON</span> <![CDATA[ ]]><i>expression</i> <![CDATA[ ]]><span class="keyword_in_text">GOTO</span> <![CDATA[ ]]><i>Address1, Address2,
|
||||
...AddressN</i></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/GOSUB.htm" class="MCXref_0">GOSUB</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">GOSUB</span> <![CDATA[ ]]><i>Address</i></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/ON_GOSUB.htm" target="" title="" alt="" class="MCXref_0">ON...GOSUB</a> <![CDATA[ ]]><sup>2.5</sup></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_2family.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">ON</span> <![CDATA[ ]]><i>expression</i> <![CDATA[ ]]><span class="keyword_in_text">GOSUB</span> <![CDATA[ ]]><i>Address1, Address2,
|
||||
...AddressN</i></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/RETURN.htm" target="" title="" alt="" class="MCXref_0">RETURN</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">RETURN</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/RUN.htm" target="" title="" alt="" class="MCXref_0">RUN</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_esxppepx.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">RUN</span> <![CDATA[ ]]><i>ProgramSlot</i></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/POLLRUN.htm" target="" title="" alt="" class="MCXref_0">POLLRUN</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_ppepx.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">POLLRUN</span> <![CDATA[ ]]><i>ProgramSlot</i></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/IF_THEN_ELSE.htm" class="MCXref_0">IF…THEN…ELSE</a><sup>2.5, †</sup></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_2family.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/SELECT_CASE.htm" target="" title="" alt="" class="MCXref_0">SELECT...CASE</a> <![CDATA[ ]]><sup>2.5, †</sup></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_2family.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>•<a href="../Commands/STOP.htm" target="" title="" alt="" class="MCXref_0">STOP</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_2family.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">STOP</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="5"> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="5"><b>LOOPING</b>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/DO_LOOP.htm" class="MCXref_0">DO…LOOP</a> <![CDATA[ ]]><sup>2.5</sup></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_2family.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">DO</span> {<span class="keyword_in_text">WHILE</span> | <span class="keyword_in_text">UNTIL</span> <![CDATA[ ]]><i>Condition(s)</i> } ...
|
||||
<span class="keyword_in_text">LOOP</span> {<span class="keyword_in_text">UNTIL</span> | <span class="keyword_in_text">WHILE</span> <![CDATA[ ]]><i>Condition(s)</i> }</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/FOR_NEXT.htm" class="MCXref_0">FOR…NEXT</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">FOR</span> <![CDATA[ ]]><i>Counter = StartValue</i> <![CDATA[ ]]><span class="keyword_in_text">TO</span> EndValue {<span class="keyword_in_text">STEP</span> <![CDATA[ ]]><i>StepValue</i>} ... <span class="keyword_in_text">NEXT</span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/EXIT.htm" class="MCXref_0">EXIT</a> <![CDATA[ ]]><sup>2.5</sup></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_2family.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">EXIT</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="5"> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="5"><b>EEPROM ACCESS</b>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/EEPROM.htm" class="MCXref_0">EEPROM</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_1.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">EEPROM</span> {<i>Location</i>,} (<i>DataItem</i> {, <i>DataItem,</i> ...})</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/DATA.htm" class="MCXref_0">DATA</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_2family.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td>{<i>Symbol</i> } <span class="keyword_in_text">DATA</span> <![CDATA[ ]]><i>DataItem</i> {, <i>DataItem,</i> ...}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/READ.htm" target="" title="" alt="" class="MCXref_0">READ</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">READ</span> <![CDATA[ ]]><i>Location,</i> {Word <![CDATA[ ]]><sup>2.5</sup>}
|
||||
<i>Variable</i> {, ...} <sup>2.5</sup></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/WRITE.htm" target="" title="" alt="" class="MCXref_0">WRITE</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">WRITE</span> <![CDATA[ ]]><i>Location</i>, {Word <![CDATA[ ]]><sup>2.5</sup>}
|
||||
<i>Value</i> {, ...} <sup>2.5</sup></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/STORE.htm" target="" title="" alt="" class="MCXref_0">STORE</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_ppepx.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">STORE</span> <![CDATA[ ]]><i>ProgramSlot</i></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="5"> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="5"><b>RAM ACCESS</b>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/GET.htm" class="MCXref_0">GET</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_esxppepx.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">GET</span> <![CDATA[ ]]><i>Location,</i> {Word <![CDATA[ ]]><sup>2.5</sup>}
|
||||
<i>Variable</i> {, ...} <sup>2.5</sup></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/PUT.htm" target="" title="" alt="" class="MCXref_0">PUT</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_esxppepx.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">PUT</span> <![CDATA[ ]]><i>Location</i>, {Word <![CDATA[ ]]><sup>2.5</sup>}
|
||||
<i>Variable</i> {, ...} <sup>2.5</sup></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="5"> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="5"><b>NUMERICS</b>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/LOOKUP.htm" target="" title="" alt="" class="MCXref_0">LOOKUP</a> <![CDATA[ ]]><sup>2</sup></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">LOOKUP</span> <![CDATA[ ]]><i>Index, </i>[<i>Value0, Value1, ...ValueN</i>],<i> Variable</i></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/LOOKDOWN.htm" target="" title="" alt="" class="MCXref_0">LOOKDOWN</a> <![CDATA[ ]]><sup>2</sup></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">LOOKDOWN</span> <![CDATA[ ]]><i>Target,</i> {<i>ComparisonOp</i> } [<i>Value0, Value1, ...ValueN</i>]<i>, Variable</i></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/RANDOM.htm" target="" title="" alt="" class="MCXref_0">RANDOM</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">RANDOM</span> <![CDATA[ ]]><i>Variable</i></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="5"> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="5"><b>DIGITAL I/O</b>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/CONFIGPIN.htm" class="MCXref_0">CONFIGPIN</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_px.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">CONFIGPIN</span> <![CDATA[ ]]><i>Mode, PinMask</i></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/INPUT.htm" class="MCXref_0">INPUT</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">INPUT</span> <![CDATA[ ]]><i>Pin</i></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/OUTPUT.htm" target="" title="" alt="" class="MCXref_0">OUTPUT</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">OUTPUT</span> <![CDATA[ ]]><i>Pin</i></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/REVERSE.htm" target="" title="" alt="" class="MCXref_0">REVERSE</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">REVERSE</span> <![CDATA[ ]]><i>Pin</i></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/LOW.htm" target="" title="" alt="" class="MCXref_0">LOW</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">LOW</span> <![CDATA[ ]]><i>Pin</i></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/HIGH.htm" class="MCXref_0">HIGH</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">HIGH</span> <![CDATA[ ]]><i>Pin</i></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/TOGGLE.htm" target="" title="" alt="" class="MCXref_0">TOGGLE</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">TOGGLE</span> <![CDATA[ ]]><i>Pin</i></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/PULSIN.htm" target="" title="" alt="" class="MCXref_0">PULSIN</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">PULSIN</span> <![CDATA[ ]]><i>Pin, State, Variable</i></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/PULSOUT.htm" target="" title="" alt="" class="MCXref_0">PULSOUT</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">PULSOUT</span> <![CDATA[ ]]><i>Pin, Duration</i></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/BUTTON.htm" target="" title="" alt="" class="MCXref_0">BUTTON</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">BUTTON</span> <![CDATA[ ]]><i>Pin, DownState, Delay, Rate, Workspace, TargetState,
|
||||
Address</i></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/COUNT.htm" class="MCXref_0">COUNT</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_2family.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">COUNT</span> <![CDATA[ ]]><i>Pin, Duration, Variable</i></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/XOUT.htm" target="" title="" alt="" class="MCXref_0">XOUT</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_2family.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">XOUT</span> <![CDATA[ ]]><i>Mpin, Zpin, </i>[<i>House\Command</i> {\<i>Cycles</i>}
|
||||
{, <i>House</i>\<i>Command</i> {\<i>Cycles</i>}...}]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/AUXIO.htm" class="MCXref_0">AUXIO</a><sup>‡</sup></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_p_only.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">AUXIO</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/MAINIO.htm" target="" title="" alt="" class="MCXref_0">MAINIO</a><sup>‡</sup></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_p_only.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">MAINIO</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/IOTERM.htm" class="MCXref_0">IOTERM</a><sup>‡</sup></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_p_only.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">IOTERM</span> <![CDATA[ ]]><i>Port</i></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/POLLIN.htm" target="" title="" alt="" class="MCXref_0">POLLIN</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_ppepx.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">POLLIN</span> <![CDATA[ ]]><i>Pin, State</i></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/POLLOUT.htm" target="" title="" alt="" class="MCXref_0">POLLOUT</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_ppepx.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">POLLOUT</span> <![CDATA[ ]]><i>Pin, State</i></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/POLLMODE.htm" target="" title="" alt="" class="MCXref_0">POLLMODE</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_ppepx.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">POLLMODE</span> <![CDATA[ ]]><i>Mode</i></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="5"> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="5"><b>ASYNCHRONOUS I/0</b>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/SERIN.htm" target="" title="" alt="" class="MCXref_0">SERIN</a> <![CDATA[ ]]><sup>2</sup></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">SERIN</span> <![CDATA[ ]]><i>Rpin</i> {\<i>Fpin</i>}, <i>Baudmode</i>,
|
||||
{<i>Plabel</i>,} {<i>Timeout</i>, <i>Tlabel</i>, } <i>[InputData]</i></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/SEROUT.htm" target="" title="" alt="" class="MCXref_0">SEROUT</a> <![CDATA[ ]]><sup>2</sup></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">SEROUT</span> <![CDATA[ ]]><i>Tpin</i> {\<i>Fpin</i>}, <i>Baudmode</i>,
|
||||
{<i>Pace</i>,} {<i>Timeout</i>, <i>Tlabel</i>,} [<i>OutputData</i>]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/OWIN.htm" target="" title="" alt="" class="MCXref_0">OWIN</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_ppepx.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">OWIN</span> <![CDATA[ ]]><i>Pin, Mode, </i>[<i>InputData</i>]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/OWOUT.htm" target="" title="" alt="" class="MCXref_0">OWOUT</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_ppepx.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">OWOUT</span> <![CDATA[ ]]><i>Pin, Mode, </i>[<i>OutputData</i>]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="5"> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="5"><b>SYNCHRONOUS SERIAL I/O</b>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/SHIFTIN.htm" target="" title="" alt="" class="MCXref_0">SHIFTIN</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_2family.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">SHIFTIN</span> <![CDATA[ ]]><i>Dpin, Cpin, Mode, [Variable</i>{\<i>Bits</i>}
|
||||
{, <i>Variable</i>{\<i>Bits</i>}...}]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/SHIFTOUT.htm" target="" title="" alt="" class="MCXref_0">SHIFTOUT</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_2family.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">SHIFTOUT</span> <![CDATA[ ]]><i>Dpin, Cpin, Mode, </i>[<i>OutputData</i>{<i>\Bits</i>}
|
||||
{, <i>OutputData</i>{\<i>Bits</i>}...}]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/I2CIN.htm" class="MCXref_0">I2CIN</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_ppepx.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">I2CIN</span> <![CDATA[ ]]><i>Pin, SlaveID,</i> {<i>Address</i>{\<i>LowAddress</i> },}
|
||||
[<i>InputData</i>]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/I2COUT.htm" class="MCXref_0">I2COUT</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_ppepx.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">I2COUT</span> <![CDATA[ ]]><i>Pin, SlaveID,</i> {<i>Address</i>{\<i>LowAddress</i>},}
|
||||
[<i>OutputData</i>]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="5"> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="5"><b>PARALLEL I/O</b>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/LCDCMD.htm" class="MCXref_0">LCDCMD</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_ppepx.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">LCDCMD</span> <![CDATA[ ]]><i>Pin, Command</i></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/LCDIN.htm" class="MCXref_0">LCDIN</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_ppepx.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">LCDIN</span> <![CDATA[ ]]><i>Pin, Command, </i>[<i>InputData</i>]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/LCDOUT.htm" class="MCXref_0">LCDOUT</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_ppepx.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">LCDOUT</span> <![CDATA[ ]]><i>Pin, Command, </i>[<i>OutputData</i>]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="5"> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="5"><b>ANALOG I/O</b>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/COMPARE.htm" class="MCXref_0">COMPARE</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_px.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">COMPARE</span> <![CDATA[ ]]><i>Mode, Result</i></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/POT.htm" target="" title="" alt="" class="MCXref_0">POT</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_1.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">POT</span> <![CDATA[ ]]><i>Pin, Scale, Variable</i></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/PWM.htm" target="" title="" alt="" class="MCXref_0">PWM</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">PWM</span> <![CDATA[ ]]><i>Pin, Duty, Duration</i></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/RCTIME.htm" target="" title="" alt="" class="MCXref_0">RCTIME</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_2family.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">RCTIME</span> <![CDATA[ ]]><i>Pin, State, Variable</i></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="5"> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="5"><b>TIME</b>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/PAUSE.htm" target="" title="" alt="" class="MCXref_0">PAUSE</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">PAUSE</span> <![CDATA[ ]]><i>Duration</i></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/POLLWAIT.htm" target="" title="" alt="" class="MCXref_0">POLLWAIT</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_ppepx.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">POLLWAIT</span> <![CDATA[ ]]><i>Duration</i></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="5"> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="5"><b>SOUND</b>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/SOUND.htm" target="" title="" alt="" class="MCXref_0">SOUND</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_1.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">SOUND</span> <![CDATA[ ]]><i>Pin, </i>(<i>Note, Duration </i>{, <i>Note, Duration</i>...})</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/FREQOUT.htm" class="MCXref_0">FREQOUT</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_2family.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">FREQOUT</span> <![CDATA[ ]]><i>Pin, Duration, Freq1</i> {, <i>Freq2</i> }</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/DTMFOUT.htm" class="MCXref_0">DTMFOUT</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_2family.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">DTMFOUT</span> Pin, {<i>OnTime, OffTime,</i> } [<i>Tone</i>
|
||||
{<i>, Tone,</i> ...}]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="5"> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="5"><b>POWER CONTROL</b>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/NAP.htm" target="" title="" alt="" class="MCXref_0">NAP</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">NAP</span> <![CDATA[ ]]><i>Duration</i></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/SLEEP.htm" target="" title="" alt="" class="MCXref_0">SLEEP</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">SLEEP</span> <![CDATA[ ]]><i>Duration</i></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/END.htm" class="MCXref_0">END</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">END</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="5"> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="5"><b>PROGRAM DEBUGGING</b>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/DEBUG.htm" class="MCXref_0">DEBUG</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">DEBUG</span> <![CDATA[ ]]><i>OutputData</i> {, <i>OutputData</i>} </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="../Commands/DEBUGIN.htm" class="MCXref_0">DEBUGIN</a><sup>2.5</sup></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_2family.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><span class="keyword_in_text">DEBUGIN</span> <![CDATA[ ]]><i>InputData</i></td>
|
||||
</tr>
|
||||
</table>
|
||||
<p> </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 © <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>
|
@ -0,0 +1,141 @@
|
||||
<?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="PBASIC Language Reference" 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> Conditional Compilation</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>
|
||||
<div class="MCBreadcrumbsBox_0"><span class="MCBreadcrumbsPrefix">You are here: </span><a class="MCBreadcrumbsLink" href="AlphaRef.htm">PBASIC Language Reference</a><span class="MCBreadcrumbsDivider"> > </span><span class="MCBreadcrumbs">Conditional Compilation</span>
|
||||
</div>
|
||||
<h1> Conditional Compilation</h1>
|
||||
<div class="ImagePlusCaption">
|
||||
<div class="Col2">
|
||||
<p>
|
||||
<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" /><span class="code_in_text"> {PBASIC 2.5}</span>
|
||||
</p>
|
||||
</div>
|
||||
<p style="text-align: right;"> </p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">In order to facilitate the creation of programs that can be compiled for and
|
||||
downloaded to the connected model of BASIC Stamp2, several conditional compile directives
|
||||
have been added to PBASIC 2.5: <span class="keyword_in_text">#DEFINE</span>, <span class="keyword_in_text">#IF...#THEN...#ELSE</span>, <span class="keyword_in_text">#SELECT...#CASE</span>, and <span class="keyword_in_text">#ERROR</span>. Conditional compile directives are evaluated
|
||||
before the program is compiled, so variables and named constants cannot be
|
||||
referenced within a conditional compilation definition.</p>
|
||||
<h2 class="code"><a name="#DEFINE"></a>#DEFINE</h2>
|
||||
<p class="PlainText">Syntax: <span class="keyword_in_text">#DEFINE</span> <![CDATA[ ]]><i>Symbol {= Value}</i></p>
|
||||
<p class="PlainText"><span class="keyword_in_text">#DEFINE</span> allows the programmer to create custom symbols for use within
|
||||
conditional compilation control structures. </p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Symbol</i></b>  is a string (up to 32 characters).</li>
|
||||
<li value="2"><b><i>Value</i></b>  is an optional constant/expression specifying the value
|
||||
of the defined symbol. If the value parameter is omitted, <i>Symbol</i> is
|
||||
defined as True.</li>
|
||||
</ul>
|
||||
<p>Example:</p><pre class="BScode" xml:space="preserve">#DEFINE DebugMode = 1</pre>
|
||||
<p>In the example above, the "= 1" is optional. Note that when the compiler
|
||||
encounters an undefined symbol it will evaluate that symbol as False (0). You
|
||||
can define a symbol as False by removing the definition with a comment character
|
||||
( ' ) or change its value to zero (recommended)</p>
|
||||
<h2 class="code"><a name="#IF...#T"></a>#IF...#THEN...#ELSE</h2>
|
||||
<p class="PlainText">Syntax: <br /><br />   <span class="keyword_in_text">#IF</span> <![CDATA[ ]]><i>Condition</i> <![CDATA[ ]]><span class="keyword_in_text">#THEN</span><br />     <i>Statement(s)</i><br /> { <span class="keyword_in_text">#ELSE</span><br />     <i>Statement(s)</i> }<br />   <span class="keyword_in_text">#ENDIF</span></p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Evaluate <i>Condition</i> and, if it is True, compile the statement(s) following
|
||||
<span class="keyword_in_text">#THEN</span>, otherwise compile the statements following <span class="keyword_in_text">#ELSE</span>.
|
||||
|
||||
</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Condition</i></b> is a statement, such that can be evaluated as True
|
||||
or False.</li>
|
||||
<li value="2"><b><i>Statement</i></b> is any valid PBASIC statement.</li>
|
||||
</ul>
|
||||
<p class="PlainText">Example:</p><pre class="BScode" xml:space="preserve">
|
||||
' set Baud for 9600-N81
|
||||
|
||||
#IF ($STAMP = BS2sx) OR ($STAMP = BS2p) #THEN
|
||||
 Baud CON 240
|
||||
#ELSE
|
||||
 Baud CON 84
|
||||
#ENDIF
|
||||
</pre>
|
||||
<p class="PlainText">In this example, the constant Baud is set to match the connected BASIC Stamp.
|
||||
This code will work with the BS2, BS2e, BS2sx, BS2p and BS2pe.</p>
|
||||
<h2 class="code"><a name="#SELECT."></a>#SELECT...#CASE</h2>
|
||||
<p class="PlainText">Syntax: <br /><br />   <span class="keyword_in_text">#SELECT</span> <![CDATA[ ]]><i>Expression</i><br />     <span class="keyword_in_text">#CASE</span> <![CDATA[ ]]><i>Condition(s)</i><br />       <i>Statement(s)</i><br />   { <span class="keyword_in_text">#CASE</span> <![CDATA[ ]]><i>Condition(s)</i><br />       <i>Statement(s)</i><br />     <span class="keyword_in_text">#CASE #ELSE</span><br />       <i>Statement(s)</i> }<br />   <span class="keyword_in_text">#ENDSELECT</span></p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Evaluate <i>Expression</i> and then conditionally compile a block of code based
|
||||
on comparison to <i>Condition(s)</i>. If no conditions are found True and a
|
||||
<span class="keyword_in_text">#CASE ELSE</span> block is included, the <span class="keyword_in_text">#CASE #ELSE</span> code statements will
|
||||
compiled. </p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Expression</i></b> is a variable, a constant or an expression.</li>
|
||||
<li value="2"><b><i>Condition</i></b> is a statement, that can be evaluated as True or
|
||||
False. Multiple conditions within the same <span class="keyword_in_text">#CASE</span> can be separated by
|
||||
commas ( , ).</li>
|
||||
<li value="3"><b><i>Statement(s)</i></b> is any valid PBASIC statement or statements.</li>
|
||||
</ul>
|
||||
<p class="PlainText">Example:</p><pre class="BScode" xml:space="preserve">
|
||||
#SELECT $STAMP
|
||||
 #CASE BS2, BS2e, BS2sx
|
||||
   GOSUB LCD_Write
|
||||
 #CASE #ELSE
|
||||
   LCDOUT LCDpin, cmd, [char]
|
||||
#ENDSELECT
|
||||
</pre>
|
||||
<h2 class="code"><a name="#ERROR"></a>#ERROR</h2>
|
||||
<p class="PlainText">Syntax: <span class="keyword_in_text">#ERROR</span> <![CDATA[ ]]><i>Message</i></p>
|
||||
<p class="PlainText"><span class="keyword_in_text">#ERROR</span> allows the programmer to create custom a custom error dialog.</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Message</i></b>  is the error message string.</li>
|
||||
</ul>
|
||||
<p class="PlainText">Example:</p><pre class="BScode" xml:space="preserve">
|
||||
#DEFINE I2CReady = (($STAMP = BS2p) OR ($STAMP = BS2pe))
|
||||
#IF NOT I2CReady #THEN
|
||||
 #ERROR "BS2p or BS2pe is required for this program."
|
||||
#ENDIF
|
||||
</pre>
|
||||
<p class="PlainText">The example above will halt the program and display the dialog below if you
|
||||
attempt to compile the program and run it on a BASIC Stamp other than the BS2p or
|
||||
BS2pe:</p>
|
||||
<img src="../../graphics/error_popup.gif" border="0" alt="" />
|
||||
<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 © <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>
|
@ -0,0 +1,191 @@
|
||||
<?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="PBASIC Language Reference" 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>Constants</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>
|
||||
<div class="MCBreadcrumbsBox_0"><span class="MCBreadcrumbsPrefix">You are here: </span><a class="MCBreadcrumbsLink" href="AlphaRef.htm">PBASIC Language Reference</a><span class="MCBreadcrumbsDivider"> > </span><span class="MCBreadcrumbs">Constants</span>
|
||||
</div>
|
||||
<h1>Constants</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;"> </p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Suppose you’re working on a program called "Three Cheers" that flashes LEDs,
|
||||
makes hooting sounds, and activates a motor that crashes cymbals together, all in
|
||||
sets of three. A portion of your PBASIC program might contain something like:</p>
|
||||
<p>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" border="0" alt="" />
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
FOR counter = 1 TO 3
|
||||
GOSUB Make_Cheers
|
||||
NEXT
|
||||
|
||||
FOR counter = 1 TO 3
|
||||
GOSUB Blink_LEDs
|
||||
NEXT
|
||||
|
||||
FOR counter = 1 TO 3
|
||||
GOSUB Crash_Cymbals
|
||||
NEXT
|
||||
</pre>
|
||||
<p class="PlainText">The numbers 1 and 3 in the code above are called constants. They are constants
|
||||
because, while the program is running, nothing can happen to change those numbers.
|
||||
This distinguishes constants from variables, which can change while the program
|
||||
is running.</p>
|
||||
<p class="PlainText">PBASIC allows you to use several numbering systems. By default, it assumes that
|
||||
numbers are in decimal (base 10), our everyday system of numbers. But you can also
|
||||
use binary and hexadecimal (hex) numbers by identifying them with prefixes. And
|
||||
PBASIC will automatically convert quoted text into the corresponding ASCII code(s).
|
||||
For example:</p>
|
||||
<table cellpadding="0" cellspacing="0" border="0">
|
||||
<tr>
|
||||
<td width="60">99</td>
|
||||
<td>decimal</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>%1010</td>
|
||||
<td>binary</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>$FE</td>
|
||||
<td>hex</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>"A"</td>
|
||||
<td>ASCII code for A (65)</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p> </p>
|
||||
<p class="PlainText">You can assign names to constants in a similar fashion to how variables are
|
||||
declared. On a BS1, it is identical to variable declarations and on the other
|
||||
BASIC Stamp modelss you use the <span class="keyword_in_text">CON</span> directive. Here is the syntax:</p>
|
||||
<p>
|
||||
<img align="absmiddle" src="../../graphics/bs1_inline.gif" border="0" alt="" />
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
SYMBOL Name = ConstantValue
|
||||
</pre>
|
||||
<p>
|
||||
<img align="absmiddle" src="../../graphics/bs2all_inline.gif" border="0" alt="" />
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
Name CON ConstantValue
|
||||
</pre>
|
||||
<p class="PlainText">Once created, named constants may be used in place of the numbers they
|
||||
represent. For example:</p>
|
||||
<p>
|
||||
<img align="absmiddle" src="../../graphics/bs1_inline.gif" border="0" alt="" />
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
SYMBOL Cheers = 3
|
||||
|
||||
SYMBOL idx = B2
|
||||
|
||||
Main:
|
||||
FOR idx = 1 TO Cheers
|
||||
GOSUB Make_Cheers
|
||||
NEXT
|
||||
</pre>
|
||||
<p>
|
||||
<img align="absmiddle" src="../../graphics/bs2all_inline.gif" border="0" alt="" />
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
Cheers CON 3
|
||||
|
||||
idx VAR Nib
|
||||
|
||||
Main:
|
||||
FOR idx = 1 TO Cheers
|
||||
GOSUB Make_Cheers
|
||||
NEXT
|
||||
</pre>
|
||||
<p class="PlainText">That code would work exactly the same as the previous <span class="keyword_in_text">FOR...NEXT</span> loops. The
|
||||
editor software would substitute the number 3 for the constant named Cheers
|
||||
throughout your program. Like variable names, labels and instructions, constant
|
||||
names are not case sensitive; CHEERS, and ChEErs would all be processed as
|
||||
identical to Cheers.</p>
|
||||
<p class="PlainText">Refer to the <a href="ElementsStyle.htm" target="" title="" alt="" class="MCXref_0">Elements of PBASIC Style</a> for
|
||||
suggested guidelines on naming constant values.</p>
|
||||
<p class="PlainText">Using named constants does not increase the amount of code downloaded to the
|
||||
BASIC Stamp, and it often improves the clarity of the program. Weeks after a
|
||||
program is written, you may not remember what a particular number was supposed to
|
||||
represent—using a name may jog your memory (or simplify the detective work needed
|
||||
to figure it out).</p>
|
||||
<p class="PlainText">Named constants also have another benefit. Suppose the "Three Cheers" program
|
||||
had to be upgraded to "Five Cheers." In the original example you would have to
|
||||
change all of the 3s to 5s. Search and replace would help, but you might
|
||||
accidentally change some 3s that weren't numbers of cheers, too. However, if you
|
||||
made smart use of a named constant, all you would have to do is change 3 to 5 in
|
||||
one place, the constant's declaration:</p>
|
||||
<p>
|
||||
<img align="absmiddle" src="../../graphics/bs1_inline.gif" border="0" alt="" />
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
SYMBOL Cheers = 5
|
||||
</pre>
|
||||
<p>
|
||||
<img align="absmiddle" src="../../graphics/bs2all_inline.gif" border="0" alt="" />
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
Cheers CON 5
|
||||
</pre>
|
||||
<p class="PlainText">Now, assuming that you used the constant cheers wherever your program needed
|
||||
'the number of cheers,' your upgrade would be done.</p>
|
||||
<p>
|
||||
<img align="absmiddle" src="../../graphics/bs2all_inline.gif" border="0" alt="" />
|
||||
</p>
|
||||
<p class="PlainText">On the BS2-family you can take this idea a step further by defining constants
|
||||
with expressions; groups of math and/or logic operations that the editor software
|
||||
solves (evaluates) at compile time (the time right after you start the download
|
||||
and before the BASIC Stamp starts running your program). For example, suppose the
|
||||
"Cheers" program also controls a pump to fill glasses with champagne. Perhaps the
|
||||
number of glasses to fill is always twice the number of cheers, minus 1 (another
|
||||
constant):</p><pre class="BScode" xml:space="preserve">
|
||||
Cheers CON 5 ' # of cheers
|
||||
Glasses CON Cheers * 2 - 1 ' # of glasses
|
||||
</pre>
|
||||
<p class="PlainText">As you can see, one constant can be defined in terms of another. That is, the
|
||||
number glasses depends on the number cheers.</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 © <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>
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,128 @@
|
||||
<?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="PBASIC Language Reference" 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>Compiler Directives</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>
|
||||
<div class="MCBreadcrumbsBox_0"><span class="MCBreadcrumbsPrefix">You are here: </span><a class="MCBreadcrumbsLink" href="AlphaRef.htm">PBASIC Language Reference</a><span class="MCBreadcrumbsDivider"> > </span><span class="MCBreadcrumbs">Compiler Directives</span>
|
||||
</div>
|
||||
<h1>Compiler Directives</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;"> </p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p>(Also see <a href="ConditionalCompile.htm" target="" title="" alt="" class="MCXref_0"> Conditional Compilation</a>)</p>
|
||||
<h2>$STAMP</h2>
|
||||
<p class="PlainText">The $STAMP directive is a special command that is included (usually
|
||||
at the top) in a program to indicate the model of BASIC Stamp targeted. Buttons on the editor
|
||||
tool bar simplify adding or modifying the $STAMP directive: </p>
|
||||
<p class="PlainText">
|
||||
<img src="../../Resources/Images/STAMPButtons.png" />
|
||||
</p>
|
||||
<p class="PlainText">The
|
||||
line below is an example of the $STAMP directive (in this case, it indicates that
|
||||
the program is intended for a BASIC Stamp 2):</p><pre>
|
||||
' {$STAMP BS2}
|
||||
</pre>
|
||||
<p class="PlainText">This line should be entered into your code, usually near the top, on a line
|
||||
by itself. Note that the directive appears on a comment line (the apostrophe (')
|
||||
indicates this) for compatibility with the DOS versions of the editor.</p>
|
||||
<p class="PlainText">The 'BS2' in the example above should be changed to indicate the appropriate
|
||||
model of the BASIC Stamp you are using. For example, to use other BASIC Stamp
|
||||
module, enter one (just one) of the following lines into your code:</p><pre>
|
||||
' {$STAMP BS1}
|
||||
' {$STAMP BS2}
|
||||
' {$STAMP BS2e}
|
||||
' {$STAMP BS2sx}
|
||||
' {$STAMP BS2p}
|
||||
' {$STAMP BS2pe}
|
||||
' {$STAMP BS2px}
|
||||
</pre>
|
||||
<p class="PlainText">The directive itself must be enclosed in brackets, {...}. There should not be
|
||||
any spaces between the dollar sign, $, and the word STAMP, however, the directive
|
||||
may contain additional spaces in certain other areas. </p>
|
||||
<p class="PlainText">The $STAMP directive is read and acted upon by the BASIC Stamp Windows Editor
|
||||
any time a source code file is loaded, tokenized, downloaded (run) or viewed in
|
||||
the Memory Map.</p>
|
||||
<h3><a name="Defining"></a>Defining Multi-File Projects</h3>
|
||||
<p class="PlainText">The BS2e, BS2sx, BS2p and BS2pe modules support multi-file projects, which require a modified syntax for the $STAMP directive. A project is a set of up to eight files that
|
||||
should all be downloaded to the BASIC Stamp for a single application. See <a href="MultiFileProjects.htm" target="" title="" alt="" class="MCXref_0">Multi-File Projects</a> for details.</p>
|
||||
<h3>Conditional Compilation</h3>
|
||||
<p class="PlainText">To create source code that is usable on multiple BS2 models, but requires changing as set of constants, symbols, or conditions depending on that model, see <a href="ConditionalCompile.htm" target="" title="" alt="" class="MCXref_0"> Conditional Compilation</a>.</p>
|
||||
<h2>$PBASIC</h2>
|
||||
<p class="PlainText">The $PBASIC directive allows the programmer to specify the syntax level for
|
||||
the compiler to use. Buttons on the editor tool bar simplify adding or
|
||||
modifying the $PBASIC directive:</p>
|
||||
<p class="PlainText">
|
||||
<img src="../../Resources/Images/PBASICButtons.png" />
|
||||
</p>
|
||||
<p class="PlainText">Examples:</p><pre>
|
||||
' {$PBASIC 1.0} ' use version 1.0 syntax (BS1 only)
|
||||
' {$PBASIC 2.0} ' use version 2.0 syntax
|
||||
' {$PBASIC 2.5} ' use version 2.5 syntax
|
||||
</pre>
|
||||
<p class="PlainText">Note that if the $PBASIC directive is omitted, the compiler will assume
|
||||
version 2.0 syntax, unless a $STAMP BS1 directive is present. </p>
|
||||
<h2>$PORT</h2>
|
||||
<p class="PlainText">The purpose of the $PORT directive is to direct a PBASIC program towards a
|
||||
specific serial port. The syntax is as follows:</p><pre>
|
||||
' {$PORT COM#}
|
||||
</pre>
|
||||
<p class="PlainText">...where # is a valid port number. When any PBASIC program containing this
|
||||
directive is downloaded, all other ports will be ignored. This directive is
|
||||
especially important if using two of the same BASIC Stamp models (such as two BS2s)
|
||||
on two COM ports and you have two different PBASIC programs to download (one to
|
||||
each BS2). Without this directive, developing and downloading in this case would
|
||||
be a tedious task of always answering the "which Stamp?" prompt. The Port directive
|
||||
can be automatically inserted or modified by selecting the appropriate port from
|
||||
the Directive -> Port menu. The COM ports listed in the Directive -> Port menu
|
||||
are automatically updated any time a change is made to the exiting computer hardware
|
||||
or to the available ports list (in preferences).</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 © <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>
|
@ -0,0 +1,253 @@
|
||||
<?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="PBASIC Language Reference" 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>Elements of PBASIC Style</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>
|
||||
<div class="MCBreadcrumbsBox_0"><span class="MCBreadcrumbsPrefix">You are here: </span><a class="MCBreadcrumbsLink" href="AlphaRef.htm">PBASIC Language Reference</a><span class="MCBreadcrumbsDivider"> > </span><span class="MCBreadcrumbs">Elements of PBASIC Style</span>
|
||||
</div>
|
||||
<h1>Elements of PBASIC Style</h1>
|
||||
<h2>INTRODUCTION</h2>
|
||||
<p class="PlainText">Like most versions of the BASIC programming language, PBASIC is very forgiving
|
||||
and the compiler enforces no particular formatting style. As long as the source
|
||||
code is syntactically correct, it will compile and download to the BASIC Stamp
|
||||
without trouble.</p>
|
||||
<p class="PlainText">Why, then, would one suggest a specific style for PBASIC? Consider this: Over
|
||||
three million BASIC Stamp modules have been sold and there are several thousand
|
||||
members that participate in the
|
||||
<a href="http://forums.parallax.com/forums/default.aspx" target="_blank" title="Open Parallax Forums in new window" alt="Open Parallax Forums in new window">Parallax online forums</a>.
|
||||
This makes it highly likely that you'll be sharing your PBASIC code
|
||||
with someone, if not co-developing a BASIC Stamp project. Writing code in an
|
||||
organized, predictable manner will save you -- and your potential colleagues --
|
||||
a lot of time; in analysis, in troubleshooting and especially when you return to
|
||||
a project after a long break.</p>
|
||||
<p class="PlainText">The style guidelines presented here are just that: <i>guidelines</i>. They have
|
||||
been developed from style guidelines used by professional programmers using other
|
||||
high-level languages such as Visual Basic<sup>®</sup>, C/C++, and Java™.
|
||||
Use these guidelines as-is, or modify them to suit your individual needs. The key
|
||||
is selecting a style the works well for you or your organization, and then
|
||||
sticking to it.</p>
|
||||
<h2>PBASIC Style Guidelines</h2>
|
||||
<h3>1. Do It Right The First Time</h3>
|
||||
<p class="PlainText">Many programmers, especially new ones, fall into the "<i>I'll knock it out now
|
||||
and fix it later.</i>" trap. Invariably, the "<i>fix it later</i>" part never
|
||||
happens and sloppy code makes its way into production projects. If you don't
|
||||
have time to do it right, when will you find time to do it again?</p>
|
||||
<p class="PlainText">Start clean and you'll be less likely to introduce errors in your code. And
|
||||
if errors do pop up, clean and organized formatting will make them easier to find
|
||||
and fix.</p>
|
||||
<h3>2. Be Organized and Consistent</h3>
|
||||
<p class="PlainText">Using a blank program template will help you organize your programs and establish
|
||||
a consistent presentation.</p>
|
||||
<h3>3. Use Meaningful Names</h3>
|
||||
<p class="PlainText">Be verbose when naming constants, variables and program labels. The compiler will
|
||||
allow names up to 32 characters long. Using meaningful names will reduce the
|
||||
number of comments and make your programs easier to read, debug and maintain.</p>
|
||||
<h3>4. Naming I/O Pins</h3>
|
||||
<p class="PlainText">BASIC Stamp I/O pins are a special case as various elements of the PBASIC language
|
||||
require a pin to be constant value, an input variable or an output variable. To
|
||||
prevent redundant definitions, use the PIN type.</p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0" alt="" /><pre class="BScode" xml:space="preserve">
|
||||
HeaterCtrl PIN 15
|
||||
</pre>
|
||||
<p class="PlainText">Since connections don't change during the program run, I/O pins are named like
|
||||
constants using mixed-case, beginning with an uppercase letter.</p>
|
||||
<h3>5. Naming Constants</h3>
|
||||
<p class="PlainText">Begin constant names with an uppercase letter and use mixed case, using uppercase
|
||||
letters at the beginning of new words within the name.</p>
|
||||
<img src="../../graphics/bs1_inline.gif" border="0" alt="" /><pre class="BScode" xml:space="preserve">
|
||||
SYMBOL AlarmCode = 25
|
||||
</pre>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0" alt="" /><pre class="BScode" xml:space="preserve">
|
||||
AlarmCode CON 25
|
||||
</pre>
|
||||
<h3>6. Naming Variables</h3>
|
||||
<p class="PlainText">Begin variable names with a lowercase letter and use mixed case, using uppercase
|
||||
letters at the beginning of new words within the name.</p>
|
||||
<p class="PlainText">BS1: Avoid using W0 (B0 and B1) so that bit variables (Bit0..Bit15) are
|
||||
available for use in your programs. Bit variables 0..15 overlay W0, so the use
|
||||
of W0 may cause undesired effects.</p>
|
||||
<img src="../../graphics/bs1_inline.gif" border="0" alt="" /><pre class="BScode" xml:space="preserve">
|
||||
SYMBOL waterLevel = W1
|
||||
</pre>
|
||||
<p class="PlainText">BS2: Avoid the use of internal variable names (such as B0 or W1) in your
|
||||
programs. Allow the compiler to automatically assign RAM space by declaring a
|
||||
variable of specific type.</p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0" alt="" /><pre class="BScode" xml:space="preserve">
|
||||
waterLevel VAR Word
|
||||
</pre>
|
||||
<h3>7. Variable Type Declarations</h3>
|
||||
<p class="PlainText">When using the BS1, variable type is declared by aliasing the SYMBOL name to an
|
||||
internal variable of a specific size.</p>
|
||||
<img src="../../graphics/bs1_inline.gif" border="0" alt="" /><pre class="BScode" xml:space="preserve">
|
||||
SYMBOL status = Bit0
|
||||
SYMBOL ovenTmp = B2
|
||||
SYMBOL rndVal = W2
|
||||
</pre>
|
||||
<p class="PlainText">For the BS2, variable types should be in mixed-case and start with an
|
||||
uppercase letter.</p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0" alt="" /><pre class="BScode" xml:space="preserve">
|
||||
status VAR Bit
|
||||
counter VAR Nib
|
||||
ovenTmp VAR Byte
|
||||
rndVal VAR Word
|
||||
</pre>
|
||||
<p class="PlainText">Conserve BASIC Stamp user RAM by declaring the variable type required to hold
|
||||
the expected values of the variable. </p>
|
||||
<img src="../../graphics/bs1_inline.gif" border="0" alt="" /><pre class="BScode" xml:space="preserve">
|
||||
SYMBOL bitVal = BIT0 ' 0 - 1
|
||||
SYMBOL byteVal = B2 ' 0 - 255
|
||||
SYMBOL wordVal = W2 ' 0 - 65535
|
||||
</pre>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0" alt="" /><pre class="BScode" xml:space="preserve">
|
||||
bitValue VAR Bit ' 0 - 1
|
||||
nibValue VAR Nib ' 0 - 15
|
||||
byteValue VAR Byte ' 0 - 255
|
||||
wordValue VAR Word ' 0 - 65535 </pre>
|
||||
<h3>8. Program Labels</h3>
|
||||
<p class="PlainText">Begin program labels with an uppercase letter, used mixed case, separate words
|
||||
within the label with an underscore character and begin new words with a number
|
||||
or uppercase letter. Labels should be preceded by at least one blank line, begin
|
||||
in column 1 and must be terminated with a colon (except after GOTO and THEN
|
||||
[in classic PBASIC] where they appear at the end of the line and without a colon).</p>
|
||||
<img src="../../graphics/bsall_inline.gif" border="0" alt="" /><pre class="BScode" xml:space="preserve">
|
||||
Print_String:
|
||||
READ eeAddr, char
|
||||
IF char = 0 THEN Print_Done
|
||||
DEBUG char
|
||||
eeAddr = eeAddr + 1
|
||||
GOTO Print_String
|
||||
|
||||
Print_Done:
|
||||
RETURN
|
||||
</pre>
|
||||
<h3>9. PBASIC Keywords</h3>
|
||||
<p class="PlainText">All PBASIC language keywords, including SYMBOL, CON, VAR, PIN and serial/debugging
|
||||
format modifiers (DEC, HEX, BIN) and constants (CR, LF) should be uppercase. (Although PBASIC
|
||||
is not case-sensitive, the BASIC Stamp Editor's Syntax Highlighting feature will automatically make
|
||||
these keywords all caps</p>
|
||||
<img src="../../graphics/bsall_inline.gif" border="0" alt="" /><pre class="BScode" xml:space="preserve">
|
||||
Main:
|
||||
DEBUG "BASIC Stamp", CR
|
||||
END
|
||||
</pre>
|
||||
<h3>10. Indent Nested Code</h3>
|
||||
<p class="PlainText">Nesting blocks of code improves readability and helps reduce the introduction of
|
||||
errors. Indenting each level with two spaces is recommended to make the code
|
||||
readable without taking up too much space.</p>
|
||||
<p class="PlainText"><b>Note:</b> <![CDATA[ ]]><i>The dots are used to illustrate the level of nesting and are
|
||||
<b>not</b> a part of the code.</i></p>
|
||||
<img src="../../graphics/bs1_inline.gif" border="0" alt="" /><pre class="BScode" xml:space="preserve">
|
||||
Main:
|
||||
..FOR testLoop = 1 TO 10
|
||||
....IF checkLevel >= Threshold THEN LED_Okay
|
||||
....lowLevel = lowLevel + 1
|
||||
....GOTO Loop_Delay
|
||||
|
||||
LED_Okay:
|
||||
....LEDokay = IsOn
|
||||
|
||||
Loop_Delay:
|
||||
....PAUSE 100
|
||||
..NEXT
|
||||
..IF testMode = Yes THEN Main
|
||||
</pre>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0" alt="" /><pre class="BScode" xml:space="preserve">
|
||||
Main:
|
||||
..DO
|
||||
....FOR testLoop = 1 TO 10
|
||||
......IF (checkLevel < Threshold) THEN
|
||||
........lowLevel = lowLevel + 1
|
||||
......ELSE
|
||||
........LEDokay = IsOn
|
||||
......ENDIF
|
||||
......PAUSE 100
|
||||
....NEXT
|
||||
..LOOP WHILE (testMode = Yes)
|
||||
</pre>
|
||||
<h3>11. Condition Statements</h3>
|
||||
<p class="PlainText">Enclose condition statements in parentheses for clarity (BS2 only - parenthesis
|
||||
are not allowed when using the BS1).</p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0" alt="" /><pre class="BScode" xml:space="preserve">
|
||||
Check_Temp:
|
||||
IF (indoorTemp >= setPoint) THEN
|
||||
AcCtrl = IsOn
|
||||
ELSE
|
||||
lowLevel = lowLevel + 1
|
||||
ENDIF
|
||||
</pre><pre class="BScode" xml:space="preserve">
|
||||
Fill_Water_Tank:
|
||||
DO WHILE (waterLevel = IsLow)
|
||||
TankFill = IsOn
|
||||
PAUSE 250
|
||||
LOOP
|
||||
</pre><pre class="BScode" xml:space="preserve">
|
||||
Get_Delay:
|
||||
DO
|
||||
DEBUG HOME, "Enter time (5 - 30)... ", CLREOL
|
||||
DEBUGIN DEC2 tmDelay
|
||||
LOOP UNTIL ((tmDelay >= 5) AND (tmDelay =< 30))
|
||||
</pre>
|
||||
<h3>12. Be Generous With White Space</h3>
|
||||
<p class="PlainText">White space (spaces and blank lines) does not affect compiler performance or BASIC
|
||||
Stamp execution speed, so be generous with it to make listings easier to read. Allow at least one blank line before program labels (two blanks
|
||||
lines before a subroutine label is recommended). Separate items in a parameter list
|
||||
with a space.</p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0" alt="" /><pre class="BScode" xml:space="preserve">
|
||||
Main:
|
||||
DO
|
||||
ON task GOSUB Update_Motors, Scan_IR, Close_Gripper
|
||||
LOOP
|
||||
|
||||
Update_Motors:
|
||||
PULSOUT MtrLeft, leftSpeed
|
||||
PULSOUT MtrRight, rightSpeed
|
||||
PAUSE 20
|
||||
task = (task + 1) // NumTasks
|
||||
RETURN
|
||||
</pre>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0" alt="" />
|
||||
<p class="PlainText">An exception to this guideline is with the bits parameter used with SHIFTIN
|
||||
and SHIFTOUT, the REP modifier for DEBUG and SEROUT, and the byte count and
|
||||
terminating byte value for SERIN. In these cases, format without spaces.</p><pre class="BScode" xml:space="preserve">
|
||||
SHIFTIN A2Ddata, A2Dclock, MSBPost, [result\9]
|
||||
</pre><pre class="BScode" xml:space="preserve">
|
||||
DEBUG REP "*"\25, CR
|
||||
</pre><pre class="BScode" xml:space="preserve">
|
||||
SERIN IRbSIO, IRbBaud, [buffer\8\255]
|
||||
</pre>
|
||||
<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 © <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>
|
@ -0,0 +1,348 @@
|
||||
<?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="PBASIC Language Reference" 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>Memory Organization </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>
|
||||
<div class="MCBreadcrumbsBox_0"><span class="MCBreadcrumbsPrefix">You are here: </span><a class="MCBreadcrumbsLink" href="AlphaRef.htm">PBASIC Language Reference</a><span class="MCBreadcrumbsDivider"> > </span><span class="MCBreadcrumbs">Memory Organization</span>
|
||||
</div>
|
||||
<h1>Memory Organization </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;"> </p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p>(See also: <a href="Variables.htm" target="" title="" alt="" class="MCXref_0">Variables</a>)</p>
|
||||
<p> </p>
|
||||
<p class="PlainText">The BASIC Stamp has two kinds of memory; RAM (for variables used by your
|
||||
program) and EEPROM (for storing the program itself). EEPROM may also be used to
|
||||
store long-term data in much the same way that desktop computers use a hard drive
|
||||
to hold both programs and files.</p>
|
||||
<p class="PlainText">An important distinction between RAM and EEPROM is this:</p>
|
||||
<ul>
|
||||
<li value="1">RAM loses its contents when the BASIC Stamp loses power; when power returns,
|
||||
all RAM locations are cleared to 0s.</li>
|
||||
<li value="2">EEPROM retains the contents of memory, with or without power, until it is
|
||||
overwritten (such as during the program-downloading process or with a
|
||||
<a href="../Commands/WRITE.htm" target="" title="" alt="" class="MCXref_0">WRITE</a> instruction.)
|
||||
</li>
|
||||
</ul>
|
||||
<h2>
|
||||
<img align="absmiddle" src="../../graphics/bs1_inline.gif" border="0" />  BASIC Stamp 1 RAM Organization</h2>
|
||||
<p class="PlainText">The BS1 has 16 bytes (8 words) of RAM space arranged as shown in the table
|
||||
below. The first word, called PORT, is used for I/O pin control. It consists of
|
||||
two bytes, PINS and DIRS. The bits within PINS correspond to each of the
|
||||
eight I/O pins on the BS1. Reading PINS effectively reads the I/O pins
|
||||
directly, returning an 8-bit set of 1's and 0's corresponding to the high and
|
||||
low state of the respective I/O pin at that moment. Writing to PINS will
|
||||
store a high or low value on the respective I/O pins (though only on pins
|
||||
that are set to outputs).</p>
|
||||
<table align="center" width="60%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF" align="center" valign="top">
|
||||
<td width="20%">Word Name</td>
|
||||
<td width="20%">Byte Names</td>
|
||||
<td width="20%">Bit Name</td>
|
||||
<td width="40%">Special Notes</td>
|
||||
</tr>
|
||||
<tr valign="MIDDLE">
|
||||
<td align="CENTER">PORT</td>
|
||||
<td align="CENTER">PINS<br />DIRS</td>
|
||||
<td align="CENTER">PIN0 - PIN7<br />DIR0 - DIR7</td>
|
||||
<td> I/O pins; bit addressable<br />  I/O pins directions; bit addressable</td>
|
||||
</tr>
|
||||
<tr valign="MIDDLE">
|
||||
<td align="CENTER">W0</td>
|
||||
<td align="CENTER">B0<br />B1</td>
|
||||
<td align="CENTER">BIT0 - BIT7<br />BIT8 - BIT15</td>
|
||||
<td> Bit addressable<br /> Bit addressable</td>
|
||||
</tr>
|
||||
<tr valign="MIDDLE">
|
||||
<td align="CENTER">W1</td>
|
||||
<td align="CENTER">B2<br />B3</td>
|
||||
<td align="CENTER"> </td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr valign="MIDDLE">
|
||||
<td align="CENTER">W2</td>
|
||||
<td align="CENTER">B4<br />B5</td>
|
||||
<td align="CENTER"> </td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr valign="MIDDLE">
|
||||
<td align="CENTER">W3</td>
|
||||
<td align="CENTER">B6<br />B7</td>
|
||||
<td align="CENTER"> </td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr valign="MIDDLE">
|
||||
<td align="CENTER">W4</td>
|
||||
<td align="CENTER">B8<br />B9</td>
|
||||
<td align="CENTER"> </td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr valign="MIDDLE">
|
||||
<td align="CENTER">W5</td>
|
||||
<td align="CENTER">B10<br />B11</td>
|
||||
<td align="CENTER"> </td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr valign="MIDDLE">
|
||||
<td align="CENTER">W6</td>
|
||||
<td align="CENTER">B12<br />B13</td>
|
||||
<td align="CENTER"> </td>
|
||||
<td> Used by <span class="keyword_in_text">GOSUB </span>instruction<br /> Used by <span class="keyword_in_text">GOSUB </span>instruction</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p> </p>
|
||||
<p class="PlainText">The second byte of PORT, DIRS, controls the direction of the I/O pins. Each
|
||||
bit within DIRS corresponds to an I/O pin's direction. A high bit (1) sets the
|
||||
corresponding I/O pin to an output direction and a low bit (0) sets the
|
||||
corresponding I/O pin to an input direction.</p>
|
||||
<p class="PlainText">The remaining words (W0 – W6) are available for general-purpose use. Each word
|
||||
consists of separately addressable bytes and the first two bytes (B0 and B1) are
|
||||
bit addressable as well. You may assign other names (symbols) to these RAM registers
|
||||
as shown in section "Defining and Using Variables", below.</p>
|
||||
<p class="PlainText">When the BS1 is powered up, or reset, all memory locations are cleared to 0,
|
||||
so all pins are inputs (DIRS = %00000000). Also, if the PBASIC program sets all
|
||||
the I/O pins to outputs (DIRS = %11111111), then they will initially output low,
|
||||
since the output latch (PINS) is cleared to all zeros upon power-up or reset, as
|
||||
well.</p>
|
||||
<h2>
|
||||
<img align="absmiddle" src="../../graphics/bs2all_inline.gif" border="0" />  BASIC Stamp 2 Series RAM Organization</h2>
|
||||
<p class="PlainText">The BS2, BS2e, BS2sx, BS2p, BS2pe, and BS2px have 32 bytes of Variable RAM space arranged as
|
||||
shown in the table below. Of these, the first six bytes are reserved for input,
|
||||
output, and direction control of the I/O pins. The remaining 26 bytes are available
|
||||
for general-purpose use as variables.</p>
|
||||
<p class="PlainText"><b>Note</b>: There are 16 words, consisting of two bytes each for a total
|
||||
of 32 bytes. All bits are individually addressable through modifiers and the bits
|
||||
within the upper three words are also individually addressable through the
|
||||
pre-defined names shown.</p>
|
||||
<table align="center" width="80%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF" align="center" valign="top">
|
||||
<td width="15%">Word Name</td>
|
||||
<td width="15%">Byte Names</td>
|
||||
<td width="15%">Nibble Names</td>
|
||||
<td width="15%">Bit Name</td>
|
||||
<td width="40%">Special Notes</td>
|
||||
</tr>
|
||||
<tr valign="MIDDLE">
|
||||
<td align="CENTER">INS</td>
|
||||
<td align="CENTER">INL<br />INH</td>
|
||||
<td align="CENTER">INA, INB<br />INC, IND</td>
|
||||
<td align="CENTER">IN0 - IN7<br />IN8 - IN15</td>
|
||||
<td> Input pins</td>
|
||||
</tr>
|
||||
<tr valign="MIDDLE">
|
||||
<td align="CENTER">OUTS</td>
|
||||
<td align="CENTER">OUTL<br />OUTH</td>
|
||||
<td align="CENTER">OUTA, OUTB<br />OUTC, OUTD</td>
|
||||
<td align="CENTER">OUT0 - OUT7<br />OUT8 - OUT15</td>
|
||||
<td> Output pins</td>
|
||||
</tr>
|
||||
<tr valign="MIDDLE">
|
||||
<td align="CENTER">DIRS</td>
|
||||
<td align="CENTER">DIRL<br />DIRH</td>
|
||||
<td align="CENTER">DIRA, DIRB<br />DIRC, DIRD</td>
|
||||
<td align="CENTER">DIR0 - DIR7<br />DIR8 - DIR15</td>
|
||||
<td> I/O pin direction control</td>
|
||||
</tr>
|
||||
<tr valign="MIDDLE">
|
||||
<td align="CENTER">W0</td>
|
||||
<td align="CENTER">B0<br />B1</td>
|
||||
<td> </td>
|
||||
<td> </td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr valign="MIDDLE">
|
||||
<td align="CENTER">W1</td>
|
||||
<td align="CENTER">B2<br />B3</td>
|
||||
<td> </td>
|
||||
<td> </td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr valign="MIDDLE">
|
||||
<td align="CENTER">W2</td>
|
||||
<td align="CENTER">B4<br />B5</td>
|
||||
<td> </td>
|
||||
<td> </td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr valign="MIDDLE">
|
||||
<td align="CENTER">W3</td>
|
||||
<td align="CENTER">B6<br />B7</td>
|
||||
<td> </td>
|
||||
<td> </td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr valign="MIDDLE">
|
||||
<td align="CENTER">W4</td>
|
||||
<td align="CENTER">B8<br />B9</td>
|
||||
<td> </td>
|
||||
<td> </td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr valign="MIDDLE">
|
||||
<td align="CENTER">W5</td>
|
||||
<td align="CENTER">B10<br />B11</td>
|
||||
<td> </td>
|
||||
<td> </td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr valign="MIDDLE">
|
||||
<td align="CENTER">W6</td>
|
||||
<td align="CENTER">B12<br />B13</td>
|
||||
<td> </td>
|
||||
<td> </td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr valign="MIDDLE">
|
||||
<td align="CENTER">W7</td>
|
||||
<td align="CENTER">B14<br />B15</td>
|
||||
<td> </td>
|
||||
<td> </td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr valign="MIDDLE">
|
||||
<td align="CENTER">W8</td>
|
||||
<td align="CENTER">B16<br />B17</td>
|
||||
<td> </td>
|
||||
<td> </td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr valign="MIDDLE">
|
||||
<td align="CENTER">W9</td>
|
||||
<td align="CENTER">B18<br />B19</td>
|
||||
<td> </td>
|
||||
<td> </td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr valign="MIDDLE">
|
||||
<td align="CENTER">W10</td>
|
||||
<td align="CENTER">B20<br />B21</td>
|
||||
<td> </td>
|
||||
<td> </td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr valign="MIDDLE">
|
||||
<td align="CENTER">W11</td>
|
||||
<td align="CENTER">B22<br />B23</td>
|
||||
<td> </td>
|
||||
<td> </td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr valign="MIDDLE">
|
||||
<td align="CENTER">W12</td>
|
||||
<td align="CENTER">B24<br />B25</td>
|
||||
<td> </td>
|
||||
<td> </td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
</table>
|
||||
<p> </p>
|
||||
<p class="PlainText">The INS variable always shows the state of the I/O pins themselves, regardless
|
||||
of the direction of each I/O pin. We call this, "reading the pins." If a pin was
|
||||
set to an input mode (within DIRS) and an external circuit connected the I/O pin
|
||||
to ground, the corresponding bit of INS would be zero. If a pin was set to be an
|
||||
output and the pin's state was set to a high level (within OUTS), the corresponding
|
||||
bit of INS would be high. If, however, that same pin was externally connected
|
||||
directly to ground, the corresponding bit of INS would be low; since we're reading
|
||||
the state of the pin itself and the BASIC Stamp cannot override a pin that is
|
||||
driven to ground or 5 volts externally. Note: The final example is an error; it
|
||||
will cause a direct short and can cause damage to the BASIC Stamp! Do not
|
||||
intentionally connect output pins directly to Vss (Ground) or Vdd (positive supply)
|
||||
or you risk destroying your BASIC Stamp module.</p>
|
||||
<p class="PlainText">To summarize: DIRS determines whether a pin's state is set by external
|
||||
circuitry (input, 0) or by the state of OUTS (output, 1). INS always matches the
|
||||
actual states of the I/O pins, whether they are inputs or outputs. OUTS holds bits
|
||||
that will only appear on pins whose DIRS bits are set to output.</p>
|
||||
<p class="PlainText">In programming the BASIC Stamp, it's often more convenient to deal with
|
||||
individual bytes, nibbles or bits of INS, OUTS and DIRS rather than the entire
|
||||
16-bit words. PBASIC has built-in names for these elements, shown in table above.</p>
|
||||
<p class="PlainText">Here's an example of what is described in the table above. The INS register is
|
||||
16-bits (corresponding to I/O pins 0 through 15). The INS register consists of
|
||||
two bytes, called INL (the Low byte) and INH (the High byte). INL corresponds to
|
||||
I/O pins 0 through 7 and INH corresponds to I/O pins 8 through 15. INS can also be
|
||||
thought of as containing four nibbles, INA, INB, INC and IND. INA is I/O pins 0
|
||||
through 3, INB is I/O pins 4 through 7, etc. In addition, each of the bits of INS
|
||||
can be accessed directly using the names IN0, IN1, IN2... IN15.</p>
|
||||
<p class="PlainText">The same naming scheme holds true for the OUTS and DIRS variables as well.</p>
|
||||
<p class="PlainText">As the table shows, the BASIC Stamp's memory is organized into 16 words of 16
|
||||
bits each. The first three words are used for I/O. The remaining 13 words are
|
||||
available for use as general-purpose variables.</p>
|
||||
<p class="PlainText">Just like the I/O variables, the general-purpose variables have predefined
|
||||
names: W0 through W12 and B0 through B25. B0 is the low byte of W0; B1 is the high
|
||||
byte of W0; and so on through W12 (B24=low byte, B25=high byte). Unlike I/O
|
||||
variables, there's no reason that your program variables have to be stuck in a
|
||||
specific position in the BASIC Stamp's physical memory. A byte is a byte regardless
|
||||
of its location. And if a program uses a mixture of variables of different sizes,
|
||||
it can be a pain in the neck to logically dole them out or allocate storage.</p>
|
||||
<p class="PlainText">More importantly, <b>mixing fixed variables with automatically allocated
|
||||
variables is an invitation to bugs.</b> A
|
||||
fixed variable can overlap an allocated variable, causing data meant for one
|
||||
variable to show up in another! The fixed variable names (of the general-purpose
|
||||
variables) are only provided for power users who require absolute access to a
|
||||
specific location in RAM.</p>
|
||||
<p class="PlainText">We recommend that you avoid using the fixed variables in most situations.
|
||||
Instead, let PBASIC allocate variables as described in the next section. The
|
||||
editor software will organize your storage requirements to make optimal use of
|
||||
the available memory.</p>
|
||||
<h2>
|
||||
<img align="absmiddle" src="../../graphics/bsesxppepx_inline.gif" border="0">
|
||||
</img>  Scratch Pad RAM </h2>
|
||||
<p class="PlainText">The BS2e, BS2sx, BS2p, BS2pe, and BS2px have some additional RAM called
|
||||
Scratch Pad RAM. The BS2e and BS2sx have are 64 bytes of Scratch Pad RAM (0 – 63),
|
||||
and the BS2p, BS2pe, and BS2px have 128 bytes of Scratch Pad RAM (0 – 127).
|
||||
Scratch Pad RAM can only be accessed with the <span class="keyword_in_text">GET</span> and<span class="keyword_in_text"> PUT</span> commands (see the
|
||||
<a href="../Commands/GET.htm" target="" title="" alt="" class="MCXref_0">GET</a> and <a href="../Commands/PUT.htm" target="" title="" alt="" class="MCXref_0">PUT</a> command descriptions
|
||||
for more information) and cannot have variable names assigned to it.</p>
|
||||
<p class="PlainText">The highest location in Scratch Pad RAM (location 63 on the BS2e and BS2sx,
|
||||
location 127 on the BS2p, BS2pe, and BS2px) is read-only, and always contains
|
||||
the number of the currently running program slot. This can be handy for programs
|
||||
that need to know which program slot they exist in.</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 © <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>
|
@ -0,0 +1,92 @@
|
||||
<?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="PBASIC Language Reference" 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>Multi-File Projects</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>
|
||||
<div class="MCBreadcrumbsBox_0"><span class="MCBreadcrumbsPrefix">You are here: </span><a class="MCBreadcrumbsLink" href="AlphaRef.htm">PBASIC Language Reference</a><span class="MCBreadcrumbsDivider"> > </span><span class="MCBreadcrumbs">Multi-File Projects</span>
|
||||
</div>
|
||||
<h1>Multi-File Projects</h1>
|
||||
<div class="ImagePlusCaption">
|
||||
<div class="Col2">
|
||||
<p>
|
||||
<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;"> </p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText"><a name="Defining"></a>For BS2e, BS2sx, BS2p, BS2pe, and BS2px programs, each editor page can be a separate
|
||||
project, or part of a single project. A project is a set of up to eight files that
|
||||
should all be downloaded to the BASIC Stamp for a single application. Each of the
|
||||
files within the project is downloaded into a separate "program slot". Only the
|
||||
BASIC Stamp 2e, 2sx, 2p, 2pe, and 2px modules support multi-file projects.</p>
|
||||
<h2>$STAMP Directive for a Multi-File Project</h2>
|
||||
<p class="PlainText">For BASIC Stamp projects (consisting of multiple programs), the $STAMP directive
|
||||
has an option to specify additional filenames. The syntax below demonstrates this
|
||||
form of the $STAMP directive:</p><pre>
|
||||
' {$STAMP BS2e, file2, file3, ..., file8}
|
||||
</pre>
|
||||
<p class="PlainText">Use this form of the $STAMP directive if a project, consisting of multiple files, is desired. This form of the directive must be entered only into the first program (to be downloaded into program slot 0). The file2, file3, etc. items should be the actual name (and optionally the path) of the other files in the project. File2 refers to the program that should be downloaded into program slot 1, file3 is the program that should be downloaded into program slot 2, etc. If no path is given, the filename is given the path of program 0 when loading them into the editor.</p>
|
||||
<p class="PlainText">Up to seven filenames can be included, bringing the total to eight files in the project all together. Upon loading, tokenizing, running or viewing program 0 in the Memory Map, the editor will read the $STAMP directive, determine if the indicated files exist, will load them if necessary and change their captions to indicate the project they belong to and their associated program number. After the directive is tokenized properly, and all associated files are labeled properly, tokenizing, running or viewing any program in the Memory Map will result in that program’s entire project being tokenized, downloaded or viewed.</p>
|
||||
<p class="PlainText">When program #0 of a multi-file project is opened from diskette, the entire project will be loaded (all referenced files) as well. When a file that is part of a multi-file project is closed, the entire project (all the associated files) will be closed as well.</p>
|
||||
<h2>Creating a Multi-File Project</h2>
|
||||
<p class="PlainText">To create a project consisting of multiple files, follow these steps:</p>
|
||||
<ol>
|
||||
<li value="1">Create the first file in the editor and save it (we'll call it Sample.bsx). This will be the program that is downloaded into program slot 0.</li>
|
||||
<li value="2">Create at least one other file in the editor and save it also (we'll call it NextProgram.bsx).</li>
|
||||
</ol>
|
||||
<p class="PlainTextIndent">Note: At this point the editor tabs will be:</p>
|
||||
<p class="PlainTextIndent">0:Sample.bsx and 0:NextProgram.bsx.</p>
|
||||
<p class="PlainTextIndent">...indicating that there are two unrelated files open "Sample.bsx" and "NextProgram.bsx" and each will be downloaded into program slot 0.</p>
|
||||
<ol MadCap:continue="true">
|
||||
<li value="3">Go back to the first program and enter or modify the $STAMP directive using the project format. Use "NextProgram" as the File2 argument. For example:</li>
|
||||
</ol>
|
||||
<p class="PlainTextIndent">' {$STAMP BS2sx, NextProgram.bsx}</p>
|
||||
<ol MadCap:continue="true">
|
||||
<li value="4">Then tokenize the code by pressing F7 or selecting Run → Check Syntax from the menu.</li>
|
||||
</ol>
|
||||
<p class="PlainText">At this point, the BASIC Stamp Editor will see the $STAMP directive and realize that this file (Sample.bsx) is the first file in a project and that the second file should be NextProgram.bsx. It will then search for the file on the hard drive (to verify its path is correct), will see that it is already loaded, and then will change the editor tabs to indicate the project relationship. At this point the editor tabs will be:</p>
|
||||
<p class="PlainTextIndent">0:Sample.bsx and [Sample] 1:NextProgram.bsx.</p>
|
||||
<p class="PlainText">...indicating that there are two related files open; "Sample.bsx" and "NextProgram.bsx". NextProgram.bsx belongs to the "Sample" project and it will be downloaded into program slot 1 and Sample.bsx will be downloaded into program slot 0.</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 © <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>
|
@ -0,0 +1,403 @@
|
||||
<?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="PBASIC Language Reference" 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>PBASIC Operators</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>
|
||||
<div class="MCBreadcrumbsBox_0"><span class="MCBreadcrumbsPrefix">You are here: </span><a class="MCBreadcrumbsLink" href="AlphaRef.htm">PBASIC Language Reference</a><span class="MCBreadcrumbsDivider"> > </span><span class="MCBreadcrumbs">PBASIC Operators</span>
|
||||
</div>
|
||||
<h1>PBASIC Operators</h1>
|
||||
<p>
|
||||
<img src="../../graphics/pgm_icon1.gif" border="0" alt="" />
|
||||
<img src="../../graphics/pgm_icon2.gif" border="0" alt="" />
|
||||
<img src="../../graphics/pgm_icon2e.gif" border="0" alt="" />
|
||||
<img src="../../graphics/pgm_icon2sx.gif" border="0" alt="" />
|
||||
<img src="../../graphics/pgm_icon2p.gif" border="0" alt="" />
|
||||
<img src="../../graphics/pgm_icon2pe.gif" border="0" alt="" />
|
||||
<img src="../../graphics/pgm_icon2px.gif" border="0" alt="" />
|
||||
</p>
|
||||
<p> </p>
|
||||
<p class="PlainText">(See <a href="OpsPrecedence.htm" target="" title="" alt="" class="MCXref_0">Operator Precedence</a> for details of the sequence in which expression operators are evaluated.)</p>
|
||||
<h2>Binary and Unary Operators</h2>
|
||||
<p class="PlainText">There are two types of operators in PBASIC, binary operators which require two arguments (such as the addition operator in 2 + 3) and unary operators which require one argument (such as the negate operator in -5). All the PBASIC operators are shown below, grouped under binary operators or unary operators. Click on any operator to see a full description on the Binary Operator or Unary Operator page.</p>
|
||||
<h2>Notes about the 16-bit workspace</h2>
|
||||
<p class="PlainText">Many of the operator descriptions will say something like "computes (some function) of a 16-bit number." This does not mean that the operator does not work on smaller byte or nibble values, but rather that the computation is done in a 16-bit workspace. If the value is smaller than 16 bits, the BASIC Stamp pads it with leading 0s to make a 16-bit value. If the 16-bit result of a calculation is to be packed into a smaller variable, the higher-order bits are discarded (truncated).</p>
|
||||
<table cellpadding="4" cellspacing="0" border="0">
|
||||
<tr>
|
||||
<td colspan="5"><a href="Ops_bi.htm" target="" title="" alt="" class="MCXref_0">Binary Operators</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="10"> </td>
|
||||
<td width="55">• <a href="Ops_bi.htm#addition">+</a></td>
|
||||
<td width="90" align="absmiddle">
|
||||
<img src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td width="15"> </td>
|
||||
<td><a href="Ops_bi.htm#addition">Addition</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="Ops_bi.htm#subtraction">-</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><a href="Ops_bi.htm#subtraction">Subtraction</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="Ops_bi.htm#multiply">*</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><a href="Ops_bi.htm#multiply">Multiplication</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="Ops_bi.htm#multi-high">**</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><a href="Ops_bi.htm#multi-high">Multiply High (Return Upper 16 Bits)</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="Ops_bi.htm#multi-mid">*/</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_2family.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><a href="Ops_bi.htm#multi-mid">Multiply Middle (Return Middle 16 Bits)</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="Ops_bi.htm#divide">/</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><a href="Ops_bi.htm#divide">Division</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="Ops_bi.htm#modulus">//</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><a href="Ops_bi.htm#modulus">Modulus (Remainder of Division)</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="Ops_bi.htm#limit-min">MIN</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><a href="Ops_bi.htm#limit-min">Limit a Value to Specified Low</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="Ops_bi.htm#limit-max">MAX</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><a href="Ops_bi.htm#limit-max">Limit a Value to Specified High</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="Ops_bi.htm#digit">DIG</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_2family.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><a href="Ops_bi.htm#digit">Return Specified Digit of Number</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="Ops_bi.htm#reverse">REV</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_2family.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><a href="Ops_bi.htm#reverse">Reverse Specified Number of Bits</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="Ops_bi.htm#shfitleft"><<</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_2family.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><a href="Ops_bi.htm#shfitleft">Shift Bits Left by Specified Amount</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="Ops_bi.htm#shiftright">>></a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_2family.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><a href="Ops_bi.htm#shiftright">Shift Bits Right by Specified Amount</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="Ops_bi.htm#bitwiseand">&</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><a href="Ops_bi.htm#bitwiseand">Bitwise AND</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="Ops_bi.htm#bitwiseor">|</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><a href="Ops_bi.htm#bitwiseor">Bitwise OR</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="Ops_bi.htm#bitwisexor">^</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><a href="Ops_bi.htm#bitwisexor">Bitwise XOR</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="Ops_bi.htm#andnot">&/</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_1.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><a href="Ops_bi.htm#andnot">Bitwise AND NOT</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="Ops_bi.htm#ornot">|/</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_1.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><a href="Ops_bi.htm#ornot">Bitwise OR NOT</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="Ops_bi.htm#xornot">^/</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_1.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><a href="Ops_bi.htm#xornot">Bitwise XOR NOT</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="Ops_bi.htm#and">AND</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><a href="Ops_bi.htm#and">Logical AND</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="Ops_bi.htm#or">OR</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><a href="Ops_bi.htm#or">Logical OR</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="Ops_bi.htm#xor">XOR</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><a href="Ops_bi.htm#xor">Logical XOR</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="Ops_bi.htm#arctan">ATN</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_2family.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><a href="Ops_bi.htm#arctan">Return Arctangent of Vector</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="Ops_bi.htm#hypot">HYP</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_2family.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><a href="Ops_bi.htm#hypot">Return Hypotenuse</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="5"> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="5"><a href="Ops_uni.htm" target="" title="" alt="" class="MCXref_0">Unary Operators</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="Ops_uni.htm#absval">ABS</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_2family.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><a href="Ops_uni.htm#absval">Return Absolute Value</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="Ops_uni.htm#negative">-</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_all.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><a href="Ops_uni.htm#negative">Negate</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="Ops_uni.htm#invert">~</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_2family.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><a href="Ops_uni.htm#invert">Bitwise Inverse</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="Ops_uni.htm#dcd">DCD</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_2family.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><a href="Ops_uni.htm#dcd">2<sup>n</sup>-power Decoder</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="Ops_uni.htm#ncd">NCD</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_2family.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><a href="Ops_uni.htm#ncd">Priority Encoder of 16-bit Value</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="Ops_uni.htm#sine">SIN</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_2family.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><a href="Ops_uni.htm#sine">Return (signed) Sine Value of Angle</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="Ops_uni.htm#cosine">COS</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_2family.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><a href="Ops_uni.htm#cosine">Return (signed) Cosine Value of Angle</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="Ops_uni.htm#square">SQR</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_2family.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><a href="Ops_uni.htm#square">Return Square Root of value</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>• <a href="Ops_uni.htm#not">NOT</a></td>
|
||||
<td>
|
||||
<img align="absmiddle" src="../../graphics/stamp_2family.gif" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td><a href="Ops_uni.htm#not">Logical NOT</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p> </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 © <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>
|
@ -0,0 +1,105 @@
|
||||
<?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="PBASIC Language Reference|PBASIC Operators" 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>Operator Precedence</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>
|
||||
<div class="MCBreadcrumbsBox_0"><span class="MCBreadcrumbsPrefix">You are here: </span><a class="MCBreadcrumbsLink" href="AlphaRef.htm">PBASIC Language Reference</a><span class="MCBreadcrumbsDivider"> > </span><a class="MCBreadcrumbsLink" href="Operators.htm">PBASIC Operators</a><span class="MCBreadcrumbsDivider"> > </span><span class="MCBreadcrumbs">Operator Precedence</span>
|
||||
</div>
|
||||
<h1>Operator Precedence</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;"> </p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p>(See <a href="Operators.htm" target="" title="" alt="" class="MCXref_0">PBASIC Operators</a> for a complete list of all PBASIC operators, with links to explanations of each.)</p>
|
||||
<p> </p>
|
||||
<h2>Left-to-Right Evaluation</h2>
|
||||
<p class="PlainText">The BASIC Stamp solves math problems in the order they are written;
|
||||
from left to right. The result of each operation is fed into the next
|
||||
operation. So to compute:</p>
|
||||
<p>    12 + 3 * 2 / 4</p>
|
||||
<p> </p>
|
||||
<p class="PlainText">...the BASIC Stamp goes through a
|
||||
sequence like this:</p>
|
||||
<p>    12 + 3 = 15<br></br>    15 * 2 = 30<br></br>    30 / 4 = 7</p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Note that since the BASIC Stamp performs integer math (whole numbers
|
||||
only) 30 / 4 results in 7, not 7.5. </p>
|
||||
<p class="PlainText">Some other dialects of BASIC would compute that same expression based
|
||||
on their precedence of operators, which requires that multiplication and
|
||||
division be done before addition. So the result would be:</p>
|
||||
<p>    3 * 2 = 6<br></br>    6 / 4 = 1<br></br>    12 + 1 = 13</p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Once again, because of integer math, the fractional portion of 6 / 4 is
|
||||
dropped, so we get 1 instead of 1.5.</p>
|
||||
<p class="PlainText">Unary operators (those with one argument) take precedence over binary operators (those with two arguments); the unary operation is always performed first. For example, on all BS2 models, SQR is the unary operator for square root. In the expression:</p>
|
||||
<p class="PlainText">10 - SQR 16</p>
|
||||
<p class="PlainText">...the BASIC Stamp first takes the square root of 16, then subtracts it from 10.</p>
|
||||
<h2>Using Parentheses </h2>
|
||||
<img src="../../graphics/bs1_inline.gif" border="0" alt="">
|
||||
</img>
|
||||
<p class="PlainText">The BS1 does not allow parentheses in expressions. Unfortunately, all
|
||||
expressions have to be written so that they evaluate as intended strictly
|
||||
from left to right. The negative operator is the only unary operator for the BS1.</p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0" alt="">
|
||||
</img>
|
||||
<p class="PlainText">The BS2 family modules, however, allow parentheses to be
|
||||
used to change the order of evaluation. Enclosing a math operation in
|
||||
parentheses gives it priority over other operations. To make the BASIC Stamp
|
||||
compute the previous expression in the conventional way, you would write it
|
||||
as 12 + (3 * 2 / 4). Within the parentheses, the BASIC Stamp works from left
|
||||
to right. If you wanted to be even more specific, you could write 12 +
|
||||
((3 * 2) / 4). When there are parentheses within parentheses, the BASIC
|
||||
Stamp works from the innermost parentheses outward. Parentheses
|
||||
placed within parentheses are called nested parentheses.</p>
|
||||
<h2>Integer Math</h2>
|
||||
<p class="PlainText">The BASIC Stamp performs all math operations by the rules of positive integer math. That is, it handles only whole numbers, and drops any fractional portions from the results of computations. The BASIC Stamp handles negative numbers using two's complement rules. </p>
|
||||
<p class="PlainText">All BS2 models can interpret two's complement negative numbers correctly in <span class="keyword_in_text">DEBUG</span> and <span class="keyword_in_text">SEROUT</span> instructions using formatters like SDEC (for signed decimal). In calculations, however, it assumes that all values are positive. This yields correct results with two's complement negative numbers for addition, subtraction, and multiplication, but not for division. </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 © <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>
|
850
help/BasicStampHelp/Content/LanguageTopics/Reference/Ops_bi.htm
Normal file
850
help/BasicStampHelp/Content/LanguageTopics/Reference/Ops_bi.htm
Normal file
@ -0,0 +1,850 @@
|
||||
<?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="PBASIC Language Reference|PBASIC Operators" 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>Binary Operators</title>
|
||||
<link href="../../SkinSupport/MadCap.css" rel="stylesheet" />
|
||||
<link href="../../Resources/Stylesheets/BSE_Help.css" rel="stylesheet" />
|
||||
<script src="../../SkinSupport/MadCapAll.js">
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="MCBreadcrumbsBox_0"><span class="MCBreadcrumbsPrefix">You are here: </span><a class="MCBreadcrumbsLink" href="AlphaRef.htm">PBASIC Language Reference</a><span class="MCBreadcrumbsDivider"> > </span><a class="MCBreadcrumbsLink" href="Operators.htm">PBASIC Operators</a><span class="MCBreadcrumbsDivider"> > </span><span class="MCBreadcrumbs">Binary Operators</span>
|
||||
</div>
|
||||
<h1>Binary Operators</h1>
|
||||
<p>
|
||||
<img src="../../graphics/pgm_icon1.gif" border="0" alt="" />
|
||||
<img src="../../graphics/pgm_icon2.gif" border="0" alt="" />
|
||||
<img src="../../graphics/pgm_icon2e.gif" border="0" alt="" />
|
||||
<img src="../../graphics/pgm_icon2sx.gif" border="0" alt="" />
|
||||
<img src="../../graphics/pgm_icon2p.gif" border="0" alt="" />
|
||||
<img src="../../graphics/pgm_icon2pe.gif" border="0" alt="" />
|
||||
<img src="../../graphics/pgm_icon2px.gif" border="0" alt="" />
|
||||
</p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Binary operators require two arguments. Click on any operator in the list below for details and examples.</p>
|
||||
<p class="PlainText">(See also: <a href="Ops_uni.htm" target="" title="" alt="" class="MCXref_0">Unary Operators</a> and <a href="OpsPrecedence.htm" target="" title="" alt="" class="MCXref_0">Operator Precedence</a>.)</p>
|
||||
<h2>Notes about the 16-bit workspace</h2>
|
||||
<p class="PlainText">Many of the operator descriptions will say something like "computes (some function) of a 16-bit number." This does not mean that the operator does not work on smaller byte or nibble values, but rather that the computation is done in a 16-bit workspace. If the value is smaller than 16 bits, the BASIC Stamp pads it with leading 0s to make a 16-bit value. If the 16-bit result of a calculation is to be packed into a smaller variable, the higher-order bits are discarded (truncated).</p>
|
||||
<div class="MCDropDown">
|
||||
<div class="MCDropDownHead_0"><a class="MCDropDownHotSpot_0" href="javascript:void(0);" id="MCDropDownHotSpot_2082691904_0" onclick="FMCDropDown( this ); return false;"><img style="border: none;margin-right: 2px;" src="../../SkinSupport/DropDownClosed.gif" MadCap:altsrc="../../SkinSupport/DropDownOpen.gif" onload="if ( typeof( FMCPreloadImage ) == 'function' ) { FMCPreloadImage( '../../SkinSupport/DropDownOpen.gif' ); }" class="MCDropDownIcon" />+   (Addition)</a>
|
||||
</div>
|
||||
<div class="MCDropDownBody" id="MCDropDownBody_2082691904_0" style="display: none;">
|
||||
<p> </p>
|
||||
<p class="PlainText"><a name="addition"></a>The Addition operator (+) adds variables and/or constants, returning a 16-bit
|
||||
result. It works exactly as you would expect with unsigned integers from 0 to 65535.
|
||||
If the result of addition is larger than 65535, the carry bit will be lost. If the
|
||||
values added are signed 16-bit numbers and the destination is a 16-bit variable,
|
||||
the result of the addition will be correct in both sign and value.</p>
|
||||
<img src="../../graphics/bs1_inline.gif" border="0" alt="" /><pre class="BScode" xml:space="preserve">
|
||||
SYMBOL value1 = W0
|
||||
SYMBOL value2 = W1
|
||||
|
||||
Main:
|
||||
value1 = -99
|
||||
value2 = 100
|
||||
value1 = value1 + value2 ' Add the numbers
|
||||
DEBUG value1 ' Show the result (1)
|
||||
END
|
||||
</pre>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0" alt="" /><pre class="BScode" xml:space="preserve">
|
||||
value1 VAR Word
|
||||
value2 VAR Word
|
||||
|
||||
Main:
|
||||
value1 = -1575
|
||||
value2 = 976
|
||||
value1 = value1 + value2 ' Add the numbers
|
||||
DEBUG SDEC ? value1 ' Show the result (-599)
|
||||
END
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="MCDropDown">
|
||||
<div class="MCDropDownHead_0"><a class="MCDropDownHotSpot_0" href="javascript:void(0);" id="MCDropDownHotSpot_2082691904_1" onclick="FMCDropDown( this ); return false;"><img style="border: none;margin-right: 2px;" src="../../SkinSupport/DropDownClosed.gif" MadCap:altsrc="../../SkinSupport/DropDownOpen.gif" onload="if ( typeof( FMCPreloadImage ) == 'function' ) { FMCPreloadImage( '../../SkinSupport/DropDownOpen.gif' ); }" class="MCDropDownIcon" />-   (Subtraction)</a>
|
||||
</div>
|
||||
<div class="MCDropDownBody" id="MCDropDownBody_2082691904_1" style="display: none;">
|
||||
<p> </p>
|
||||
<p class="PlainText"><a name="subtraction"></a>The Subtraction operator (-) subtracts variables and/or constants, returning
|
||||
a 16-bit result. It works exactly as you would expect with unsigned integers from 0
|
||||
to 65535. If the result is negative, it will be correctly expressed as a signed
|
||||
16-bit number. </p>
|
||||
<img src="../../graphics/bs1_inline.gif" border="0" alt="" /><pre class="BScode" xml:space="preserve">
|
||||
SYMBOL value1 = W0
|
||||
SYMBOL value2 = W1
|
||||
|
||||
Main:
|
||||
value1 = 199
|
||||
value2 = 100
|
||||
value1 = value1 - value2 ' Subtract value2 from value1
|
||||
DEBUG value1 ' Show the result (99)
|
||||
END
|
||||
</pre>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0" alt="" /><pre class="BScode" xml:space="preserve">
|
||||
value1 VAR Word
|
||||
value2 VAR Word
|
||||
|
||||
Main:
|
||||
value1 = 1000
|
||||
value2 = 1999
|
||||
value1 = value1 - value2 ' Subtract value2 from value1
|
||||
DEBUG SDEC ? value1 ' Show the result (-999)
|
||||
END
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="MCDropDown">
|
||||
<div class="MCDropDownHead_0"><a class="MCDropDownHotSpot_0" href="javascript:void(0);" id="MCDropDownHotSpot_2082691904_2" onclick="FMCDropDown( this ); return false;"><img style="border: none;margin-right: 2px;" src="../../SkinSupport/DropDownClosed.gif" MadCap:altsrc="../../SkinSupport/DropDownOpen.gif" onload="if ( typeof( FMCPreloadImage ) == 'function' ) { FMCPreloadImage( '../../SkinSupport/DropDownOpen.gif' ); }" class="MCDropDownIcon" />*   (Multiplication)</a>
|
||||
</div>
|
||||
<div class="MCDropDownBody" id="MCDropDownBody_2082691904_2" style="display: none;">
|
||||
<p> </p>
|
||||
<p class="PlainText"><a name="multiply"></a>The Multiply operator (*) multiplies variables and/or constants, returning
|
||||
the low 16 bits of the result. It works exactly as you would expect with
|
||||
unsigned integers from 0 to 65535. If the result of multiplication is larger
|
||||
than 65535, the excess bits will be lost. Multiplication of signed variables
|
||||
will be correct in both number and sign, provided that the result is in the
|
||||
range -32767 to +32767.</p>
|
||||
<p>
|
||||
<img src="../../graphics/bs1_inline.gif" border="0" alt="" />
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
SYMBOL value1 = W0
|
||||
SYMBOL value2 = W1
|
||||
|
||||
Main:
|
||||
value1 = 1000
|
||||
value2 = 19
|
||||
value1 = value1 * value2 ' Multiply the numbers
|
||||
DEBUG value1 ' Show the result (19000)
|
||||
END
|
||||
</pre>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0" alt="" /><pre class="BScode" xml:space="preserve">
|
||||
value1 VAR Word
|
||||
value2 VAR Word
|
||||
|
||||
Main:
|
||||
value1 = 1000
|
||||
value2 = 19
|
||||
value1 = value1 * value2 ' Multiply the numbers
|
||||
DEBUG SDEC ? value1 ' Show the result (19000)
|
||||
END
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="MCDropDown">
|
||||
<div class="MCDropDownHead_0"><a class="MCDropDownHotSpot_0" href="javascript:void(0);" id="MCDropDownHotSpot_2082691904_3" onclick="FMCDropDown( this ); return false;"><img style="border: none;margin-right: 2px;" src="../../SkinSupport/DropDownClosed.gif" MadCap:altsrc="../../SkinSupport/DropDownOpen.gif" onload="if ( typeof( FMCPreloadImage ) == 'function' ) { FMCPreloadImage( '../../SkinSupport/DropDownOpen.gif' ); }" class="MCDropDownIcon" />**   Multiply High (Return Upper 16 Bits)</a>
|
||||
</div>
|
||||
<div class="MCDropDownBody" id="MCDropDownBody_2082691904_3" style="display: none;">
|
||||
<p> </p>
|
||||
<p class="PlainText"><a name="multi-high"></a>The Multiply High operator (**) multiplies variables and/or constants,
|
||||
returning the high 16 bits of the result. When you multiply two 16-bit
|
||||
values, the result can be as large as 32 bits. Since the largest variable
|
||||
supported by PBASIC is 16 bits, the highest 16 bits of a 32-bit
|
||||
multiplication result are normally lost. The ** (double-star) operator gives you these upper 16 bits. For example, suppose you multiply 65000
|
||||
($FDE8) by itself. The result is 4,225,000,000 or $FBD46240. The * (star, or
|
||||
normal multiplication) operator would return the lower 16 bits, $6240.
|
||||
The ** operator returns $FBD4.</p>
|
||||
<p>
|
||||
<img src="../../graphics/bs1_inline.gif" border="0" alt="" />
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
SYMBOL value1 = W0
|
||||
SYMBOL value2 = W1
|
||||
|
||||
Main:
|
||||
value1 = $FDE8
|
||||
value2 = value1 ** value1 ' Multiply value1 by itself
|
||||
DEBUG $value2 ' Show upper 16 bits
|
||||
END
|
||||
</pre>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0" alt="" /><pre class="BScode" xml:space="preserve">
|
||||
value1 VAR Word
|
||||
value2 VAR Word
|
||||
|
||||
Main:
|
||||
value1 = $FDE8
|
||||
value1 = value1 ** value1 ' Multiply value1 by itself
|
||||
DEBUG HEX ? value1 ' Show upper 16 bits
|
||||
END
|
||||
</pre>
|
||||
<p class="PlainText">An interesting application of the ** operator is to multiply by a known
|
||||
fractional value less than one. The fraction value is expressed in units
|
||||
of 1/65536. To find the fractional ** parameter, multiply the fraction part
|
||||
by 65536. Example:</p>
|
||||
<img src="../../graphics/bs1_inline.gif" border="0" alt="" /><pre class="BScode" xml:space="preserve">
|
||||
SYMBOL Frac = 47554 ' = 0.72562 x 65536
|
||||
SYMBOL value = W0
|
||||
|
||||
Test:
|
||||
value = 10000
|
||||
value = value ** Frac ' Multiply 10000 by 0.72562
|
||||
DEBUG value ' Show result (7256)
|
||||
</pre>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0" alt="" /><pre class="BScode" xml:space="preserve">
|
||||
Frac CON 47554 ' = 0.72562 x 65536
|
||||
value VAR Word
|
||||
|
||||
Test:
|
||||
value = 10000
|
||||
value = value ** Frac ' Multiply 10000 by 0.72562
|
||||
DEBUG ? value ' Show result (7256)
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="MCDropDown">
|
||||
<div class="MCDropDownHead_0"><a class="MCDropDownHotSpot_0" href="javascript:void(0);" id="MCDropDownHotSpot_2082691904_4" onclick="FMCDropDown( this ); return false;"><img style="border: none;margin-right: 2px;" src="../../SkinSupport/DropDownClosed.gif" MadCap:altsrc="../../SkinSupport/DropDownOpen.gif" onload="if ( typeof( FMCPreloadImage ) == 'function' ) { FMCPreloadImage( '../../SkinSupport/DropDownOpen.gif' ); }" class="MCDropDownIcon" />*/   Multiply Middle (Return Middle 16 Bits)</a>
|
||||
</div>
|
||||
<div class="MCDropDownBody" id="MCDropDownBody_2082691904_4" style="display: none;">
|
||||
<p> </p>
|
||||
<p class="PlainText"><a name="multi-mid"></a>The Multiply Middle operator (*/) multiplies variables and/or constants,
|
||||
returning the middle 16 bits of the 32-bit result. This has the effect of
|
||||
multiplying a value by a whole number and a fraction. The whole number
|
||||
is the upper byte of the multiplier (0 to 255 whole units) and the fraction is
|
||||
the lower byte of the multiplier (0 to 255 units of 1/256 each). The */ (star-slash)
|
||||
operator gives you an excellent workaround for the BASIC Stamp's integer-only
|
||||
math. Suppose you want to multiply a value by 1.5. The whole number, and therefore
|
||||
the upper byte of the multiplier, would be 1, and the lower byte (fractional part)
|
||||
would be 128, since 128/256 = 0.5. It may be clearer to express the */ multiplier
|
||||
in hex—as $0180—since hex keeps the contents of the upper and lower bytes separate.
|
||||
|
||||
|
||||
</p>
|
||||
<p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0" alt="" />
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
value1 VAR Word
|
||||
|
||||
Main:
|
||||
value1 = 100
|
||||
value1= value1 */ $0180 ' Multiply by 1.5 [1 + (128/256)]
|
||||
DEBUG ? value1 ' Show result (150)
|
||||
END
|
||||
</pre>
|
||||
<p class="PlainText">To calculate constants for use with the */ operator, take the desired (mixed) target multiplier and multiply it by 256, then convert the result to a whole integer: INT(mixed * 256). For instance, if our target multiplier is Pi
|
||||
(3.14159), the resulting constant to represent that value for the */ operator is INT(3.13159 * 256) = INT(804.25) = 804 ($0324). Notice that the upper byte is $03 (decimal 3; the whole number), and the lower
|
||||
byte is $24 (decimal 36; the fractional part that means 36/256). So the constant Pi for use with */
|
||||
would be $0324. This isn’t a perfect match for Pi, but the error is only
|
||||
about 0.1%.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="MCDropDown">
|
||||
<div class="MCDropDownHead_0"><a class="MCDropDownHotSpot_0" href="javascript:void(0);" id="MCDropDownHotSpot_2082691904_5" onclick="FMCDropDown( this ); return false;"><img style="border: none;margin-right: 2px;" src="../../SkinSupport/DropDownClosed.gif" MadCap:altsrc="../../SkinSupport/DropDownOpen.gif" onload="if ( typeof( FMCPreloadImage ) == 'function' ) { FMCPreloadImage( '../../SkinSupport/DropDownOpen.gif' ); }" class="MCDropDownIcon" />/   (Division)</a>
|
||||
</div>
|
||||
<div class="MCDropDownBody" id="MCDropDownBody_2082691904_5" style="display: none;">
|
||||
<p> </p>
|
||||
<p class="PlainText"><a name="divide"></a>The Division operator (/) divides variables and/or constants, returning a
|
||||
16-bit result. It works exactly as you would expect with unsigned integers
|
||||
from 0 to 65535. Use / only with positive values; signed values do not
|
||||
provide correct results. Here’s an example of unsigned division:
|
||||
|
||||
<img src="../../graphics/bs1_inline.gif" border="0" alt="" /></p><pre class="BScode" xml:space="preserve">
|
||||
SYMBOL value1 = W0
|
||||
SYMBOL value2 = W1
|
||||
|
||||
Main:
|
||||
value1 = 1000
|
||||
value2 = 5
|
||||
value1 = value1 / value2 ' Divide the numbers
|
||||
DEBUG value1 ' Show the result (200)
|
||||
END
|
||||
</pre>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0" alt="" /><pre class="BScode" xml:space="preserve">
|
||||
value1 VAR Word
|
||||
Value2 VAR Word
|
||||
|
||||
Main:
|
||||
value1 = 1000
|
||||
value2 = 5
|
||||
value1 = value1 / value2 ' Divide the numbers
|
||||
DEBUG DEC ? value1 ' Show the result (200)
|
||||
END
|
||||
</pre>
|
||||
<p class="PlainText">A workaround to the inability to divide signed numbers is to have your
|
||||
program divide absolute values, then negate the result if one (and only
|
||||
one) of the operands was negative. All values must lie within the range of
|
||||
-32767 to +32767.</p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0" alt="" /><pre class="BScode" xml:space="preserve">
|
||||
sign VAR Bit ' bit to hold the sign
|
||||
value1 VAR Word
|
||||
Value2 VAR Word
|
||||
|
||||
Main:
|
||||
value1 = 100
|
||||
value2 = -3200
|
||||
sign = value1.Bit15 ^ value2.Bit15 ' determine result sign
|
||||
value2 = ABS value2 / ABS value1 ' divide absolute values
|
||||
IF (sign = 1) THEN value2 = -value2 ' correct sign if negative
|
||||
DEBUG SDEC ? value2 ' show the result (-32)
|
||||
END
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="MCDropDown">
|
||||
<div class="MCDropDownHead_0"><a class="MCDropDownHotSpot_0" href="javascript:void(0);" id="MCDropDownHotSpot_2082691904_6" onclick="FMCDropDown( this ); return false;"><img style="border: none;margin-right: 2px;" src="../../SkinSupport/DropDownClosed.gif" MadCap:altsrc="../../SkinSupport/DropDownOpen.gif" onload="if ( typeof( FMCPreloadImage ) == 'function' ) { FMCPreloadImage( '../../SkinSupport/DropDownOpen.gif' ); }" class="MCDropDownIcon" />// (Modulus—Remainder of Division)</a>
|
||||
</div>
|
||||
<div class="MCDropDownBody" id="MCDropDownBody_2082691904_6" style="display: none;">
|
||||
<p> </p>
|
||||
<p class="PlainText"><a name="modulus"></a>The Modulus operator (//) returns the remainder left after dividing one
|
||||
value by another. Some division problems don’t have a whole-number
|
||||
result; they return a whole number and a fraction. For example, 1000 / 6 =
|
||||
166.667. Integer math doesn’t allow the fractional portion of the result, so
|
||||
1000 / 6 = 166. However, 166 is an approximate answer, because 166 * 6 =
|
||||
996. The division operation left a remainder of 4. The // (double-slash)
|
||||
operator returns the remainder of a given division operation. Naturally, numbers
|
||||
that divide evenly, such as 1000 / 5, produce a remainder of 0.</p>
|
||||
<img src="../../graphics/bs1_inline.gif" border="0" alt="" /><pre class="BScode" xml:space="preserve">
|
||||
SYMBOL value1 = W0
|
||||
SYMBOL value2 = W1
|
||||
|
||||
Main:
|
||||
value1 = 1000
|
||||
value2 = 6
|
||||
value1 = value1 // value2 ' get remainder of value1 / value2
|
||||
DEBUG value1 ' show the result (4)
|
||||
END
|
||||
</pre>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0" alt="" /><pre class="BScode" xml:space="preserve">
|
||||
value1 VAR Word
|
||||
value2 VAR Word
|
||||
|
||||
Main:
|
||||
value1 = 1000
|
||||
value2 = 6
|
||||
value1 = value1 // value2 ' get remainder of value1 / value2
|
||||
DEBUG DEC ? value1 ' show the result (4)
|
||||
END
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="MCDropDown">
|
||||
<div class="MCDropDownHead_0"><a class="MCDropDownHotSpot_0" href="javascript:void(0);" id="MCDropDownHotSpot_2082691904_7" onclick="FMCDropDown( this ); return false;"><img style="border: none;margin-right: 2px;" src="../../SkinSupport/DropDownClosed.gif" MadCap:altsrc="../../SkinSupport/DropDownOpen.gif" onload="if ( typeof( FMCPreloadImage ) == 'function' ) { FMCPreloadImage( '../../SkinSupport/DropDownOpen.gif' ); }" class="MCDropDownIcon" />MIN   (Limit a Value to Specified Low)</a>
|
||||
</div>
|
||||
<div class="MCDropDownBody" id="MCDropDownBody_2082691904_7" style="display: none;">
|
||||
<p> </p>
|
||||
<p class="PlainText"><a name="limit-min"></a>The Minimum operator (MIN) limits a value to a specified 16-bit positive
|
||||
minimum. The syntax of MIN is:</p>
|
||||
<p class="PlainText"><span class="code_in_text">Value MIN Limit
|
||||
</span>
|
||||
</p>
|
||||
<p class="PlainText">Where <i>Value</i> is a constant or variable value to perform the MIN function
|
||||
upon and <i>Limit</i> is the minimum Value that <i>value</i> is allowed to be. When used in a statement like <i>result = Value MIN Limit</i>, its
|
||||
logic is, 'if <i>Value</i> is less than <i>Limit</i>, then make result =
|
||||
<i>Limit</i>; if <i>Value</i> is greater than or equal to <i>Limit</i>, make
|
||||
result = <i>Value</i>.' MIN works in positive math only; its comparisons are not
|
||||
valid when used on two’s complement negative numbers, since the positive-integer representation of a number like -1 ($FFFF in hexadecimal or 65535 in unsigned decimal) is larger
|
||||
than that of a number like 10 ($000A hexadecimal or 10 decimal). Use MIN only with unsigned
|
||||
integers. Because of the way fixed-size integers work, you should be careful when
|
||||
using an expression involving MIN 0. For example, result = 0 - 1 MIN 0 will result in
|
||||
65535 because 0 - 1 = -1 (65535 in two's compliment math) and 65535 is greater the minimum boundary 0.</p>
|
||||
<img src="../../graphics/bs1_inline.gif" border="0" alt="" /><pre class="BScode" xml:space="preserve">
|
||||
SYMBOL value1 = W0
|
||||
SYMBOL value2 = W1
|
||||
|
||||
Main:
|
||||
FOR value1 = 100 TO 0 STEP -10 ' walk value1 from 100 to 0
|
||||
value2 = value1 MIN 50 ' use MIN to clamp at 50
|
||||
DEBUG value2 ' show "clamped" value
|
||||
NEXT
|
||||
END
|
||||
</pre>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0" alt="" /><pre class="BScode" xml:space="preserve">
|
||||
value1 VAR Word
|
||||
value2 VAR Word
|
||||
|
||||
Main:
|
||||
FOR value1 = 100 TO 0 STEP 10 ' walk value1 from 100 to 0
|
||||
value2 = value1 MIN 50 ' use MIN to clamp at 50
|
||||
DEBUG DEC ? value2 MIN 50 ' show "clamped" value
|
||||
NEXT
|
||||
END
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="MCDropDown">
|
||||
<div class="MCDropDownHead_0"><a class="MCDropDownHotSpot_0" href="javascript:void(0);" id="MCDropDownHotSpot_2082691904_8" onclick="FMCDropDown( this ); return false;"><img style="border: none;margin-right: 2px;" src="../../SkinSupport/DropDownClosed.gif" MadCap:altsrc="../../SkinSupport/DropDownOpen.gif" onload="if ( typeof( FMCPreloadImage ) == 'function' ) { FMCPreloadImage( '../../SkinSupport/DropDownOpen.gif' ); }" class="MCDropDownIcon" />MAX   (Limit a Value to a Specified High)</a>
|
||||
</div>
|
||||
<div class="MCDropDownBody" id="MCDropDownBody_2082691904_8" style="display: none;">
|
||||
<p> </p>
|
||||
<p class="PlainText"><a name="limit-max"></a>The Maximum operator (MAX) limits a value to a specified 16-bit positive maximum.
|
||||
The syntax of MAX is:</p>
|
||||
<p class="PlainText"><span class="code_in_text">Value MAX Limit</span> <![CDATA[ ]]></p>
|
||||
<p class="PlainText">...where <i>Value</i> is a constant or variable value to perform the MAX function
|
||||
upon and <i>Limit</i> is the maximum value that <i>Value</i> is allowed to be. When used in a statement like <i>result = Value MAX Limit</i>, its
|
||||
logic is, ‘if <i>Value</i> is greater than <i>Limit</i>, then make result =
|
||||
<i>Limit</i>; if <i>Value</i> is less than or equal to <i>Limit</i>, make result =
|
||||
<i>Value</i>.’ MAX works in positive math only; its comparisons are not valid when
|
||||
used on two’s complement negative numbers, since the positive-integer representation
|
||||
of a number like -1 ($FFFF in hexadecimal or 65535 in unsigned decimal) is larger than that of a
|
||||
number like 10 ($000A hexadecimal or 10 decimal). Use MAX only with unsigned integers. Because
|
||||
of the way fixed-size integers work, you should be careful when using an expression
|
||||
involving MAX 65535. For example, result = 65535+1 MAX 65535 will result in 0 because 65535 + 1 = 0 (in 16-bits) and 0 is less than the maximum boundary 65535.</p>
|
||||
<img src="../../graphics/bs1_inline.gif" border="0" alt="" /><pre class="BScode" xml:space="preserve">
|
||||
SYMBOL value1 = W0
|
||||
SYMBOL value2 = W1
|
||||
|
||||
Main:
|
||||
FOR value1 = 0 TO 100 STEP 10 ' Walk value1 from 0 to 100
|
||||
value2 = value1 MAX 50 ' Use MAX to clamp at 50
|
||||
DEBUG value2 ' Show "clamped" value
|
||||
NEXT
|
||||
END
|
||||
</pre>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0" alt="" /><pre class="BScode" xml:space="preserve">
|
||||
value VAR Word
|
||||
|
||||
Main:
|
||||
FOR value = 0 TO 100 STEP 10 ' Walk value from 0 to 100
|
||||
DEBUG ? value MAX 50 ' Show "clamped" value
|
||||
NEXT
|
||||
END
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="MCDropDown">
|
||||
<div class="MCDropDownHead_0"><a class="MCDropDownHotSpot_0" href="javascript:void(0);" id="MCDropDownHotSpot_2082691904_9" onclick="FMCDropDown( this ); return false;"><img style="border: none;margin-right: 2px;" src="../../SkinSupport/DropDownClosed.gif" MadCap:altsrc="../../SkinSupport/DropDownOpen.gif" onload="if ( typeof( FMCPreloadImage ) == 'function' ) { FMCPreloadImage( '../../SkinSupport/DropDownOpen.gif' ); }" class="MCDropDownIcon" />DIG   (Returns Specified Digit of Number)</a>
|
||||
</div>
|
||||
<div class="MCDropDownBody" id="MCDropDownBody_2082691904_9" style="display: none;">
|
||||
<p> </p>
|
||||
<p class="PlainText"><a name="digit"></a>The Digit operator (DIG) returns the specified decimal digit of a 16-bit positive
|
||||
value. Digits are numbered from 0 (the right-most digit) to 4 (the left-most digit
|
||||
of a 16-bit number; 0 to 65535).
|
||||
|
||||
</p>
|
||||
<p class="PlainText">
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0" alt="" />
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
value VAR Word
|
||||
idx VAR Nib
|
||||
|
||||
Main:
|
||||
value = 9742
|
||||
DEBUG ? value DIG 2 ' Show digit 2 (7)
|
||||
|
||||
FOR idx = 0 TO 4
|
||||
DEBUG ? value DIG idx ' Show digits 0 - 4 of 9742
|
||||
NEXT
|
||||
END
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="MCDropDown">
|
||||
<div class="MCDropDownHead_0"><a class="MCDropDownHotSpot_0" href="javascript:void(0);" id="MCDropDownHotSpot_2082691904_10" onclick="FMCDropDown( this ); return false;"><img style="border: none;margin-right: 2px;" src="../../SkinSupport/DropDownClosed.gif" MadCap:altsrc="../../SkinSupport/DropDownOpen.gif" onload="if ( typeof( FMCPreloadImage ) == 'function' ) { FMCPreloadImage( '../../SkinSupport/DropDownOpen.gif' ); }" class="MCDropDownIcon" />REV   (Reverses specified number of bits)</a>
|
||||
</div>
|
||||
<div class="MCDropDownBody" id="MCDropDownBody_2082691904_10" style="display: none;">
|
||||
<p> </p>
|
||||
<p class="PlainText"><a name="reverse"></a>The Reverse operator (REV) returns a reversed (mirrored) copy of a specified number
|
||||
of bits of a value, starting with the rightmost bit (LSB). For instance,
|
||||
%10101101 REV 4 would return %1011, a mirror image of the least significant four bits of the
|
||||
value.
|
||||
|
||||
</p>
|
||||
<p class="PlainText">
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0" alt="" />
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
DEBUG BIN4 ? %11001010 REV 4 ' Mirror lower 4 bits (%0101)
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="MCDropDown">
|
||||
<div class="MCDropDownHead_0"><a class="MCDropDownHotSpot_0" href="javascript:void(0);" id="MCDropDownHotSpot_2082691904_11" onclick="FMCDropDown( this ); return false;"><img style="border: none;margin-right: 2px;" src="../../SkinSupport/DropDownClosed.gif" MadCap:altsrc="../../SkinSupport/DropDownOpen.gif" onload="if ( typeof( FMCPreloadImage ) == 'function' ) { FMCPreloadImage( '../../SkinSupport/DropDownOpen.gif' ); }" class="MCDropDownIcon" /><<   (Shifts Bits Left by Specified Amount)</a>
|
||||
</div>
|
||||
<div class="MCDropDownBody" id="MCDropDownBody_2082691904_11" style="display: none;">
|
||||
<p> </p>
|
||||
<p class="PlainText"><a name="shfitleft"></a>The Shift Left operator (<<) shifts the bits of a value to the left a
|
||||
specified number of places. Bits shifted off the left end of a number are lost;
|
||||
bits shifted into the right end of the number are 0s. Shifting the bits of a
|
||||
value left n number of times has the same effect as multiplying that number by 2
|
||||
to the nth power. For instance 100 << 3 (shift the bits of the decimal
|
||||
number 100 left three places) is equivalent to 100 * 2<sup>3</sup>.
|
||||
|
||||
</p>
|
||||
<p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0" alt="" />
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
value VAR Word
|
||||
idx VAR Byte
|
||||
|
||||
Main:
|
||||
value = %1111111111111111
|
||||
|
||||
FOR idx = 1 TO 16 ' loop 16 times
|
||||
DEBUG BIN16 ? Value << idx ' display shifted value
|
||||
NEXT
|
||||
END
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="MCDropDown">
|
||||
<div class="MCDropDownHead_0"><a class="MCDropDownHotSpot_0" href="javascript:void(0);" id="MCDropDownHotSpot_2082691904_12" onclick="FMCDropDown( this ); return false;"><img style="border: none;margin-right: 2px;" src="../../SkinSupport/DropDownClosed.gif" MadCap:altsrc="../../SkinSupport/DropDownOpen.gif" onload="if ( typeof( FMCPreloadImage ) == 'function' ) { FMCPreloadImage( '../../SkinSupport/DropDownOpen.gif' ); }" class="MCDropDownIcon" />>>   (Shift Bits Right by Specified Amount)</a>
|
||||
</div>
|
||||
<div class="MCDropDownBody" id="MCDropDownBody_2082691904_12" style="display: none;">
|
||||
<p> </p>
|
||||
<p class="PlainText"><a name="shiftright"></a>The Shift Right operator (>>) shifts the bits of a variable to the right a
|
||||
specified number of places. Bits shifted off the right end of a number are lost;
|
||||
bits shifted into the left end of the number are 0s. Shifting the bits of a value
|
||||
right n number of times has the same effect as dividing that number (unsigned) by 2 to the
|
||||
nth power. For instance 100 >> 3 (shift the bits of the decimal number 100 right
|
||||
three places) is equivalent to 100 / 2<sup>3</sup>.</p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0" alt="" /><pre class="BScode" xml:space="preserve">
|
||||
value VAR Word
|
||||
idx VAR Byte
|
||||
|
||||
Main:
|
||||
value = %1111111111111111
|
||||
|
||||
FOR idx = 1 TO 16 ' loop 16 times
|
||||
DEBUG BIN16 ? Value >> idx ' display shifted value
|
||||
NEXT
|
||||
END
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="MCDropDown">
|
||||
<div class="MCDropDownHead_0"><a class="MCDropDownHotSpot_0" href="javascript:void(0);" id="MCDropDownHotSpot_2082691904_13" onclick="FMCDropDown( this ); return false;"><img style="border: none;margin-right: 2px;" src="../../SkinSupport/DropDownClosed.gif" MadCap:altsrc="../../SkinSupport/DropDownOpen.gif" onload="if ( typeof( FMCPreloadImage ) == 'function' ) { FMCPreloadImage( '../../SkinSupport/DropDownOpen.gif' ); }" class="MCDropDownIcon" />&   (Bitwise AND)</a>
|
||||
</div>
|
||||
<div class="MCDropDownBody" id="MCDropDownBody_2082691904_13" style="display: none;">
|
||||
<p> </p>
|
||||
<p class="PlainText"><a name="bitwiseand"></a>The Bitwise AND (&) operator returns the bit pattern of the logical AND of each bit pair in two binary values. Each bit of these values is subject to the following logic:</p><pre xml:space="preserve"><tt>    0 & 0 = 0
|
||||
    0 & 1 = 0
|
||||
    1 & 0 = 0
|
||||
    1 & 1 = 1</tt>
|
||||
</pre>
|
||||
<p class="PlainText">The result returned by & will contain 1s in only those bit positions in which
|
||||
both input values contain 1s.</p>
|
||||
<img src="../../graphics/bs1_inline.gif" border="0" alt="" /><pre class="BScode" xml:space="preserve">
|
||||
SYMBOL value1 = B0
|
||||
SYMBOL value2 = B1
|
||||
SYMBOL result = B2
|
||||
|
||||
Main:
|
||||
value1 = %00001111
|
||||
value2 = %10101101
|
||||
result = value1 & value2
|
||||
DEBUG %result ' Show AND result (%00001101)
|
||||
END
|
||||
</pre>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0" alt="" /><pre class="BScode" xml:space="preserve">
|
||||
DEBUG BIN8 ? %00001111 & %10101101 ' Show AND result (%00001101)
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="MCDropDown">
|
||||
<div class="MCDropDownHead_0"><a class="MCDropDownHotSpot_0" href="javascript:void(0);" id="MCDropDownHotSpot_2082691904_14" onclick="FMCDropDown( this ); return false;"><img style="border: none;margin-right: 2px;" src="../../SkinSupport/DropDownClosed.gif" MadCap:altsrc="../../SkinSupport/DropDownOpen.gif" onload="if ( typeof( FMCPreloadImage ) == 'function' ) { FMCPreloadImage( '../../SkinSupport/DropDownOpen.gif' ); }" class="MCDropDownIcon" />|   (Bitwise OR)</a>
|
||||
</div>
|
||||
<div class="MCDropDownBody" id="MCDropDownBody_2082691904_14" style="display: none;">
|
||||
<p> </p>
|
||||
<p class="PlainText"><a name="bitwiseor"></a>The Bitwise OR (|) operator returns the bit pattern of the logical OR of each bit pair in two binary values. Each bit of the values is subject to the following logic: </p><pre xml:space="preserve"><tt>    0 | 0 = 0
|
||||
    0 | 1 = 1
|
||||
    1 | 0 = 1
|
||||
    1 | 1 = 1</tt>
|
||||
</pre>
|
||||
<p class="PlainText">The result returned by | will contain 1s in any bit positions in which one or
|
||||
the other (or both) input values contain 1s.</p>
|
||||
<img src="../../graphics/bs1_inline.gif" border="0" alt="" /><pre class="BScode" xml:space="preserve">
|
||||
SYMBOL value1 = B0
|
||||
SYMBOL value2 = B1
|
||||
SYMBOL result = B2
|
||||
|
||||
Main:
|
||||
value1 = %00001111
|
||||
value2 = %10101001
|
||||
result = value1 | value2
|
||||
DEBUG %result ' Show OR result (%10101111)
|
||||
END
|
||||
</pre>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0" alt="" /><pre class="BScode" xml:space="preserve">
|
||||
DEBUG BIN8 ? %00001111 | %10101001 ' Show OR result (%10101111)
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="MCDropDown">
|
||||
<div class="MCDropDownHead_0"><a class="MCDropDownHotSpot_0" href="javascript:void(0);" id="MCDropDownHotSpot_2082691904_15" onclick="FMCDropDown( this ); return false;"><img style="border: none;margin-right: 2px;" src="../../SkinSupport/DropDownClosed.gif" MadCap:altsrc="../../SkinSupport/DropDownOpen.gif" onload="if ( typeof( FMCPreloadImage ) == 'function' ) { FMCPreloadImage( '../../SkinSupport/DropDownOpen.gif' ); }" class="MCDropDownIcon" />^   (Bitwise XOR)</a>
|
||||
</div>
|
||||
<div class="MCDropDownBody" id="MCDropDownBody_2082691904_15" style="display: none;">
|
||||
<p> </p>
|
||||
<p class="PlainText"><a name="bitwisexor"></a>The Bitwise Exclusive OR operator (|) returns the bit pattern of the logical XOR of each bit pair in two binary values. Each bit of the values is subject to the following logic: </p><pre xml:space="preserve"><tt>    0 ^ 0 = 0
|
||||
    0 ^ 1 = 1
|
||||
    1 ^ 0 = 1
|
||||
    1 ^ 1 = 0</tt>
|
||||
</pre>
|
||||
<p class="PlainText">The result returned by ^ will contain 1s in any bit positions in which one or
|
||||
the other (but not both) input values contain 1s.</p>
|
||||
<img src="../../graphics/bs1_inline.gif" border="0" alt="" /><pre class="BScode" xml:space="preserve">
|
||||
SYMBOL value1 = B0
|
||||
SYMBOL value2 = B1
|
||||
SYMBOL result = B2
|
||||
|
||||
Main:
|
||||
value1 = %00001111
|
||||
value2 = %10101001
|
||||
result = value1 ^ value2
|
||||
DEBUG %result ' Show OR result (%10100110)
|
||||
END
|
||||
</pre>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0" alt="" /><pre class="BScode" xml:space="preserve">
|
||||
DEBUG BIN8 ? %00001111 ^ %10101001 ' Show OR result (%10100110)
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="MCDropDown">
|
||||
<div class="MCDropDownHead_0"><a class="MCDropDownHotSpot_0" href="javascript:void(0);" id="MCDropDownHotSpot_2082691904_16" onclick="FMCDropDown( this ); return false;"><img style="border: none;margin-right: 2px;" src="../../SkinSupport/DropDownClosed.gif" MadCap:altsrc="../../SkinSupport/DropDownOpen.gif" onload="if ( typeof( FMCPreloadImage ) == 'function' ) { FMCPreloadImage( '../../SkinSupport/DropDownOpen.gif' ); }" class="MCDropDownIcon" />&/   (Bitwise AND NOT)</a>
|
||||
</div>
|
||||
<div class="MCDropDownBody" id="MCDropDownBody_2082691904_16" style="display: none;">
|
||||
<p class="PlainText"> </p>
|
||||
<p class="PlainText"><a name="andnot"></a>The Bitwise AND NOT operator (&/) returns the bit pattern of the logical AND NOT of each bit pair in two binary values. Each bit of the values is subject to the following logic:</p><pre xml:space="preserve"><tt>    0 &/ 0 = 0
|
||||
    0 &/ 1 = 0
|
||||
    1 &/ 0 = 1
|
||||
    1 &/ 1 = 0</tt>
|
||||
</pre>
|
||||
<p class="PlainText">The result returned by &/ will contain 1s in any bit positions in which the
|
||||
first value is 1 and the second value is 0.</p>
|
||||
<img src="../../graphics/bs1_inline.gif" border="0" alt="" /><pre class="BScode" xml:space="preserve">
|
||||
SYMBOL value1 = B0
|
||||
SYMBOL value2 = B1
|
||||
SYMBOL result = B2
|
||||
|
||||
Main:
|
||||
value1 = %00001111
|
||||
value2 = %10101001
|
||||
result = value1 &/ value2
|
||||
DEBUG %result ' Show AND NOT result (%00000110)
|
||||
END
|
||||
</pre>
|
||||
<div class="MCDropDown">
|
||||
<div class="MCDropDownHead_0"><a class="MCDropDownHotSpot_0" href="javascript:void(0);" id="MCDropDownHotSpot_2082691904_17" onclick="FMCDropDown( this ); return false;"><img style="border: none;margin-right: 2px;" src="../../SkinSupport/DropDownClosed.gif" MadCap:altsrc="../../SkinSupport/DropDownOpen.gif" onload="if ( typeof( FMCPreloadImage ) == 'function' ) { FMCPreloadImage( '../../SkinSupport/DropDownOpen.gif' ); }" class="MCDropDownIcon" />|/ (Bitwise OR NOT)</a>
|
||||
</div>
|
||||
<div class="MCDropDownBody" id="MCDropDownBody_2082691904_17" style="display: none;">
|
||||
<p class="PlainText"> </p>
|
||||
<p class="PlainText"><a name="ornot"></a>The OR NOT operator (|/) returns the bitwise OR NOT of two values. Each bit of the values is subject to the following logic:</p><pre xml:space="preserve"><tt>  0 |/ 0 = 1
|
||||
    0 |/ 1 = 0
|
||||
    1 |/ 0 = 1
|
||||
    1 |/ 1 = 1</tt>
|
||||
</pre>
|
||||
<p class="PlainText">The result returned by |/ will contain 1s in any bit positions in which the
|
||||
first value is 1 or the second value is 0.</p>
|
||||
<img src="../../graphics/bs1_inline.gif" border="0" alt="" /><pre class="BScode" xml:space="preserve">
|
||||
SYMBOL value1 = B0
|
||||
SYMBOL value2 = B1
|
||||
SYMBOL result = B2
|
||||
|
||||
Main:
|
||||
value1 = %00001111
|
||||
value2 = %10101001
|
||||
result = value1 |/ value2
|
||||
DEBUG %result ' Show OR NOT result (%01011111)
|
||||
END
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="MCDropDown">
|
||||
<div class="MCDropDownHead_0"><a class="MCDropDownHotSpot_0" href="javascript:void(0);" id="MCDropDownHotSpot_2082691904_18" onclick="FMCDropDown( this ); return false;"><img style="border: none;margin-right: 2px;" src="../../SkinSupport/DropDownClosed.gif" MadCap:altsrc="../../SkinSupport/DropDownOpen.gif" onload="if ( typeof( FMCPreloadImage ) == 'function' ) { FMCPreloadImage( '../../SkinSupport/DropDownOpen.gif' ); }" class="MCDropDownIcon" />^/   (Bitwise XOR NOT)</a>
|
||||
</div>
|
||||
<div class="MCDropDownBody" id="MCDropDownBody_2082691904_18" style="display: none;">
|
||||
<p> </p>
|
||||
<p><a name="xornot"></a>The Bitwise XOR NOT operator (^/) returns the bit pattern of the logical XOR NOT of each bit pair in two binary values. Each bit of
|
||||
the values is subject to the following logic:
|
||||
|
||||
</p><pre xml:space="preserve"><tt>    0 ^/ 0 = 1
|
||||
    0 ^/ 1 = 0
|
||||
    1 ^/ 0 = 0
|
||||
    1 ^/ 1 = 1</tt>
|
||||
</pre>
|
||||
<p class="PlainText">The result returned by ^/ will contain 1s in any bit positions in which the
|
||||
first value and second values are equal.</p>
|
||||
<img src="../../graphics/bs1_inline.gif" border="0" /><pre class="BScode" xml:space="preserve">
|
||||
SYMBOL value1 = B0
|
||||
SYMBOL value2 = B1
|
||||
SYMBOL result = B2
|
||||
|
||||
Main:
|
||||
value1 = %00001111
|
||||
value2 = %10101001
|
||||
result = value1 ^/ value2
|
||||
DEBUG %result ' Show OR NOT result (%01011001)
|
||||
END
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="MCDropDown">
|
||||
<div class="MCDropDownHead_0"><a class="MCDropDownHotSpot_0" href="javascript:void(0);" id="MCDropDownHotSpot_2082691904_19" onclick="FMCDropDown( this ); return false;"><img style="border: none;margin-right: 2px;" src="../../SkinSupport/DropDownClosed.gif" MadCap:altsrc="../../SkinSupport/DropDownOpen.gif" onload="if ( typeof( FMCPreloadImage ) == 'function' ) { FMCPreloadImage( '../../SkinSupport/DropDownOpen.gif' ); }" class="MCDropDownIcon" />AND   (Logical AND)</a>
|
||||
</div>
|
||||
<div class="MCDropDownBody" id="MCDropDownBody_2082691904_19" style="display: none;">
|
||||
<p> </p>
|
||||
<p class="PlainText"><a name="and"></a>The AND operator returns the logical AND of two values or expressions. Note that
|
||||
in the BASIC Stamp, a non-zero value is considered True (T), zero is considered
|
||||
False (F). The values/expressions are subject to the following logic:
|
||||
</p><pre xml:space="preserve"><tt>    F AND F = F
|
||||
    F AND T = F
|
||||
    T AND F = F
|
||||
    T AND T = T</tt>
|
||||
</pre>
|
||||
<p class="PlainText">The result returned by AND will be True or False.</p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0" /><pre class="BScode" xml:space="preserve">
|
||||
score VAR Byte
|
||||
avg VAR Byte
|
||||
|
||||
Main:
|
||||
score = 93
|
||||
avg = 89
|
||||
|
||||
IF (score > 80) AND (avg > 70) THEN
|
||||
DEBUG "Promote to next grade." ' both conditions are True
|
||||
ELSE
|
||||
DEBUG "Consider additional tutoring." ' at least one condition is False
|
||||
ENDIF
|
||||
END
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="MCDropDown">
|
||||
<div class="MCDropDownHead_0"><a class="MCDropDownHotSpot_0" href="javascript:void(0);" id="MCDropDownHotSpot_2082691904_20" onclick="FMCDropDown( this ); return false;"><img style="border: none;margin-right: 2px;" src="../../SkinSupport/DropDownClosed.gif" MadCap:altsrc="../../SkinSupport/DropDownOpen.gif" onload="if ( typeof( FMCPreloadImage ) == 'function' ) { FMCPreloadImage( '../../SkinSupport/DropDownOpen.gif' ); }" class="MCDropDownIcon" />OR   (Logical OR)</a>
|
||||
</div>
|
||||
<div class="MCDropDownBody" id="MCDropDownBody_2082691904_20" style="display: none;">
|
||||
<p> </p>
|
||||
<p class="PlainText"><a name="or"></a>The OR operator returns the logical OR of two values or expressions. Note that
|
||||
in the BASIC Stamp, a non-zero value is considered True (T), zero is considered
|
||||
False (F). The values/expressions are subject to the following logic:</p><pre xml:space="preserve"><tt>  F OR F = F
|
||||
    F OR T = T
|
||||
    T OR F = T
|
||||
    T OR T = T</tt>
|
||||
</pre>
|
||||
<p class="PlainText">The result returned by OR will be True or False.</p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0" /><pre class="BScode" xml:space="preserve">
|
||||
score VAR Byte
|
||||
avg VAR Byte
|
||||
|
||||
Main:
|
||||
score = 63
|
||||
avg = 89
|
||||
|
||||
IF (score < 80) OR (avg < 70) THEN
|
||||
DEBUG "Consider additional tutoring." ' at least one condition is True
|
||||
ELSE
|
||||
DEBUG "Promote to next grade." ' both conditions are False
|
||||
ENDIF
|
||||
END
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="MCDropDown">
|
||||
<div class="MCDropDownHead_0"><a class="MCDropDownHotSpot_0" href="javascript:void(0);" id="MCDropDownHotSpot_2082691904_21" onclick="FMCDropDown( this ); return false;"><img style="border: none;margin-right: 2px;" src="../../SkinSupport/DropDownClosed.gif" MadCap:altsrc="../../SkinSupport/DropDownOpen.gif" onload="if ( typeof( FMCPreloadImage ) == 'function' ) { FMCPreloadImage( '../../SkinSupport/DropDownOpen.gif' ); }" class="MCDropDownIcon" />XOR   (Logical XOR)</a>
|
||||
</div>
|
||||
<div class="MCDropDownBody" id="MCDropDownBody_2082691904_21" style="display: none;">
|
||||
<p> </p>
|
||||
<p class="PlainText"><a name="xor"></a>The XOR operator returns the logical Exclusive OR of two values or expressions.
|
||||
Note that in the BASIC Stamp, a non-zero value is considered True (T), zero is
|
||||
considered False (F). The values/expressions are subject to the following logic:</p><pre xml:space="preserve"><tt>    F XOR F = F
|
||||
    F XOR T = T
|
||||
    T XOR F = T
|
||||
    T XOR T = F</tt>
|
||||
</pre>
|
||||
<p class="PlainText">The XOR operator can be confusing at first. An easy way to remember the logic
|
||||
is: <i>If one or the other is True -- but not both -- then the result is True,
|
||||
otherwise the result is False.</i></p>
|
||||
<p class="PlainText">The result returned by XOR will be True or False.</p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0" /><pre class="BScode" xml:space="preserve">
|
||||
turnL VAR Bit
|
||||
turnR VAR Bit
|
||||
|
||||
Main:
|
||||
turnL = 0
|
||||
turnR = 1
|
||||
|
||||
IF (turnL = 1) XOR (turnR = 1) THEN ' one or other is True
|
||||
DEBUG "Turning - ", "L" + ("R" - "L" * turnR)
|
||||
ELSE
|
||||
DEBUG "Continue straight." ' both True or both False
|
||||
ENDIF
|
||||
END
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="MCDropDown">
|
||||
<div class="MCDropDownHead_0"><a class="MCDropDownHotSpot_0" href="javascript:void(0);" id="MCDropDownHotSpot_2082691904_22" onclick="FMCDropDown( this ); return false;"><img style="border: none;margin-right: 2px;" src="../../SkinSupport/DropDownClosed.gif" MadCap:altsrc="../../SkinSupport/DropDownOpen.gif" onload="if ( typeof( FMCPreloadImage ) == 'function' ) { FMCPreloadImage( '../../SkinSupport/DropDownOpen.gif' ); }" class="MCDropDownIcon" />ATN   (Returns Arctangent of Vector (X, Y))</a>
|
||||
</div>
|
||||
<div class="MCDropDownBody" id="MCDropDownBody_2082691904_22" style="display: none;">
|
||||
<p> </p>
|
||||
<p class="PlainText"><a name="arctan"></a>The Arctangent operator (ATN) returns the angle to the vector specified by X and
|
||||
Y coordinate values. In the BASIC Stamp, the angle is returned in binary radians
|
||||
(0 to 255) instead of degrees (0 to 359). Coordinate input values are limited from
|
||||
-127 to 127 (signed bytes) as shown in the diagram below:
|
||||
</p>
|
||||
<p>
|
||||
<center>
|
||||
<img src="../../graphics/ATN_HYP.png" border="0" />
|
||||
</center>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0" />
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
idx VAR Nib ' loop counter
|
||||
xCoord VAR Byte ' x coordinate of vector
|
||||
yCoord VAR Byte ' y coordinate of vector
|
||||
brads VAR Word ' angle in brads
|
||||
degr VAR Word ' angle in degrees
|
||||
|
||||
Main:
|
||||
FOR idx = 0 TO 7 ' load vector data
|
||||
|
||||
LOOKUP idx, [ 1, 1, 0, -1, -1, -1, 0, 1], xCoord
|
||||
LOOKUP idx, [ 0, 1, 1, 1, 0, -1, -1, -1], yCoord
|
||||
|
||||
brads = xCoord ATN yCoord ' get angle of vector
|
||||
degr = brads * 180 / 128 ' convert to degrees
|
||||
|
||||
DEBUG DEC (idx + 1), ": ",
|
||||
"ATN (", SDEC xCoord, ", ", SDEC yCoord, ")",
|
||||
CRSRX, 18, "= ", DEC brads, " (", DEC degr, ")", CR
|
||||
NEXT
|
||||
END
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="MCDropDown">
|
||||
<div class="MCDropDownHead_0"><a class="MCDropDownHotSpot_0" href="javascript:void(0);" id="MCDropDownHotSpot_2082691904_23" onclick="FMCDropDown( this ); return false;"><img style="border: none;margin-right: 2px;" src="../../SkinSupport/DropDownClosed.gif" MadCap:altsrc="../../SkinSupport/DropDownOpen.gif" onload="if ( typeof( FMCPreloadImage ) == 'function' ) { FMCPreloadImage( '../../SkinSupport/DropDownOpen.gif' ); }" class="MCDropDownIcon" />HYP   (Returns Hypotenuse)</a>
|
||||
</div>
|
||||
<div class="MCDropDownBody" id="MCDropDownBody_2082691904_23" style="display: none;">
|
||||
<p> </p>
|
||||
<p><a name="hypot"></a>The Hypotenuse operator (HYP) returns the length of the hypotenuse of a right
|
||||
triangle with sides of length A and B. Side length (vector) input values are
|
||||
limited to -127 to 127 (signed bytes).</p>
|
||||
<p> </p>
|
||||
<p>
|
||||
<center>
|
||||
<img src="../../graphics/hyp.gif" border="0" />
|
||||
</center>
|
||||
</p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0" /><pre class="BScode" xml:space="preserve">
|
||||
DEBUG ? 3 HYP 4 ' display hypotenuse of 5
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
<p> </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 © <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>
|
307
help/BasicStampHelp/Content/LanguageTopics/Reference/Ops_uni.htm
Normal file
307
help/BasicStampHelp/Content/LanguageTopics/Reference/Ops_uni.htm
Normal file
@ -0,0 +1,307 @@
|
||||
<?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="PBASIC Language Reference|PBASIC Operators" 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>Unary Operators</title>
|
||||
<link href="../../SkinSupport/MadCap.css" rel="stylesheet" />
|
||||
<link href="../../Resources/Stylesheets/BSE_Help.css" rel="stylesheet" />
|
||||
<script src="../../SkinSupport/MadCapAll.js">
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="MCBreadcrumbsBox_0"><span class="MCBreadcrumbsPrefix">You are here: </span><a class="MCBreadcrumbsLink" href="AlphaRef.htm">PBASIC Language Reference</a><span class="MCBreadcrumbsDivider"> > </span><a class="MCBreadcrumbsLink" href="Operators.htm">PBASIC Operators</a><span class="MCBreadcrumbsDivider"> > </span><span class="MCBreadcrumbs">Unary Operators</span>
|
||||
</div>
|
||||
<h1>Unary Operators</h1>
|
||||
<p>
|
||||
<img src="../../graphics/pgm_icon1.gif" border="0" alt="" />
|
||||
<img src="../../graphics/pgm_icon2.gif" border="0" alt="" />
|
||||
<img src="../../graphics/pgm_icon2e.gif" border="0" alt="" />
|
||||
<img src="../../graphics/pgm_icon2sx.gif" border="0" alt="" />
|
||||
<img src="../../graphics/pgm_icon2p.gif" border="0" alt="" />
|
||||
<img src="../../graphics/pgm_icon2pe.gif" border="0" alt="" />
|
||||
<img src="../../graphics/pgm_icon2px.gif" border="0" alt="" />
|
||||
</p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Unary operators work with a single argument. Click on any operator in the list below for details and examples.</p>
|
||||
<p class="PlainText">(See also: <a href="Ops_bi.htm" target="" title="" alt="" class="MCXref_0">Binary Operators</a> and <a href="OpsPrecedence.htm" target="" title="" alt="" class="MCXref_0">Operator Precedence</a>.)</p>
|
||||
<h2>Notes about the 16-bit workspace</h2>
|
||||
<p class="PlainText">Many of the operator descriptions will say something like "computes (some function) of a 16-bit number." This does not mean that the operator does not work on smaller byte or nibble values, but rather that the computation is done in a 16-bit workspace. If the value is smaller than 16 bits, the BASIC Stamp pads it with leading 0s to make a 16-bit value. If the 16-bit result of a calculation is to be packed into a smaller variable, the higher-order bits are discarded (truncated).</p>
|
||||
<div class="MCDropDown">
|
||||
<div class="MCDropDownHead_0"><a class="MCDropDownHotSpot_0" href="javascript:void(0);" id="MCDropDownHotSpot_1311391400_0" onclick="FMCDropDown( this ); return false;"><img style="border: none;margin-right: 2px;" src="../../SkinSupport/DropDownClosed.gif" MadCap:altsrc="../../SkinSupport/DropDownOpen.gif" onload="if ( typeof( FMCPreloadImage ) == 'function' ) { FMCPreloadImage( '../../SkinSupport/DropDownOpen.gif' ); }" class="MCDropDownIcon" />ABS   (Returns Absolute Value)</a>
|
||||
</div>
|
||||
<div class="MCDropDownBody" id="MCDropDownBody_1311391400_0" style="display: none;">
|
||||
<p> </p>
|
||||
<p class="PlainText"><a name="absval"></a>The Absolute Value operator (ABS) converts a signed (two’s complement)
|
||||
16-bit number to its absolute value. The absolute value of a number is a
|
||||
positive number representing the difference between that number and 0.
|
||||
For example, the absolute value of -99 is 99. The absolute value of 99 is
|
||||
also 99. ABS works on two’s complement negative numbers. Here's an example
|
||||
of ABS at work:</p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0" alt="" /><pre class="BScode" xml:space="preserve">
|
||||
result VAR Word
|
||||
|
||||
Main:
|
||||
result = -99
|
||||
DEBUG SDEC ? result ' Display -99
|
||||
DEBUG SDEC ? ABS result ' Display 99
|
||||
END
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="MCDropDown">
|
||||
<div class="MCDropDownHead_0"><a class="MCDropDownHotSpot_0" href="javascript:void(0);" id="MCDropDownHotSpot_1311391400_1" onclick="FMCDropDown( this ); return false;"><img style="border: none;margin-right: 2px;" src="../../SkinSupport/DropDownClosed.gif" MadCap:altsrc="../../SkinSupport/DropDownOpen.gif" onload="if ( typeof( FMCPreloadImage ) == 'function' ) { FMCPreloadImage( '../../SkinSupport/DropDownOpen.gif' ); }" class="MCDropDownIcon" />-   (Negate)</a>
|
||||
</div>
|
||||
<div class="MCDropDownBody" id="MCDropDownBody_1311391400_1" style="display: none;">
|
||||
<p> </p>
|
||||
<p class="PlainText"><a name="negative"></a>The Negative operator (-) negates a 16-bit number (converts to its two’s
|
||||
complement).</p>
|
||||
<img src="../../graphics/bs1_inline.gif" border="0" alt="" /><pre class="BScode" xml:space="preserve">
|
||||
SYMBOL result = W1
|
||||
|
||||
Main:
|
||||
result = -99 ' Initialize result
|
||||
result = result + 100 ' Add 100 to it
|
||||
DEBUG result ' Display result (1)
|
||||
END
|
||||
</pre>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0" alt="" /><pre class="BScode" xml:space="preserve">
|
||||
result VAR Word
|
||||
|
||||
Main:
|
||||
result = -99 ' Initialize result
|
||||
DEBUG SDEC result ' Display result (-99)
|
||||
result = result + 100 ' Add 100 to it
|
||||
DEBUG SDEC result ' Display result (1)
|
||||
END
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="MCDropDown">
|
||||
<div class="MCDropDownHead_0"><a class="MCDropDownHotSpot_0" href="javascript:void(0);" id="MCDropDownHotSpot_1311391400_2" onclick="FMCDropDown( this ); return false;"><img style="border: none;margin-right: 2px;" src="../../SkinSupport/DropDownClosed.gif" MadCap:altsrc="../../SkinSupport/DropDownOpen.gif" onload="if ( typeof( FMCPreloadImage ) == 'function' ) { FMCPreloadImage( '../../SkinSupport/DropDownOpen.gif' ); }" class="MCDropDownIcon" />~   (Invert Bits)</a>
|
||||
</div>
|
||||
<div class="MCDropDownBody" id="MCDropDownBody_1311391400_2" style="display: none;">
|
||||
<p> </p>
|
||||
<p class="PlainText"><a name="invert"></a>The Inverse operator (~) complements (inverts) the bits of a number. Each bit that contains a 1 is changed to 0 and each bit containing 0 is changed to
|
||||
1. This process is also known as a "bitwise NOT" and one's complement.</p>
|
||||
<p class="PlainText"><span class="code_in_text">    ~0 = 1
|
||||
    ~1 = 0</span>
|
||||
</p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0" alt="" /><pre class="BScode" xml:space="preserve">
|
||||
result VAR Byte
|
||||
|
||||
Main:
|
||||
result = %11110001 ' Store bits in result
|
||||
DEBUG BIN8 ? result ' Display %11110001
|
||||
result = ~result ' Complement result
|
||||
DEBUG BIN8 ? result ' Display %00001110
|
||||
END
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="MCDropDown">
|
||||
<div class="MCDropDownHead_0"><a class="MCDropDownHotSpot_0" href="javascript:void(0);" id="MCDropDownHotSpot_1311391400_3" onclick="FMCDropDown( this ); return false;"><img style="border: none;margin-right: 2px;" src="../../SkinSupport/DropDownClosed.gif" MadCap:altsrc="../../SkinSupport/DropDownOpen.gif" onload="if ( typeof( FMCPreloadImage ) == 'function' ) { FMCPreloadImage( '../../SkinSupport/DropDownOpen.gif' ); }" class="MCDropDownIcon" />DCD   (2<sup>n</sup> power Decoder)</a>
|
||||
</div>
|
||||
<div class="MCDropDownBody" id="MCDropDownBody_1311391400_3" style="display: none;">
|
||||
<p> </p>
|
||||
<p class="PlainText"><a name="dcd"></a>The Decoder operator (DCD) is a 2<sup>n</sup>-power decoder of a four-bit
|
||||
value. DCD accepts a value from 0 to 15, and returns a 16-bit number with the
|
||||
bit, described by value, set to 1.</p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0" alt="" /><pre class="BScode" xml:space="preserve">
|
||||
result VAR Word
|
||||
|
||||
Main:
|
||||
result = DCD 12 ' Set bit 12.
|
||||
DEBUG BIN ? result ' Display %0001000000000000
|
||||
END
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="MCDropDown">
|
||||
<div class="MCDropDownHead_0"><a class="MCDropDownHotSpot_0" href="javascript:void(0);" id="MCDropDownHotSpot_1311391400_4" onclick="FMCDropDown( this ); return false;"><img style="border: none;margin-right: 2px;" src="../../SkinSupport/DropDownClosed.gif" MadCap:altsrc="../../SkinSupport/DropDownOpen.gif" onload="if ( typeof( FMCPreloadImage ) == 'function' ) { FMCPreloadImage( '../../SkinSupport/DropDownOpen.gif' ); }" class="MCDropDownIcon" />NCD   (Priority Encoder of 16-bit Value)</a>
|
||||
</div>
|
||||
<div class="MCDropDownBody" id="MCDropDownBody_1311391400_4" style="display: none;">
|
||||
<p> </p>
|
||||
<p class="PlainText"><a name="ncd"></a>The Encoder operator (NCD) is a "priority" encoder of a 16-bit value. NCD
|
||||
takes a 16-bit value, finds the highest bit containing a 1 and returns the bit
|
||||
position plus one (1 through 16). If no bit is set (the input value is 0) NCD
|
||||
returns 0. NCD is a fast way to get an answer to the question "What is the
|
||||
largest power of two that this value is greater than or equal to?" The
|
||||
value NCD returns will be that power, plus one.</p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0" alt="" /><pre class="BScode" xml:space="preserve">
|
||||
result VAR Nib
|
||||
|
||||
Main:
|
||||
result = %1101 ' Highest bit set is bit 3
|
||||
DEBUG ? NCD result ' Show the NCD of Result (4)
|
||||
END
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="MCDropDown">
|
||||
<div class="MCDropDownHead_0"><a class="MCDropDownHotSpot_0" href="javascript:void(0);" id="MCDropDownHotSpot_1311391400_5" onclick="FMCDropDown( this ); return false;"><img style="border: none;margin-right: 2px;" src="../../SkinSupport/DropDownClosed.gif" MadCap:altsrc="../../SkinSupport/DropDownOpen.gif" onload="if ( typeof( FMCPreloadImage ) == 'function' ) { FMCPreloadImage( '../../SkinSupport/DropDownOpen.gif' ); }" class="MCDropDownIcon" />SIN   (Returns signed Sine of Angle)</a>
|
||||
</div>
|
||||
<div class="MCDropDownBody" id="MCDropDownBody_1311391400_5" style="display: none;">
|
||||
<p> </p>
|
||||
<p class="PlainText"><a name="sine"></a>The Sine operator (SIN) returns the two’s complement, 16-bit Sine of an
|
||||
angle specified as an 8-bit (0 to 255) value. To understand the SIN operator
|
||||
more completely, let’s look at a typical Sine function. By definition: given a
|
||||
circle with a radius of 1 unit (known as a unit circle), the Sine is the y-coordinate
|
||||
distance from the center of the circle to its edge at a given
|
||||
angle. Angles are measured relative to the 3-o'clock position on the circle,
|
||||
increasing as you go around the circle counterclockwise.</p>
|
||||
<p class="PlainText">At the origin point (0 degrees) the Sine is 0, because that point has the
|
||||
same y (vertical) coordinate as the circle center. At 45 degrees the Sine is
|
||||
0.707. At 90 degrees, Sine is 1. At 180 degrees, Sine is 0 again. At 270
|
||||
degrees, Sine is -1.</p>
|
||||
<p class="PlainText">The BASIC Stamp SIN operator breaks the circle into 0 to 255 units instead
|
||||
of 0 to 359 degrees. Some textbooks call this unit a binary radian or brad.
|
||||
Each brad is equivalent to 1.406 degrees. And instead of a unit circle,
|
||||
which results in fractional Sine values between 0 and 1, BASIC Stamp SIN
|
||||
is based on a 127-unit circle. Results are given in two’s complement form
|
||||
in order to accommodate negative values. So, at the origin, SIN is 0. At 45
|
||||
degrees (32 brads), Sine is 90. At 90 degrees (64 brads), Sine is 127. At 180
|
||||
degrees (128 brads), Sine is 0 again. At 270 degrees (192 brads), Sine is -127.</p>
|
||||
<p class="PlainText">See the image below for the relationship between degrees and brads and how the SIN
|
||||
function values relate to to the 127-unit circle.</p>
|
||||
<p class="PlainText" style="text-align: center;">
|
||||
<img src="../../graphics/SIN_COS.png" />
|
||||
</p>
|
||||
<center> </center>
|
||||
<p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0" alt="" />
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
degr VAR Word
|
||||
sine VAR Word
|
||||
|
||||
Main:
|
||||
FOR degr = 0 TO 359 STEP 45 ' Use degrees
|
||||
sine = SIN (degr * 128 / 180) ' Convert to brads, do SIN
|
||||
DEBUG "Angle: ", DEC degr, TAB ' Display results
|
||||
DEBUG "Sine: ", SDEC sine, CR
|
||||
NEXT
|
||||
END
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="MCDropDown">
|
||||
<div class="MCDropDownHead_0"><a class="MCDropDownHotSpot_0" href="javascript:void(0);" id="MCDropDownHotSpot_1311391400_6" onclick="FMCDropDown( this ); return false;"><img style="border: none;margin-right: 2px;" src="../../SkinSupport/DropDownClosed.gif" MadCap:altsrc="../../SkinSupport/DropDownOpen.gif" onload="if ( typeof( FMCPreloadImage ) == 'function' ) { FMCPreloadImage( '../../SkinSupport/DropDownOpen.gif' ); }" class="MCDropDownIcon" />COS   (Returns signed Cosine of Angle)</a>
|
||||
</div>
|
||||
<div class="MCDropDownBody" id="MCDropDownBody_1311391400_6" style="display: none;">
|
||||
<p> </p>
|
||||
<p class="PlainText"><a name="cosine"></a>The Cosine operator (COS) returns the two’s complement, 16-bit Cosine of an
|
||||
angle specified as an 8-bit (0 to 255) value. To understand the COS operator
|
||||
more completely, let’s look at a typical Cosine function. By definition: given a
|
||||
circle with a radius of 1 unit (known as a unit circle), the Cosine is the x-coordinate
|
||||
distance from the center of the circle to its edge at a given angle. Angles are
|
||||
measured relative to the 3-o'clock position on the circle, increasing as you go
|
||||
around the circle counterclockwise.</p>
|
||||
<p class="PlainText">At the origin point (0 degrees) the Cosine is 1, because that point has the
|
||||
same x (horizontal) coordinate as the circle radius. At 45 degrees the Cosine is
|
||||
0.707. At 90 degrees, Cosine is 0. At 180 degrees, Cosine is -1. At 270
|
||||
degrees, Cosine is 0 again.</p>
|
||||
<p class="PlainText">The BASIC Stamp COS operator breaks the circle into 0 to 255 units instead
|
||||
of 0 to 359 degrees. Some textbooks call this unit a binary radian or brad.
|
||||
Each brad is equivalent to 1.406 degrees. And instead of a unit circle,
|
||||
which results in fractional Cosine values between 0 and 1, BASIC Stamp COS
|
||||
is based on a 127-unit circle. Results are given in two’s complement form
|
||||
in order to accommodate negative values. So, at the origin, COS is 127. At 45
|
||||
degrees (32 brads), COS is 90. At 90 degrees (64 brads), COS is 0. At 180
|
||||
degrees (128 brads), Cosine is -127. At 270 degrees (192 brads), Cosine is 0 again.</p>
|
||||
<p class="PlainText">See the image below for the relationship between degrees and brads and how the COS
|
||||
function values relate to to the 127-unit circle.</p>
|
||||
<center>
|
||||
<img src="../../graphics/SIN_COS.png" border="0" alt="" />
|
||||
</center>
|
||||
<p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0" alt="" />
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
degr VAR Word
|
||||
cosine VAR Word
|
||||
|
||||
Main:
|
||||
FOR degr = 0 TO 359 STEP 45 ' Use degrees
|
||||
cosine = COS (degr * 128 / 180) ' Convert to brads, do COS
|
||||
DEBUG "Angle: ", DEC degr, TAB ' Display results
|
||||
DEBUG "Cosine: ", SDEC cosine, CR
|
||||
NEXT
|
||||
END
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="MCDropDown">
|
||||
<div class="MCDropDownHead_0"><a class="MCDropDownHotSpot_0" href="javascript:void(0);" id="MCDropDownHotSpot_1311391400_7" onclick="FMCDropDown( this ); return false;"><img style="border: none;margin-right: 2px;" src="../../SkinSupport/DropDownClosed.gif" MadCap:altsrc="../../SkinSupport/DropDownOpen.gif" onload="if ( typeof( FMCPreloadImage ) == 'function' ) { FMCPreloadImage( '../../SkinSupport/DropDownOpen.gif' ); }" class="MCDropDownIcon" />SQR   (Returns Square Root of Value)</a>
|
||||
</div>
|
||||
<div class="MCDropDownBody" id="MCDropDownBody_1311391400_7" style="display: none;">
|
||||
<p> </p>
|
||||
<p class="PlainText"><a name="square"></a>The Square Root operator (SQR) computes the integer square root of an
|
||||
unsigned 16-bit number. (The number must be unsigned since the square
|
||||
root of a negative number is an 'imaginary' number.) Remember that most
|
||||
square roots have a fractional part that the BASIC Stamp discards when
|
||||
doing its integer-only math. So it computes the square root of 100 as 10
|
||||
(correct), but the square root of 99 as 9 (the actual is close to 9.95).</p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0" alt="" /><pre class="BScode" xml:space="preserve">
|
||||
Main:
|
||||
DEBUG SQR 100 ' Display 10
|
||||
DEBUG SQR 99 ' Display 9 (due to truncation)
|
||||
END
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="MCDropDown">
|
||||
<div class="MCDropDownHead_0"><a class="MCDropDownHotSpot_0" href="javascript:void(0);" id="MCDropDownHotSpot_1311391400_8" onclick="FMCDropDown( this ); return false;"><img style="border: none;margin-right: 2px;" src="../../SkinSupport/DropDownClosed.gif" MadCap:altsrc="../../SkinSupport/DropDownOpen.gif" onload="if ( typeof( FMCPreloadImage ) == 'function' ) { FMCPreloadImage( '../../SkinSupport/DropDownOpen.gif' ); }" class="MCDropDownIcon" />NOT   (Logical NOT)</a>
|
||||
</div>
|
||||
<div class="MCDropDownBody" id="MCDropDownBody_1311391400_8" style="display: none;">
|
||||
<p> </p>
|
||||
<p class="PlainText"><a name="not"></a>The NOT operator returns the logical NOT of an expression. Note that in the
|
||||
BASIC Stamp, a non-zero value is considered True (T), zero is considered
|
||||
False (F). The expression is subject to the following logic:</p>
|
||||
<p class="PlainText"><tt>  <span class="code_in_text">  NOT F = T
|
||||
    NOT T = F</span></tt>
|
||||
</p>
|
||||
<p class="PlainText">The result returned by NOT will be True or False.</p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0" alt="" /><pre class="BScode" xml:space="preserve">
|
||||
speed VAR Byte
|
||||
|
||||
Main:
|
||||
DEBUG CLS, "Enter speed: "
|
||||
DEBUGIN DEC speed
|
||||
IF NOT (speed < 65) THEN ' speed must be less than 65
|
||||
DEBUG CR, "Sorry ... too fast!"
|
||||
ELSE
|
||||
DEBUG CR, "Enjoy your trip."
|
||||
ENDIF
|
||||
END
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
<p> </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 © <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>
|
155
help/BasicStampHelp/Content/LanguageTopics/Reference/Pins.htm
Normal file
155
help/BasicStampHelp/Content/LanguageTopics/Reference/Pins.htm
Normal file
@ -0,0 +1,155 @@
|
||||
<?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="PBASIC Language Reference" 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>PIN</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>
|
||||
<div class="MCBreadcrumbsBox_0"><span class="MCBreadcrumbsPrefix">You are here: </span><a class="MCBreadcrumbsLink" href="AlphaRef.htm">PBASIC Language Reference</a><span class="MCBreadcrumbsDivider"> > </span><span class="MCBreadcrumbs">PIN Directive</span>
|
||||
</div>
|
||||
<h1 class="code">PIN</h1>
|
||||
<p>
|
||||
<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" /><span class="code_in_text">{PBASIC 2.5}</span>
|
||||
</p>
|
||||
<p class="PlainText"> </p>
|
||||
<p class="PlainText">This section discusses the <span class="keyword_in_text">PIN </span>directive available with PBASIC 2.5</p>
|
||||
<p class="PlainText">(For BASIC Stamp I/O pin definitions and ratings, see <a href="../../HardwareTopics/PinDesc.htm" target="" title="" alt="" class="MCXref_0">Pin Descriptions</a>)</p>
|
||||
<p class="PlainText">(For BS2px I/O pin commands, see <a href="../Commands/COMPARE.htm" target="" title="" alt="" class="MCXref_0">COMPARE</a> and <a href="../Commands/CONFIGPIN.htm" target="" title="" alt="" class="MCXref_0">CONFIGPIN</a>.)</p>
|
||||
<p class="PlainText">With the introduction of PBASIC 2.5 syntax comes the <span class="keyword_in_text">PIN</span> directive. The
|
||||
purpose of the <span class="keyword_in_text">PIN </span>directive is to give an alias to an I/O pin and let the
|
||||
compiler determine whether a given line of code requires a numeric value for the
|
||||
pin, the output bit for that pin, or the input bit for that pin. Using the <span class="keyword_in_text">PIN</span> directive simplifies I/O pin aliasing in sophisticated programs.</p>
|
||||
<h2>PIN Syntax</h2>
|
||||
<p class="PlainText">Syntax: <i>PIN_Symbol</i> <![CDATA[ ]]><span class="keyword_in_text">PIN</span><i>Pin_Number</i></p>
|
||||
<ul>
|
||||
<li value="1"><b><i>PIN_Symbol</i></b> is a unique symbol name that will be
|
||||
used as an alias for the I/O pin number <i>Pin_Number</i>.</li>
|
||||
<li value="2"><b><i>Pin_Number</i></b> is an I/O pin number (0 to 15)</li>
|
||||
</ul>
|
||||
<h2>Summary of PIN Behaviors in Context</h2>
|
||||
<p class="PlainText"><i>PIN_Symbol</i> behaves like a constant:</p>
|
||||
<ol>
|
||||
<li value="1">...when used in a command’s <i>Pin</i> argument. Example:</li>
|
||||
</ol><pre class="snippet">OUTPUT PIN_Symbol</pre>
|
||||
<ol MadCap:continue="true">
|
||||
<li value="2">...when used in the index of an array. Example:</li>
|
||||
</ol><pre class="snippet">myArray(PIN_Symbol) = 25</pre>
|
||||
<p class="PlainText"><i>PIN_Symbol</i> behaves like an input variable (INx):</p>
|
||||
<ol>
|
||||
<li value="1">...when used in a command’s non-Pin argument that expects to read a variable/constant/expression. Example:</li>
|
||||
</ol><pre class="snippet">DEBUG BIN PIN_Symbol</pre>
|
||||
<ol MadCap:continue="true">
|
||||
<li value="2">...when used in a command’s <i>Condition</i> argument. Example:</li>
|
||||
</ol><pre class="snippet">IF PIN_Symbol = 1 THEN…</pre>
|
||||
<ol MadCap:continue="true">
|
||||
<li value="3">...when used to the right of the equal sign (=) in an assignment statement. Example:</li>
|
||||
</ol><pre class="snippet">myVariable = PIN_Symbol + 1</pre>
|
||||
<p class="PlainText"><i>PIN_Symbol</i> behaves like an output variable (OUTx):</p>
|
||||
<ol>
|
||||
<li value="1">...when used in a command’s non-<i>Pin</i> argument that expects to write a result to a variable. Example:</li>
|
||||
</ol><pre class="snippet">LOOKUP index, [0, 1, 1, 0, 1], PIN_Symbol</pre>
|
||||
<ol MadCap:continue="true">
|
||||
<li value="2">...when used to the left of the equal sign (=) in an assignment statement. Example:</li>
|
||||
</ol><pre class="snippet">PIN_Symbol = 1</pre>
|
||||
<h2>PIN Examples</h2>
|
||||
<p class="PlainText">Using the <span class="keyword_in_text">PIN</span> declaration is similar to <span class="keyword_in_text">CON</span>:</p><pre class="BScode" xml:space="preserve">
|
||||
' {$PBASIC 2.5}
|
||||
|
||||
RedLED PIN 0 ' red LED is connected to pin 0
|
||||
|
||||
IsOn CON 1 ' LED is active high
|
||||
IsOff CON 0
|
||||
|
||||
Setup:
|
||||
OUTPUT RedLED ' same as OUTPUT 0
|
||||
|
||||
Main:
|
||||
DO
|
||||
RedLED = IsOn ' same as Out0 = 1
|
||||
PAUSE 1000
|
||||
RedLED = IsOff ' same as Out0 = 0
|
||||
PAUSE 1000
|
||||
LOOP
|
||||
</pre>
|
||||
<p class="PlainText">Most programs will work like the example above where a given I/O pin will
|
||||
either be an input or an output. There are times, however, when a change in
|
||||
function is required mid program. Prior to PBASIC 2.5, programmers wishing to
|
||||
use named constants were forced to create redundant definitions or complicated
|
||||
modifiers. For example:</p><pre class="BScode" xml:space="preserve">
|
||||
' {$PBASIC 2.0}
|
||||
|
||||
SDA CON 8 ' I2C data I/O
|
||||
SCL CON 9 ' I2C clock output
|
||||
|
||||
...
|
||||
|
||||
I2C_Start:
|
||||
INPUT SDA
|
||||
INPUT SCL
|
||||
LOW SDA
|
||||
|
||||
Clock_Hold: ' monitor device clock hold
|
||||
IF (INS.LOWBIT(SCL) = 0) THEN Clock_Hold ' <-- tricky modifiers
|
||||
RETURN
|
||||
</pre>
|
||||
<p class="PlainText">With PBASIC 2.5 the tricky modifiers can be eliminated:</p><pre class="BScode" xml:space="preserve">
|
||||
' {$PBASIC 2.5}
|
||||
|
||||
SDA PIN 8 ' I2C data I/O
|
||||
SCL PIN 9 ' I2C clock output
|
||||
|
||||
...
|
||||
|
||||
I2C_Start:
|
||||
INPUT SDA
|
||||
INPUT SCL
|
||||
LOW SDA
|
||||
|
||||
Clock_Hold: ' monitor device clock hold
|
||||
DO : LOOP WHILE (SCL = 0) ' easier, same as "IN9 = 0"
|
||||
RETURN
|
||||
</pre>
|
||||
<p class="PlainText">The compiler is "smart" and knows how to replace a <span class="keyword_in_text">PIN</span> directive with a
|
||||
constant value, an INS register bit or and OUTS register bit. Note that as in
|
||||
the example above, the programmer is still responsible for setting the DIRS bit
|
||||
of the I/O pin as required by the program.</p>
|
||||
<p class="PlainText"> </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 © <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>
|
@ -0,0 +1,828 @@
|
||||
<?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="PBASIC Language Reference" 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>Reserved Words</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>
|
||||
<div class="MCBreadcrumbsBox_0"><span class="MCBreadcrumbsPrefix">You are here: </span><a class="MCBreadcrumbsLink" href="AlphaRef.htm">PBASIC Language Reference</a><span class="MCBreadcrumbsDivider"> > </span><span class="MCBreadcrumbs">Reserved Words</span>
|
||||
</div>
|
||||
<h1>Reserved Words</h1>
|
||||
<p class="PlainText">Here are complete listings of the reserved words for PBASIC 1.0,  PBASIC 2.0, and PBASIC 2.5.  The reserved word lists have been organized into 5 tables, because it varies with each BASIC Stamp model and version of PBASIC. </p>
|
||||
<h2>
|
||||
<img src="../../graphics/bs1_inline.gif" /> BASIC Stamp 1</h2>
|
||||
<p class="PlainText">The table below shows the reserved words for the BASIC Stamp 1, using the required PBASIC 1.0.</p>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF">
|
||||
<td colspan="5" style="text-align: center;">BS1
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td width="20%">AND
|
||||
</td>
|
||||
<td width="20%">GOSUB
|
||||
</td>
|
||||
<td width="20%">N2400
|
||||
</td>
|
||||
<td width="20%">PIN0..PIN7
|
||||
</td>
|
||||
<td width="20%">SOUND
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>B0..B13
|
||||
</td>
|
||||
<td>GOTO
|
||||
</td>
|
||||
<td>NAP
|
||||
</td>
|
||||
<td>PINS
|
||||
</td>
|
||||
<td>STEP
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>BIT0..BIT15
|
||||
</td>
|
||||
<td>HIGH
|
||||
</td>
|
||||
<td>NEXT
|
||||
</td>
|
||||
<td>PORT
|
||||
</td>
|
||||
<td>SYMBOL
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>BRANCH
|
||||
</td>
|
||||
<td>IF
|
||||
</td>
|
||||
<td>ON300
|
||||
</td>
|
||||
<td>POT
|
||||
</td>
|
||||
<td>T300
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>BSAVE
|
||||
</td>
|
||||
<td>INPUT
|
||||
</td>
|
||||
<td>ON600
|
||||
</td>
|
||||
<td>PULSIN
|
||||
</td>
|
||||
<td>T600
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>BUTTON
|
||||
</td>
|
||||
<td>LET
|
||||
</td>
|
||||
<td>ON1200
|
||||
</td>
|
||||
<td>PULSOUT
|
||||
</td>
|
||||
<td>T1200
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>CLS
|
||||
</td>
|
||||
<td>LOOKDOWN
|
||||
</td>
|
||||
<td>ON2400
|
||||
</td>
|
||||
<td>PWM
|
||||
</td>
|
||||
<td>T2400
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>CR
|
||||
</td>
|
||||
<td>LOOKUP
|
||||
</td>
|
||||
<td>OR
|
||||
</td>
|
||||
<td>RANDOM
|
||||
</td>
|
||||
<td>THEN
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>DEBUG
|
||||
</td>
|
||||
<td>LOW
|
||||
</td>
|
||||
<td>OT300
|
||||
</td>
|
||||
<td>READ
|
||||
</td>
|
||||
<td>TO
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>DIR0..DIR7
|
||||
</td>
|
||||
<td>MAX
|
||||
</td>
|
||||
<td>OT600
|
||||
</td>
|
||||
<td>RETURN
|
||||
</td>
|
||||
<td>TOGGLE
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>DIRS
|
||||
</td>
|
||||
<td>MIN
|
||||
</td>
|
||||
<td>OT1200
|
||||
</td>
|
||||
<td>REVERSE
|
||||
</td>
|
||||
<td>W0..W6
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>EEPROM
|
||||
</td>
|
||||
<td>N300
|
||||
</td>
|
||||
<td>OT2400
|
||||
</td>
|
||||
<td>SERIN
|
||||
</td>
|
||||
<td>WRITE
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>END
|
||||
</td>
|
||||
<td>N600
|
||||
</td>
|
||||
<td>OUTPUT
|
||||
</td>
|
||||
<td>SEROUT
|
||||
</td>
|
||||
<td> 
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>FOR
|
||||
</td>
|
||||
<td>N1200
|
||||
</td>
|
||||
<td>PAUSE
|
||||
</td>
|
||||
<td>SLEEP
|
||||
</td>
|
||||
<td> 
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p class="PlainText"> </p>
|
||||
<h2>
|
||||
<img src="../../graphics/bs2all_inline.gif" /> All BASIC Stamp 2 models</h2>
|
||||
<p class="PlainText">The table below lists the reserved words common to all BS2 models, including those for PBASIC 2.0 and PBASIC 2.5.  Words that are only reserved when using PBASIC 2.5 are marked with (<sup>2.5</sup>).</p>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF" align="center">
|
||||
<td colspan="4">All BS2 Models
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td width="25%">#CASE<sup>2.5</sup></td>
|
||||
<td width="25%">CRSRX<sup>2.5</sup></td>
|
||||
<td width="25%">INC
|
||||
</td>
|
||||
<td width="25%">PULSIN
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>#DEFINE<sup>2.5</sup></td>
|
||||
<td>CRSRXY<sup>2.5</sup></td>
|
||||
<td>IND
|
||||
</td>
|
||||
<td>PULSOUT
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>#ELSE<sup>2.5</sup></td>
|
||||
<td>CRSRY<sup>2.5</sup></td>
|
||||
<td>INH
|
||||
</td>
|
||||
<td>PWM
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>#ENDIF<sup>2.5</sup></td>
|
||||
<td>DATA
|
||||
</td>
|
||||
<td>INL
|
||||
</td>
|
||||
<td>RANDOM
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>#ENDSELECT<sup>2.5</sup></td>
|
||||
<td>DCD
|
||||
</td>
|
||||
<td>INPUT
|
||||
</td>
|
||||
<td>RCTIME
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>#ERROR<sup>2.5</sup></td>
|
||||
<td>DEBUG
|
||||
</td>
|
||||
<td>INS
|
||||
</td>
|
||||
<td>READ
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>#IF<sup>2.5</sup></td>
|
||||
<td>DEBUGIN<sup>2.5</sup></td>
|
||||
<td>ISBIN
|
||||
</td>
|
||||
<td>REP
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>#SELECT<sup>2.5</sup></td>
|
||||
<td>DEC
|
||||
</td>
|
||||
<td>ISBIN1...ISBIN16
|
||||
</td>
|
||||
<td>RETURN
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>#THEN<sup>2.5</sup></td>
|
||||
<td>DEC1...DEC5
|
||||
</td>
|
||||
<td>ISHEX
|
||||
</td>
|
||||
<td>REV
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>$PBASIC
|
||||
</td>
|
||||
<td>DIG
|
||||
</td>
|
||||
<td>ISHEX1...ISHEX4
|
||||
</td>
|
||||
<td>REVERSE
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>$PORT
|
||||
</td>
|
||||
<td>DIM
|
||||
</td>
|
||||
<td>LF<sup>2.5</sup></td>
|
||||
<td>SBIN
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>$STAMP
|
||||
</td>
|
||||
<td>DIR0...DIR15
|
||||
</td>
|
||||
<td>LIGHTSON
|
||||
</td>
|
||||
<td>SBIN1...SBIN16
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>ABS
|
||||
</td>
|
||||
<td>DIRA
|
||||
</td>
|
||||
<td>LOOKDOWN
|
||||
</td>
|
||||
<td>SDEC
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>AND
|
||||
</td>
|
||||
<td>DIRB
|
||||
</td>
|
||||
<td>LOOKUP
|
||||
</td>
|
||||
<td>SDEC1...SDEC5
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>ASC
|
||||
</td>
|
||||
<td>DIRC
|
||||
</td>
|
||||
<td>LOOP<sup>2.5</sup></td>
|
||||
<td>SELECT<sup>2.5</sup></td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>ATN
|
||||
</td>
|
||||
<td>DIRD
|
||||
</td>
|
||||
<td>LOW
|
||||
</td>
|
||||
<td>SERIN
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>B0...B25
|
||||
</td>
|
||||
<td>DIRH
|
||||
</td>
|
||||
<td>LOWBIT
|
||||
</td>
|
||||
<td>SEROUT
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>BELL
|
||||
</td>
|
||||
<td>DIRL
|
||||
</td>
|
||||
<td>LOWBYTE
|
||||
</td>
|
||||
<td>SHEX
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>BIN
|
||||
</td>
|
||||
<td>DIRS
|
||||
</td>
|
||||
<td>LOWNIB
|
||||
</td>
|
||||
<td>SHEX1...SHEX4
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>BIN1...BIN16
|
||||
</td>
|
||||
<td>DO<sup>2.5</sup></td>
|
||||
<td>LSBFIRST
|
||||
</td>
|
||||
<td>SHIFTIN
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>BIT
|
||||
</td>
|
||||
<td>DTMFOUT
|
||||
</td>
|
||||
<td>LSBPOST
|
||||
</td>
|
||||
<td>SHIFTOUT
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>BIT0...BIT15
|
||||
</td>
|
||||
<td>ELSE<sup>2.5</sup></td>
|
||||
<td>LSBPRE
|
||||
</td>
|
||||
<td>SIN
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>BKSP
|
||||
</td>
|
||||
<td>ELSEIF<sup>2.5</sup></td>
|
||||
<td>MAX
|
||||
</td>
|
||||
<td>SKIP
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>BRANCH
|
||||
</td>
|
||||
<td>END
|
||||
</td>
|
||||
<td>MIN
|
||||
</td>
|
||||
<td>SLEEP
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>BRIGHT
|
||||
</td>
|
||||
<td>ENDIF<sup>2.5</sup></td>
|
||||
<td>MSBFIRST
|
||||
</td>
|
||||
<td>SNUM
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>BS1
|
||||
</td>
|
||||
<td>ENDSELECT<sup>2.5</sup></td>
|
||||
<td>MSBPOST
|
||||
</td>
|
||||
<td>SQR
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>BS2
|
||||
</td>
|
||||
<td>EXIT<sup>2.5</sup></td>
|
||||
<td>MSBPRE
|
||||
</td>
|
||||
<td>STEP
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>BS2E
|
||||
</td>
|
||||
<td>FOR
|
||||
</td>
|
||||
<td>NAP
|
||||
</td>
|
||||
<td>STOP
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>BS2P
|
||||
</td>
|
||||
<td>FREQOUT
|
||||
</td>
|
||||
<td>NCD
|
||||
</td>
|
||||
<td>STR
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>BS2PE
|
||||
</td>
|
||||
<td>GOSUB
|
||||
</td>
|
||||
<td>NEXT
|
||||
</td>
|
||||
<td>TAB
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>BS2SX
|
||||
</td>
|
||||
<td>GOTO
|
||||
</td>
|
||||
<td>NIB
|
||||
</td>
|
||||
<td>THEN
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>BUTTON
|
||||
</td>
|
||||
<td>HEX
|
||||
</td>
|
||||
<td>NIB0...NIB3
|
||||
</td>
|
||||
<td>TO
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>BYTE
|
||||
</td>
|
||||
<td>HEX1...HEX4
|
||||
</td>
|
||||
<td>NOT
|
||||
</td>
|
||||
<td>TOGGLE
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>BYTE0
|
||||
</td>
|
||||
<td>HIGH
|
||||
</td>
|
||||
<td>NUM
|
||||
</td>
|
||||
<td>UNITOFF
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>BYTE1
|
||||
</td>
|
||||
<td>HIGHBIT
|
||||
</td>
|
||||
<td>ON<sup>2.5</sup></td>
|
||||
<td>UNITON
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>CASE<sup>2.5</sup></td>
|
||||
<td>HIGHBYTE
|
||||
</td>
|
||||
<td>OR
|
||||
</td>
|
||||
<td>UNITSOFF
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>CLRDN<sup>2.5</sup></td>
|
||||
<td>HIGHNIB
|
||||
</td>
|
||||
<td>OUT0...OUT15
|
||||
</td>
|
||||
<td>UNTIL<sup>2.5</sup></td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>CLREOL<sup>2.5</sup></td>
|
||||
<td>HOME
|
||||
</td>
|
||||
<td>OUTA
|
||||
</td>
|
||||
<td>VAR
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>CLS
|
||||
</td>
|
||||
<td>HYP
|
||||
</td>
|
||||
<td>OUTB
|
||||
</td>
|
||||
<td>W0...W12
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>CON
|
||||
</td>
|
||||
<td>IBIN
|
||||
</td>
|
||||
<td>OUTC
|
||||
</td>
|
||||
<td>WAIT
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>COS
|
||||
</td>
|
||||
<td>IBIN1...IBIN16
|
||||
</td>
|
||||
<td>OUTD
|
||||
</td>
|
||||
<td>WAITSTR
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>COUNT
|
||||
</td>
|
||||
<td>IF
|
||||
</td>
|
||||
<td>OUTH
|
||||
</td>
|
||||
<td>WHILE<sup>2.5</sup></td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>CR
|
||||
</td>
|
||||
<td>IHEX
|
||||
</td>
|
||||
<td>OUTL
|
||||
</td>
|
||||
<td>WORD
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>CRSRDN<sup>2.5</sup></td>
|
||||
<td>IHEX1...IHEX4
|
||||
</td>
|
||||
<td>OUPUT
|
||||
</td>
|
||||
<td>WRITE
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>CRSRLF<sup>2.5</sup></td>
|
||||
<td>IN0...IN15
|
||||
</td>
|
||||
<td>OUTS
|
||||
</td>
|
||||
<td>XOR
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>CRSRRT<sup>2.5</sup></td>
|
||||
<td>INA
|
||||
</td>
|
||||
<td>PAUSE
|
||||
</td>
|
||||
<td>XOUT
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>CRSRUP<sup>2.5</sup></td>
|
||||
<td>INB
|
||||
</td>
|
||||
<td>PIN<sup>2.5</sup></td>
|
||||
<td> 
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p class="PlainText"> </p>
|
||||
<h2>
|
||||
<img src="../../graphics/bs2esxOnly_inline.gif" /> BS2e and BS2sx</h2>
|
||||
<p class="PlainText">The BS2e and BS2sx have all the reserved words shown in the All BASIC Stamp 2 Modules table, above, plus those shown in the table below.  These additional words are reserved in both PBASIC 2.0 and PBASIC 2.5.</p>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF" align="center">
|
||||
<td colspan="3">BS2e and BS2sx
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td width="33%">GET
|
||||
</td>
|
||||
<td width="34%">PUT
|
||||
</td>
|
||||
<td width="33%">RUN
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p class="PlainText"> </p>
|
||||
<h2>
|
||||
<img src="../../graphics/bs2ppeOnly_inline.gif" /> BS2p and BS2pe</h2>
|
||||
<p class="PlainText">The BS2p and BS2pe have all the reserved words shown in the All BASIC Stamp 2 Modules table, above, plus those shown in the table below.  These additional words are reserved in both PBASIC 2.0 and PBASIC 2.5.</p>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF" align="center">
|
||||
<td colspan="4">BS2p and BS2pe
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td width="25%">AUXIO
|
||||
</td>
|
||||
<td width="25%">LCDCMD
|
||||
</td>
|
||||
<td width="25%">OWOUT
|
||||
</td>
|
||||
<td width="25%">POLLWAIT
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>GET
|
||||
</td>
|
||||
<td>LCDIN
|
||||
</td>
|
||||
<td>POLLIN
|
||||
</td>
|
||||
<td>PUT
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>I2CIN
|
||||
</td>
|
||||
<td>LCDOUT
|
||||
</td>
|
||||
<td>POLLMODE
|
||||
</td>
|
||||
<td>RUN
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>I2COUT
|
||||
</td>
|
||||
<td>MAINIO
|
||||
</td>
|
||||
<td>POLLOUT
|
||||
</td>
|
||||
<td>SPSTR
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>IOTERM
|
||||
</td>
|
||||
<td>OWIN
|
||||
</td>
|
||||
<td>POLLRUN
|
||||
</td>
|
||||
<td>STORE
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p> </p>
|
||||
<h2>
|
||||
<img src="../../graphics/bs2px_inline.gif" /> BS2px</h2>
|
||||
<p class="PlainText">The BS2px has all the reserved words shown in the All BASIC Stamp 2 Modules table, above, plus those shown in the table below.  These additional words are reserved in both PBASIC 2.0 and PBASIC 2.5.</p>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF" align="center">
|
||||
<td colspan="4">BS2px
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td width="25%">AUXIO
|
||||
</td>
|
||||
<td width="25%">IOTERM
|
||||
</td>
|
||||
<td width="25%">POLLIN
|
||||
</td>
|
||||
<td width="25%">RUN
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>COMPARE
|
||||
</td>
|
||||
<td>LCDCMD
|
||||
</td>
|
||||
<td>POLLMODE
|
||||
</td>
|
||||
<td>SCHMITT
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>CONFIGPIN
|
||||
</td>
|
||||
<td>LCDIN
|
||||
</td>
|
||||
<td>POLLOUT
|
||||
</td>
|
||||
<td>SPSTR
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>DIRECTION
|
||||
</td>
|
||||
<td>LCDOUT
|
||||
</td>
|
||||
<td>POLLRUN
|
||||
</td>
|
||||
<td>STORE
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>GET
|
||||
</td>
|
||||
<td>MAINIO
|
||||
</td>
|
||||
<td>POLLWAIT
|
||||
</td>
|
||||
<td>THRESHOLD
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>I2CIN
|
||||
</td>
|
||||
<td>OWIN
|
||||
</td>
|
||||
<td>PULLUP
|
||||
</td>
|
||||
<td> 
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>I2COUT
|
||||
</td>
|
||||
<td>OWOUT
|
||||
</td>
|
||||
<td>PUT
|
||||
</td>
|
||||
<td> 
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p> </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 © <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>
|
@ -0,0 +1,386 @@
|
||||
<?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="PBASIC Language Reference" 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>Variables</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>
|
||||
<div class="MCBreadcrumbsBox_0"><span class="MCBreadcrumbsPrefix">You are here: </span><a class="MCBreadcrumbsLink" href="AlphaRef.htm">PBASIC Language Reference</a><span class="MCBreadcrumbsDivider"> > </span><span class="MCBreadcrumbs">Variables</span>
|
||||
</div>
|
||||
<h1>Variables</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;"> </p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p>(See also: <a href="MemoryOrg.htm" target="" title="" alt="" class="MCXref_0">Memory Organization </a>)</p>
|
||||
<h2>Defining and Using Variables</h2>
|
||||
<p class="PlainText">Before you can use a variable in a PBASIC program you must declare it.
|
||||
"Declare" means letting the BASIC Stamp know that you plan to use a variable,
|
||||
what you want to call it, and how big it is. Although PBASIC does have predefined
|
||||
variables that you can use without declaring them first (see <a href="MemoryOrg.htm" target="" title="" alt="" class="MCXref_0">Memory Organization </a>),
|
||||
the preferred way to set up variables is to use the directive <span class="keyword_in_text">SYMBOL</span> (for the BS1)
|
||||
or <span class="keyword_in_text">VAR</span> (for all other BASIC Stamp models). Here is the syntax for a variable declaration:</p>
|
||||
<p>
|
||||
<img align="absmiddle" src="../../graphics/bs1_inline.gif" border="0" />
|
||||
</p><pre xml:space="preserve">
|
||||
SYMBOL name = RegisterName
|
||||
</pre>
|
||||
<p>
|
||||
<img align="absmiddle" src="../../graphics/bs2all_inline.gif" border="0" />
|
||||
</p><pre xml:space="preserve">
|
||||
name VAR VarType
|
||||
</pre>
|
||||
<p class="PlainText">...where <i>name</i> is the name by which you will refer to the variable,
|
||||
<i>RegisterName</i> is the "fixed" name for the register and <i>VarType</i> indicates
|
||||
the type (Bit, Nib, Byte, or Word) of storage for the variable. NOTE: The top
|
||||
example is for the BS1 and the bottom example is for all BASIC Stamp 2 models.</p>
|
||||
<h2>The Rules of Symbol Names</h2>
|
||||
<p class="PlainText">There are certain rules regarding symbol names. Symbols must start with a
|
||||
letter, can contain a mixture of letters, numbers, and underscore (_) characters,
|
||||
and must not be the same as PBASIC keywords or labels used in your program.
|
||||
Additionally, symbols can be up to 32 characters long. See the <a href="AlphaRef.htm" target="" title="" alt="" class="MCXref_0">PBASIC Command Reference</a> for a list of PBASIC keywords. PBASIC
|
||||
does not distinguish between upper and lower case, so the names MYVARIABLE,
|
||||
myVariable, and MyVaRiAbLe are all equivalent.</p>
|
||||
<p class="PlainText">Refer to the <a href="ElementsStyle.htm" target="" title="" alt="" class="MCXref_0">Elements of PBASIC Style</a> for
|
||||
suggested guidelines on naming variables.</p>
|
||||
<p>
|
||||
<img align="absmiddle" src="../../graphics/bs1_inline.gif" border="0" />
|
||||
</p>
|
||||
<p class="PlainText">For the BS1, the <i>RegisterName</i> is one of the predefined "fixed" variable
|
||||
names, such as W0, W1, B0, B1, etc. Here are a few examples of variable
|
||||
declarations on the BS1:</p><pre class="BScode" xml:space="preserve">
|
||||
SYMBOL temp = W0 ' value can be 0 to 65535
|
||||
SYMBOL cntr = B1 ' value can be 0 to 255
|
||||
SYMBOL result = B2 ' value can be 0 to 255
|
||||
</pre>
|
||||
<p class="PlainText">The above example will create a variable called <i>temp</i> whose contents
|
||||
will be stored in the RAM location called W0. Also, the variable <i>cntr</i>will be located at RAM location B1 and <i>result</i> at location B2. Note that
|
||||
<i>temp</i> is a word-sized variable (because that's what size W0 is) while the
|
||||
other two are both byte-sized variables. Throughout the rest of the program, we
|
||||
can use the names <i>temp</i>, <i>cntr</i>, and <i>result</i> instead of W0, B1
|
||||
and B2, respectively. This makes the code much more readable; it's easier to
|
||||
determine what <i>cntr</i> is used for than it would be to figure out what the
|
||||
name B1 means. Please note, that <i>cntr</i> resides at location B1, and B1
|
||||
happens to be the high byte of W0. This means than changing <i>cntr</i> will also
|
||||
change <i>temp</i> since they overlap. A situation like this usually is a mistake
|
||||
and results in strange behavior, but is also a powerful feature if used carefully.</p>
|
||||
<p>
|
||||
<img align="absmiddle" src="../../graphics/bs2all_inline.gif" border="0" />
|
||||
</p>
|
||||
<p class="PlainText">For the BS2-family, the Size argument has four choices: 1) Bit (1 bit),
|
||||
2) Nib (nibble; 4 bits), 3) Byte (8 bits), and 4) Word (16 bits). Here are some
|
||||
examples of variable declarations on the BS2-family:</p><pre class="BScode" xml:space="preserve">
|
||||
mouse VAR Bit ' Value can be 0 or 1
|
||||
cat VAR Nib ' Value can be 0 to 15
|
||||
dog VAR Byte ' Value can be 0 to 255
|
||||
rhino VAR Word ' Value can be 0 to 65535
|
||||
</pre>
|
||||
<p class="PlainText">The example above will create a bit-sized variable called <i>mouse</i>, and
|
||||
nibble-sized variable called <i>cat</i>, a byte-size variable called <i>dog</i>
|
||||
and a word-sized variable called <i>rhino</i>. Unlike in the BS1, these variable
|
||||
declarations don't point to a specific location in RAM. Instead, we only specified
|
||||
the desired size for each variable; the BASIC Stamp will arrange them in RAM as
|
||||
it sees fit. Throughout the rest of the program, we can use the names <i>mouse, cat,
|
||||
dog</i> and <i>rhino</i> to set or retrieve the contents of these variables.</p>
|
||||
<p>
|
||||
<img src="../../graphics/bs1_inline.gif" />
|
||||
<img align="absmiddle" src="../../graphics/bs2all_inline.gif" border="0" />
|
||||
</p>
|
||||
<p class="PlainText">A variable should be given the smallest size that will hold the largest value
|
||||
that will ever be stored in it. If you need a variable to hold the on/off status
|
||||
(1 or 0) of switch, use a bit. If you need a counter for a <span class="keyword_in_text">FOR...NEXT</span> loop
|
||||
that will count from 1 to 100, use a byte. And so on.</p>
|
||||
<p class="PlainText">If you assign a value to a variable that exceeds its size, the excess bits will
|
||||
be lost. For example, suppose you use the nibble variable <i>cat</i>, from the
|
||||
example above, and write cat = 260 (%100000100 binary). What will <i>cat</i>contain? It will hold only the lowest 4 bits of 260: %0100 (4 decimal).</p>
|
||||
<p>
|
||||
<img align="absmiddle" src="../../graphics/bs2all_inline.gif" border="0" />
|
||||
</p>
|
||||
<p class="PlainText">On the BS2-family, you can also define multi-part variables called arrays. An
|
||||
array is a group of variables of the same size, and sharing a single name, but
|
||||
broken up into numbered cells, called elements. You can define an array using the
|
||||
following syntax:</p><pre xml:space="preserve">
|
||||
name VAR Size(n)
|
||||
</pre>
|
||||
<p class="PlainText">where <i>name</i> and Size are the same as described earlier. The new argument,
|
||||
(n), tells PBASIC how many elements you want the array to have. For example:</p><pre class="BScode" xml:space="preserve">
|
||||
myList VAR Byte(10) ' Create a 10-byte array
|
||||
</pre>
|
||||
<p class="PlainText">Once an array is defined, you can access its elements by number. Numbering
|
||||
starts at 0 and ends at n–1. For example:</p><pre class="BScode" xml:space="preserve">
|
||||
myList(3) = 57
|
||||
DEBUG ? myList(3)
|
||||
</pre>
|
||||
<p class="PlainText">This code will display "myList(3) = 57" on the PC screen. The real power
|
||||
of arrays is that the index value can be a variable itself. For example:</p><pre class="BScode" xml:space="preserve">
|
||||
myBytes VAR Byte(10) ' Define 10-byte array
|
||||
idx VAR Nib ' Define nibble variable
|
||||
|
||||
Main:
|
||||
FOR idx = 0 TO 9 ' Repeat with idx= 0, 1...9
|
||||
myBytes(idx) = idx * 13 ' Write idx*13 to array
|
||||
NEXT
|
||||
|
||||
FOR idx = 0 TO 9 ' Repeat with idx= 0, 1...9
|
||||
DEBUG "myBytes(", DEC idx, ")= ", DEC myBytes(idx), CR ' Show contents of each cell
|
||||
NEXT
|
||||
STOP
|
||||
</pre>
|
||||
<p class="PlainText">If you run this program, <span class="keyword_in_text">DEBUG</span> will display each of the 10 values stored
|
||||
in the elements of the array: myBytes(0) = 0 * 13 = 0, myBytes(1) = 1 * 13 = 13,
|
||||
myBytes(2) = 2 * 13 = 26 ... myBytes(9) = 9 * 13 = 117.</p>
|
||||
<p class="PlainText">A word of caution about arrays: If you're familiar with other BASICs and have
|
||||
used their arrays, you have probably run into the "subscript out of range" error.
|
||||
Subscript is another term for the index value. It is out-of-range when it exceeds
|
||||
the maximum value for the size of the array. For instance, in the example above,
|
||||
<i>myBytes</i> is a 10-cell array. Allowable index numbers are 0 through 9. If
|
||||
your program exceeds this range, PBASIC will not respond with an error message.
|
||||
Instead, it will access the next RAM location past the end of the array. If you
|
||||
are not careful about this, it can cause all sorts of bugs.</p>
|
||||
<p class="PlainText">If accessing an out-of-range location is bad, why does PBASIC allow it? Unlike
|
||||
a desktop computer, the BASIC Stamp doesn't always have a display device connected
|
||||
to it for displaying error messages. So it just continues the best way it knows
|
||||
how. It's up to the programmer (you!) to prevent bugs.</p>
|
||||
<p class="PlainText">Another unique property of PBASIC arrays is this: You can refer to the 0th
|
||||
(first) cell of the array by using just the array's name without an index value.
|
||||
For example:</p>
|
||||
<p>
|
||||
<img align="absmiddle" src="../../graphics/bs2all_inline.gif" border="0" />
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
myBytes VAR Byte(10) ' Define 10-byte array
|
||||
|
||||
Main:
|
||||
myBytes(0) = 17 ' Store 17 to 0th (first) cell
|
||||
DEBUG ? myBytes(0) ' Display contents of 0th cell
|
||||
DEBUG ? myBytes ' Also displays contents of 0th cell
|
||||
</pre>
|
||||
<p class="PlainText">This feature is how the "string" capabilities of the <span class="keyword_in_text">DEBUG</span> and <span class="keyword_in_text">SEROUT</span> command expect to work, that is, referencing the variable name only and not a specific
|
||||
element. A string is simply a byte array used to store text. See the "<a href="../Commands/DEBUG.htm#Displayi">Displaying
|
||||
Strings (Byte Arrays)</a>" section in the <a href="../Commands/DEBUG.htm" target="" title="" alt="" class="MCXref_0">DEBUG</a> command
|
||||
description for more information.</p>
|
||||
<p class="PlainText">An <i><b>alias</b></i> is an alternative name for an existing variable. For
|
||||
example:</p>
|
||||
<p>
|
||||
<img align="absmiddle" src="../../graphics/bs1_inline.gif" border="0" />
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
SYMBOL cat = B0 ' Create a byte-sized variable
|
||||
SYMBOL tabby = cat ' Create alias for cat
|
||||
</pre>
|
||||
<p>
|
||||
<img align="absmiddle" src="../../graphics/bs2all_inline.gif" border="0" />
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
cat VAR Byte ' Create a byte-sized variable
|
||||
tabby VAR cat ' Create alias for cat
|
||||
</pre>
|
||||
<p class="PlainText">In this example, <i>tabby</i> is an alias to the variable <i>cat</i>. Anything
|
||||
stored in <i>cat</i> shows up in <i>tabby</i> and vice versa. Both names refer to
|
||||
the same physical piece of RAM. This kind of alias can be useful when you want to
|
||||
reuse a temporary variable in different places in your program, but also want the
|
||||
variable's name to reflect its function in each place. Use caution, because it is
|
||||
easy to forget about the aliases; during debugging, you might end up asking 'How
|
||||
did that value get here?!' The answer is that it was stored in the variable's
|
||||
alias.</p>
|
||||
<p>
|
||||
<img align="absmiddle" src="../../graphics/bs2all_inline.gif" border="0" />
|
||||
</p>
|
||||
<p class="PlainText">On the BS2-family an alias can also serve as a window into a portion of another
|
||||
variable. This is done using "modifiers." Here the alias is assigned with a
|
||||
modifier that specifies what part:</p><pre class="BScode" xml:space="preserve">
|
||||
rhino VAR Word ' A 16-bit variable
|
||||
head VAR rhino.HIGHBYTE ' Highest 8 bits of rhino
|
||||
tail VAR rhino.LOWBYTE ' Lowest 8 bits of rhino
|
||||
</pre>
|
||||
<p class="PlainText">Given that example, if you write the value %1011000011111101 to <i>rhino</i>,
|
||||
then <i>head</i> would contain %10110000 and <i>tail</i> would contain %11111101.</p>
|
||||
<p class="PlainText">The table below lists all the variable modifiers. PBASIC2 lets you apply these
|
||||
modifiers to any variable name and to combine them in any fashion that makes sense.
|
||||
For example, it will allow:</p><pre class="BScode" xml:space="preserve">
|
||||
rhino VAR Word ' A 16-bit variable
|
||||
eye VAR rhino.HIGHBYTE.LOWNIB.BIT1 ' A bit
|
||||
</pre>
|
||||
<p>
|
||||
<center>
|
||||
<table cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF" align="center" valign="top">
|
||||
<td width="80">Symbol</td>
|
||||
<td width="260">Definitions</td>
|
||||
</tr>
|
||||
<tr valign="MIDDLE">
|
||||
<td align="CENTER">LOWBYTE</td>
|
||||
<td> Low byte of a word</td>
|
||||
</tr>
|
||||
<tr valign="MIDDLE">
|
||||
<td align="CENTER">HIGHBYTE</td>
|
||||
<td> High byte of a word</td>
|
||||
</tr>
|
||||
<tr valign="MIDDLE">
|
||||
<td align="CENTER">BYTE0</td>
|
||||
<td> Low byte of a word</td>
|
||||
</tr>
|
||||
<tr valign="MIDDLE">
|
||||
<td align="CENTER">BYTE1</td>
|
||||
<td> High byte of a word</td>
|
||||
</tr>
|
||||
<tr valign="MIDDLE">
|
||||
<td align="CENTER">LOWNIB</td>
|
||||
<td> Low nibble of a word or byte</td>
|
||||
</tr>
|
||||
<tr valign="MIDDLE">
|
||||
<td align="CENTER">HIGHNIB</td>
|
||||
<td> High nibble of a word or byte</td>
|
||||
</tr>
|
||||
<tr valign="MIDDLE">
|
||||
<td align="CENTER">NIB0</td>
|
||||
<td> Nibble 0 of a word or byte</td>
|
||||
</tr>
|
||||
<tr valign="MIDDLE">
|
||||
<td align="CENTER">NIB1</td>
|
||||
<td> Nibble 1 of a word or byte</td>
|
||||
</tr>
|
||||
<tr valign="MIDDLE">
|
||||
<td align="CENTER">NIB2</td>
|
||||
<td> Nibble 2 of a word</td>
|
||||
</tr>
|
||||
<tr valign="MIDDLE">
|
||||
<td align="CENTER">NIB3</td>
|
||||
<td> Nibble 3 of a word</td>
|
||||
</tr>
|
||||
<tr valign="MIDDLE">
|
||||
<td align="CENTER">LOWBIT</td>
|
||||
<td> Low bit (LSB) of a word, byte, or nibble</td>
|
||||
</tr>
|
||||
<tr valign="MIDDLE">
|
||||
<td align="CENTER">HIGHBIT</td>
|
||||
<td> High bit (MSB) of a word, byte, or nibble</td>
|
||||
</tr>
|
||||
<tr valign="MIDDLE">
|
||||
<td align="CENTER">BIT0</td>
|
||||
<td> Bit 0 (LSB) of a word, byte, or nibble</td>
|
||||
</tr>
|
||||
<tr valign="MIDDLE">
|
||||
<td align="CENTER">BIT1</td>
|
||||
<td> Bit 1 of a word, byte, or nibble</td>
|
||||
</tr>
|
||||
<tr valign="MIDDLE">
|
||||
<td align="CENTER">BIT2</td>
|
||||
<td> Bit 2 of a word, byte, or nibble</td>
|
||||
</tr>
|
||||
<tr valign="MIDDLE">
|
||||
<td align="CENTER">BIT3</td>
|
||||
<td> Bit 3 of a word, byte, or nibble</td>
|
||||
</tr>
|
||||
<tr valign="MIDDLE">
|
||||
<td align="CENTER">BIT4 ... BIT7</td>
|
||||
<td> Bits 4 through 7 of a word or byte</td>
|
||||
</tr>
|
||||
<tr valign="MIDDLE">
|
||||
<td align="CENTER">BIT8 ... BIT15</td>
|
||||
<td> Bits 8 through 15 of a word</td>
|
||||
</tr>
|
||||
</table>
|
||||
</center>
|
||||
</p>
|
||||
<p> </p>
|
||||
<p class="PlainText">The commonsense rule for combining modifiers is that they must get progressively
|
||||
smaller from left to right. It would make no sense to specify, for instance, the
|
||||
low byte of a nibble, because a nibble is smaller than a byte! And just because
|
||||
you can stack up modifiers doesn't mean that you should unless it is the clearest
|
||||
way to express the location of the part you want get at. The example above might
|
||||
be improved:</p><pre class="BScode" xml:space="preserve">
|
||||
rhino VAR Word ' A 16-bit variable
|
||||
eye VAR rhino.BIT9 ' A bit
|
||||
</pre>
|
||||
<p class="PlainText">Although we've only discussed variable modifiers in terms of creating alias
|
||||
variables, you can also use them within program instructions:</p><pre class="BScode" xml:space="preserve">
|
||||
rhino VAR Word ' A 16-bit variable
|
||||
head VAR rhino.HIGHBYTE ' Highest 8 bits of rhino
|
||||
|
||||
Main:
|
||||
rhino = 13567
|
||||
DEBUG ? head ' Show the value of alias variable head
|
||||
DEBUG ? rhino.HIGHBYTE ' rhino.HIGHBYTE works too
|
||||
STOP
|
||||
</pre>
|
||||
<p class="PlainText">Modifiers also work with arrays. For example:</p><pre class="BScode" xml:space="preserve">
|
||||
myBytes VAR Byte(10) ' Define 10-byte array
|
||||
|
||||
Main:
|
||||
myBytes(0) = $AB ' Hex $AB into 0th byte
|
||||
DEBUG HEX ? myBytes.LOWNIB(0) ' Show low nib ($B)
|
||||
DEBUG HEX ? myBytes.LOWNIB(1) ' Show high nib ($A)
|
||||
</pre>
|
||||
<p class="PlainText">If you looked closely at that example, you probably thought it was a misprint.
|
||||
Shouldn't myBytes.LowNib(1) give you the low nibble of byte 1 of the array rather
|
||||
than the high nibble of byte 0? Well, it doesn't. The modifier changes the meaning
|
||||
of the index value to match its own size. In the example above, when myBytes() is
|
||||
addressed as a byte array, it has 10 byte-sized cells numbered 0 through 9. When
|
||||
it is addressed as a nibble array, using myBytes.LowNib(), it has 20 nibble-sized
|
||||
cells numbered 0 through 19. You could also address it as individual bits using
|
||||
myBytes.LowBit(), in which case it would have 80 bit-sized cells numbered 0
|
||||
through 79.</p>
|
||||
<p class="PlainText">What if you use something other than a “low” modifier, say myBytes.HighNib()?
|
||||
That will work, but its effect will be to start the nibble array with the high
|
||||
nibble of myBytes(0). The nibbles you address with this nib array will all be
|
||||
contiguous, one right after the other, as in the previous example.</p><pre class="BScode" xml:space="preserve">
|
||||
myBytes VAR Byte(10) ' Define 10-byte array
|
||||
|
||||
Main:
|
||||
myBytes(0) = $AB ' Hex $AB into 0th byte
|
||||
myBytes(1) = $CD ' Hex $CD into next byte
|
||||
DEBUG HEX ? myBytes.HIGHNIB(0) ' Show high nib of cell 0 ($A)
|
||||
DEBUG HEX ? myBytes.HIGHNIB(1) ' Show next nib ($D)
|
||||
</pre>
|
||||
<p class="PlainText">This property of modified arrays makes the names a little confusing. If you
|
||||
prefer, you can use the less-descriptive versions of the modifier names; Bit0
|
||||
instead of LowBit, Nib0 instead of LowNib, and Byte0 instead of LowByte. These
|
||||
have exactly the same effect, but may be less likely to be misconstrued.</p>
|
||||
<p class="PlainText">You may also use modifiers with the 0th cell of an array by referring to just
|
||||
the array name without the index value in parentheses. It's fair game for aliases
|
||||
and modifiers, both in <span class="keyword_in_text">VAR </span>directives and in instructions.</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 © <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>
|
Reference in New Issue
Block a user