194 lines
11 KiB
HTML
194 lines
11 KiB
HTML
|
<?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>RUN</title>
|
|||
|
<link href="../../SkinSupport/MadCap.css" rel="stylesheet" />
|
|||
|
<link href="../../Resources/Stylesheets/BSE_Help.css" rel="stylesheet" />
|
|||
|
<script src="../../SkinSupport/MadCapAll.js" type="text/javascript">
|
|||
|
</script>
|
|||
|
</head>
|
|||
|
<body>
|
|||
|
<h1 class="code">RUN</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;"><a href="../ExampleTopics/RunEx.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">RUN Example</a>
|
|||
|
</p>
|
|||
|
<p> </p>
|
|||
|
</div>
|
|||
|
<p class="clear"> </p>
|
|||
|
<p> </p>
|
|||
|
<p class="PlainText">Syntax: <span class="keyword_in_text">RUN</span> <![CDATA[ ]]><i>ProgramSlot</i></p>
|
|||
|
<h2>Function</h2>
|
|||
|
<p class="PlainText">Switches execution to another BASIC Stamp program (in a different program slot).
|
|||
|
|
|||
|
</p>
|
|||
|
<ul>
|
|||
|
<li value="1"><b><i>ProgramSlot</i></b> is a variable/constant/expression (0 – 7) that
|
|||
|
specifies the program slot to run.</li>
|
|||
|
</ul>
|
|||
|
<h2>Quick Facts</h2>
|
|||
|
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
|||
|
<tr>
|
|||
|
<td width="20%" align="center" bgcolor="#CFCFCF"> </td>
|
|||
|
<td width="16%" align="center" bgcolor="#CFCFCF">BS2e</td>
|
|||
|
<td width="16%" align="center" bgcolor="#CFCFCF">BS2sx</td>
|
|||
|
<td width="16%" align="center" bgcolor="#CFCFCF">BS2p</td>
|
|||
|
<td width="16%" align="center" bgcolor="#CFCFCF">BS2pe</td>
|
|||
|
<td width="16%" align="center" bgcolor="#CFCFCF">BS2px</td>
|
|||
|
</tr>
|
|||
|
<tr>
|
|||
|
<td align="center" bgcolor="#CFCFCF">Number of program slots</td>
|
|||
|
<td colspan="5" align="center">8 (numbered 0 to 7) <sup>†</sup></td>
|
|||
|
</tr>
|
|||
|
<tr>
|
|||
|
<td align="center" bgcolor="#CFCFCF">Time delay to switch between program slots</td>
|
|||
|
<td align="center">770 µs</td>
|
|||
|
<td align="center">300 µs</td>
|
|||
|
<td align="center">250 µs</td>
|
|||
|
<td align="center">736 µs</td>
|
|||
|
<td align="center">195 µs</td>
|
|||
|
</tr>
|
|||
|
<tr>
|
|||
|
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
|||
|
<td align="center" colspan="2">
|
|||
|
<p colspan="2" align="center">n/a</p>
|
|||
|
</td>
|
|||
|
<td align="center" colspan="3">
|
|||
|
<p colspan="3" align="center"><a href="POLLRUN.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">POLLRUN</a>
|
|||
|
</p>
|
|||
|
</td>
|
|||
|
</tr>
|
|||
|
<tr>
|
|||
|
<td align="center" bgcolor="#CFCFCF">Special Notes</td>
|
|||
|
<td colspan="5" align="center"><span class="keyword_in_text">RUN</span> is similar to a <span class="keyword_in_text">GOTO</span>...you can not "return" from a <span class="keyword_in_text">RUN</span></td>
|
|||
|
</tr>
|
|||
|
</table>
|
|||
|
<p><sup>†</sup>The BS2pe has 16 slots, but only slots 0 - 7 are available for programs. Slots 8 - 15 may be used for data storage.</p>
|
|||
|
<h2>Explanation</h2>
|
|||
|
<p class="PlainText">The BS2e, BS2sx, BS2p, and BS2px have a total of 16 kilobytes of code space; the BS2pe
|
|||
|
has 16 kilobytes of code space and an additional 16 kilobytes of data space. This
|
|||
|
EEPROM space is organized into slots of 2 kilobytes (2048 bytes) each. Up to eight
|
|||
|
different programs can be downloaded to the BASIC Stamp (one program per slot).
|
|||
|
When the BASIC Stamp powers up, or is reset, the program in slot 0 is executed.</p>
|
|||
|
<p class="PlainText">The <span class="keyword_in_text">RUN</span> command allows you to activate another program and causes
|
|||
|
the BASIC Stamp to stay in the newly activated program until it receives
|
|||
|
another <span class="keyword_in_text">RUN</span> command, or until a power-down or reset condition occurs.
|
|||
|
The <span class="keyword_in_text">RUN</span> command is similar to a <span class="keyword_in_text">GOTO</span> command in that it allows you
|
|||
|
to "goto" another program. Normally a master-type program will be used
|
|||
|
in program slot 0 (since slot 0 runs first) and will control initial execution
|
|||
|
of the other programs.</p>
|
|||
|
<p class="PlainText">Look at the following example (there are two programs here, make sure to
|
|||
|
download them into program slots 0 and 1, respectively). See the special use of the <a href="../Reference/Directives.htm">$STAMP</a> directive in <a href="../Reference/Directives.htm#Defining">Defining Multi-File Projects</a> for more information.
|
|||
|
|
|||
|
</p>
|
|||
|
<p class="PlainText">Download the following two lines into program slot 0:</p><pre class="BScode" xml:space="preserve">
|
|||
|
DEBUG "Hello "
|
|||
|
 RUN 1
|
|||
|
</pre>
|
|||
|
<p class="PlainText">Download the following three lines into program slot 1:</p><pre class="BScode" xml:space="preserve">
|
|||
|
DEBUG "World!", CR
|
|||
|
 PAUSE 1000
|
|||
|
 RUN 0
|
|||
|
</pre>
|
|||
|
<p class="PlainText">The above two programs (assuming they have been downloaded into program slots 0 and 1, respectively) will display "Hello World!" on the screen. Program 0 is the first to run and it displays "Hello ", then issues a <span class="code_in_text">RUN 1</span> command. The BASIC Stamp then starts execution of program 1, from its first line of code, which causes "World!" to be displayed. Program 1 then pauses for one second and the runs program 0 again.</p>
|
|||
|
<h3>What Happens To I/O Pins And RAM When Using RUN?</h3>
|
|||
|
<p class="PlainText">The I/O pins retain their current state (directions and output latches) and
|
|||
|
all Variable and Scratchpad RAM locations retain their current data
|
|||
|
during a transition between programs with the RUN command. If sharing
|
|||
|
data between programs within Variable RAM, make sure to keep similar
|
|||
|
variable declarations (defined in the same order) in all programs so that
|
|||
|
the variables align themselves on the proper word, byte, nibble and bit
|
|||
|
boundaries across programs. The following programs illustrate what happens
|
|||
|
with mismatched variable declarations:</p><pre class="BScode" xml:space="preserve">
|
|||
|
' Download this program to Slot 0
|
|||
|
|
|||
|
cats VAR Byte
|
|||
|
dogs VAR Byte
|
|||
|
|
|||
|
Setup:
|
|||
|
cats = 3
|
|||
|
dogs = 1
|
|||
|
|
|||
|
Main:
|
|||
|
DEBUG "In Slot 0", CR
|
|||
|
DEBUG ? cats
|
|||
|
DEBUG ? dogs
|
|||
|
RUN 1
|
|||
|
</pre><pre class="BScode" xml:space="preserve">
|
|||
|
' Download this program to Slot 1
|
|||
|
|
|||
|
cats VAR Byte
|
|||
|
dogs VAR Byte
|
|||
|
fleas VAR Word
|
|||
|
|
|||
|
Main:
|
|||
|
DEBUG "In Slot 1", CR
|
|||
|
DEBUG ? cats
|
|||
|
DEBUG ? dogs
|
|||
|
DEBUG ? fleas
|
|||
|
END
|
|||
|
</pre>
|
|||
|
<p class="PlainText">When the Slot 1 program runs you may be surprised to see that cats and dogs
|
|||
|
are now zero and fleas are up to 259! - even though we didn't explicitly define
|
|||
|
them. What happened? The key to remember is that variable names are simply
|
|||
|
pointers to RAM addresses, and the PBASIC compiler assigns variable names to RAM
|
|||
|
in descending order by size. This means that in the Slot 1 program, fleas was
|
|||
|
assigned to RAM locations 0 and 1 which are holding the values 3 and 1
|
|||
|
respectively. Since words are stored low-byte first, the value 259 for fleas
|
|||
|
makes sense (3 + (1 * 256)).</p>
|
|||
|
<p class="PlainText">Any program number specified above 7 will wrap around and result in
|
|||
|
running one of the 8 programs (RUN 8 will run program 0, RUN 9 will run
|
|||
|
program 1, etc). The current program slot can be read from the last byte of the
|
|||
|
Scratchpad RAM. Example:</p><pre class="BScode" xml:space="preserve">
|
|||
|
#SELECT $STAMP
|
|||
|
#CASE BS2
|
|||
|
pgmSlot = 0 ' everything in slot 0
|
|||
|
rwSlot = 0
|
|||
|
#CASE BS2E, BS2SX
|
|||
|
READ 63, pgmSlot ' read current slot
|
|||
|
rwSlot = pgmSlot ' READ/WRITE slot is same
|
|||
|
#CASE BS2P, BS2PE, BS2PX
|
|||
|
READ 127, pgmSlot ' get slot control byte
|
|||
|
rwSlot = rwSlot.HIGHNIB ' READ/WRITE in high nibble
|
|||
|
pgmSlot = pgmSlot.LOWNIB ' pgm slot in low nibble
|
|||
|
#ENDSELECT
|
|||
|
</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>
|