Initial commit after migrating repo and assuring the product launches
This commit is contained in:
121
help/BasicStampHelp/Content/LanguageTopics/Commands/AUXIO.htm
Normal file
121
help/BasicStampHelp/Content/LanguageTopics/Commands/AUXIO.htm
Normal file
@ -0,0 +1,121 @@
|
||||
<?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>AUXIO</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">AUXIO</h1>
|
||||
<div class="ImagePlusCaption">
|
||||
<div class="Col2">
|
||||
<p>
|
||||
<img src="../../graphics/pgm_icon2p.gif" border="0" alt="BS2p icon" title="BS2p icon" /> (BS2p40)</p>
|
||||
</div>
|
||||
<p style="text-align: right;"><a href="../ExampleTopics/AuMainIotermEx.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">AUXIO / MAINIO / IOTERM Example</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: <span class="keyword_in_text">AUXIO</span></p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Switch from control of main I/O pins</p>
|
||||
<h2>Quick Facts</h2>
|
||||
<table cellpadding="4" cellspacing="0" border="1" style="caption-side: top;width: 100%;">
|
||||
<col />
|
||||
<col />
|
||||
<tr bgcolor="#CFCFCF">
|
||||
<td width="15%" align="center"> </td>
|
||||
<td width="85%" align="center">BS2p, BS2pe, and BS2px</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">I/O Pin IDs</td>
|
||||
<td>0 - 15 (just like main I/O, but after AUXIO command, all references affect
|
||||
physical pins 21 - 36).</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Special Notes</td>
|
||||
<td>
|
||||
<p>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.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
||||
<td>
|
||||
<p colspan="2" align="center"><a href="MAINIO.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">MAINIO</a>, <a href="IOTERM.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">IOTERM</a></p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText">The BS2p, BS2pe, and BS2px is available as a 24-pin module that is pin-compatible
|
||||
with the BS2, BS2e, and BS2sx. Also available is a 40-pin module called the BS2p40
|
||||
with an additional 16 I/O pins (for a total of 32). The BS2p40's extra, or
|
||||
<i>auxiliary</i>, I/O pins can be accessed in the same manner as the main I/O pins
|
||||
(by using the IDs 0 to 15) but only after issuing an <span class="keyword_in_text">AUXIO</span> or <span class="keyword_in_text">IOTERM 1</span> command. The <span class="keyword_in_text">AUXIO</span> command causes the BASIC
|
||||
Stamp to affect the auxiliary I/O pins instead of the main I/O pins in all further
|
||||
code until the <span class="keyword_in_text">MAINIO</span> or <span class="keyword_in_text">IOTERM 0</span> command is reached, or the BASIC Stamp
|
||||
is reset or power-cycled. <span class="keyword_in_text"> AUXIO</span> is also used when setting the DIRS register
|
||||
for auxiliary IO pins on the BS2p40.</p>
|
||||
<p class="PlainText">The following example illustrates this:</p><pre class="BScode" xml:space="preserve">
|
||||
Main:
|
||||
HIGH 0
|
||||
AUXIO
|
||||
LOW 0
|
||||
</pre>
|
||||
<p class="PlainText">The first line of the above example will set I/O pin 0 of the main I/O pins
|
||||
(physical pin 5) high. Afterward, the <span class="keyword_in_text">AUXIO</span> command tells the BASIC
|
||||
Stamp that all commands following it should affect the auxiliary I/O pins.
|
||||
The following <span class="keyword_in_text">LOW</span> command will set I/O pin 0 of the auxiliary I/O pins
|
||||
(physical pin 21) low. </p>
|
||||
<p class="PlainText">Note that the main I/O and auxiliary I/O pins are independent of each other;
|
||||
the states of the main I/O pins remain unchanged while the program affects the
|
||||
auxiliary I/O pins, and vice versa.</p>
|
||||
<h3> Reducing Power Consumption </h3>
|
||||
<p class="PlainText">When the BASIC Stamp is reset all RAM variables, including DIRS and OUTS are
|
||||
cleared to zero. This goes for main and auxiliary pins. On the BS2p24,
|
||||
BS2pe, and BS2px the auxiliary pins from the interpreter chip are not connected to
|
||||
physical IO pins on the BASIC Stamp. While not connected to anything, these
|
||||
pins do have pull-ups activated, effectively connecting them to Vdd. After
|
||||
reset, reading the auxiliary pins from a BS2p24, BS2pe, or BS2px will return all 1s.
|
||||
For lowest possible current consumption where required, you may set the BS2p24,
|
||||
BS2pe, and BS2px auxiliary pins as output low.</p><pre class="BScode" xml:space="preserve">
|
||||
Setup:
|
||||
AUXIO ' select AUXIO pins
|
||||
OUTS = $0000 ' force outputs low
|
||||
DIRS = $FFFF ' make (unconnected) pins outputs
|
||||
MAINIO ' back to MAINIO group
|
||||
</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>
|
107
help/BasicStampHelp/Content/LanguageTopics/Commands/BRANCH.htm
Normal file
107
help/BasicStampHelp/Content/LanguageTopics/Commands/BRANCH.htm
Normal file
@ -0,0 +1,107 @@
|
||||
<?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>BRANCH</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">BRANCH</h1>
|
||||
<div class="ImagePlusCaption">
|
||||
<div class="Col2">
|
||||
<p>
|
||||
<img src="../../graphics/pgm_icon1.gif" border="0" alt="BS1 icon" title="BS1 icon" />
|
||||
<img src="../../graphics/pgm_icon2.gif" border="0" alt="BS2 icon" title="BS2 icon" />
|
||||
<img src="../../graphics/pgm_icon2e.gif" border="0" alt="BS2e icon" title="BS2e icon" />
|
||||
<img src="../../graphics/pgm_icon2sx.gif" border="0" alt="BS2sx icon" title="BS2sx icon" />
|
||||
<img src="../../graphics/pgm_icon2p.gif" border="0" alt="BS2p icon" title="BS2p icon" />
|
||||
<img src="../../graphics/pgm_icon2pe.gif" border="0" alt="BS2pe icon" title="BS2pe icon" />
|
||||
<img src="../../graphics/pgm_icon2px.gif" border="0" alt="BS2px icon" title="BS2px icon" />
|
||||
</p>
|
||||
</div>
|
||||
<p style="text-align: right;"><a href="../ExampleTopics/BranchEx.htm" target="" title="" alt="" class="MCXref_0">BRANCH Examples</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax <img align="absmiddle" src="../../graphics/mini_1.gif" />:
|
||||
<span class="keyword_in_text">BRANCH</span> <![CDATA[ ]]><i>Offset<u style="font-style: normal; text-decoration: none;">, (</u>Address1</i>,<i> Address2</i>, ..<i>.AddressN</i>)</p>
|
||||
<p class="PlainText">Syntax <img align="absmiddle" src="../../graphics/mini_2.gif" />: <span class="keyword_in_text">BRANCH</span> <![CDATA[ ]]><i>Offset,</i> [<i>Address1</i>,<i> Address2</i>, ...<i>AddressN</i>]</p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Go to the <i>Address</i> specified by <i>Offset</i> (if in range).</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Offset</i></b> is a variable/constant/expression* (0 - 255) that
|
||||
specifies the index of the address, in the list, to branch to (0 - N).</li>
|
||||
<li value="2"><b><i>Addresses</i></b> are labels that specify where to go. <span class="keyword_in_text">BRANCH </span>will ignore any list entries beyond offset 255.</li>
|
||||
</ul>
|
||||
<p class="PlainText">*<img src="../../graphics/bs1note.gif" style="vertical-align: super;" /> Note: expressions are not allowed as arguments on the BS1.</p>
|
||||
<h2>Quick Facts</h2>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr>
|
||||
<td align="center" width="150" bgcolor="#CFCFCF"> </td>
|
||||
<td align="center" width="40%" bgcolor="#CFCFCF">BS1</td>
|
||||
<td align="center" width="40%" bgcolor="#CFCFCF">BS2 Family</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Limit of <i>Address</i> entries</td>
|
||||
<td align="center">Limited only by memory</td>
|
||||
<td align="center">256</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
||||
<td align="center">None</td>
|
||||
<td align="center">
|
||||
<p align="center"><a href="ON_GOTO.htm" target="" title="" alt="" class="MCXref_0">ON...GOTO</a>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p> </p>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText">The <span class="keyword_in_text">BRANCH </span>instruction is useful when you want to write something like this:</p><pre class="BScode" xml:space="preserve">Test_Value:
|
||||
IF value = 0 THEN Case_0 ' if value is 0, jump to Case_0
|
||||
IF value = 1 THEN Case_1 ' if value is 1, jump to Case_1
|
||||
IF value = 2 THEN Case_2 ' if value is 2, jump to Case_2
|
||||
</pre>
|
||||
<p class="PlainText">You can use <span class="keyword_in_text">BRANCH</span> to organize this into a single statement:</p>
|
||||
<p class="PlainText">
|
||||
<img src="../../graphics/bs1_inline.gif" />
|
||||
</p><pre class="BScode" xml:space="preserve">  BRANCH value, (Case_0, Case_1, Case_2)</pre>
|
||||
<p class="PlainText">
|
||||
<img src="../../graphics/bs2all_inline.gif" />
|
||||
</p><pre class="BScode" xml:space="preserve">  BRANCH value, (Case_0, Case_1, Case_2)</pre>
|
||||
<p class="PlainText">This works exactly the same as the previous <a href="IF_THEN.htm" target="" title="" alt="" class="MCXref_0">IF…THEN</a> example. If the value isn’t in range (in this case if value is greater than 2), <span class="keyword_in_text">BRANCH </span>does nothing and the program continues with the next instruction after <span class="keyword_in_text">BRANCH</span>.</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>
|
126
help/BasicStampHelp/Content/LanguageTopics/Commands/BUTTON.htm
Normal file
126
help/BasicStampHelp/Content/LanguageTopics/Commands/BUTTON.htm
Normal file
@ -0,0 +1,126 @@
|
||||
<?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>BUTTON</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">BUTTON</h1>
|
||||
<div class="ImagePlusCaption">
|
||||
<div class="Col2">
|
||||
<p>
|
||||
<img src="../../graphics/pgm_icon1.gif" border="0" alt="BS1 icon" title="BS1 icon" />
|
||||
<img src="../../graphics/pgm_icon2.gif" border="0" alt="BS2 icon" title="BS2 icon" />
|
||||
<img src="../../graphics/pgm_icon2e.gif" border="0" alt="BS2e icon" title="BS2e icon" />
|
||||
<img src="../../graphics/pgm_icon2sx.gif" border="0" alt="BS2sx icon" title="BS2sx icon" />
|
||||
<img src="../../graphics/pgm_icon2p.gif" border="0" alt="BS2p icon" title="BS2p icon" />
|
||||
<img src="../../graphics/pgm_icon2pe.gif" border="0" alt="BS2pe icon" title="BS2pe icon" />
|
||||
<img src="../../graphics/pgm_icon2px.gif" border="0" alt="BS2px icon" title="BS2px icon" />
|
||||
</p>
|
||||
</div>
|
||||
<p style="text-align: right;"><a href="../ExampleTopics/ButtonEx.htm" target="" title="" alt="" class="MCXref_0">BUTTON Example</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: <span class="keyword_in_text">BUTTON</span> <![CDATA[ ]]><i>Pin</i>,<i> DownState</i>,<i> Delay</i>,<i> Rate</i>,<i> Workspace</i>,<i> TargetState</i>,<i> Address</i></p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Monitor and process a pushbutton input, perform auto-repeat, and branch to address
|
||||
if button is in target state. Button circuits may be active-low or active-high.
|
||||
|
||||
</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Pin</i></b> is a variable/constant/expression* (0 - 15) that specifies
|
||||
the I/O pin to use. This pin will be set to input mode.</li>
|
||||
<li value="2"><b><i>DownState</i></b> is a variable/constant/expression* (0 or 1) that
|
||||
specifies which logical state occurs when the button is pressed.</li>
|
||||
<li value="3"><b><i>Delay</i></b> is a variable/constant/expression* (0 - 255) that specifies
|
||||
how long the button must be pressed before auto-repeat starts. The delay is
|
||||
measured in cycles of the <span class="keyword_in_text">BUTTON</span> routine. <i>Delay</i> has two special
|
||||
settings: 0 and 255. If <i>Delay</i> is 0, <span class="keyword_in_text">BUTTON</span> performs no debounce
|
||||
or auto-repeat. If <i>Delay</i> is 255, Button performs debounce, but no
|
||||
auto-repeat. </li>
|
||||
<li value="4"><b><i>Rate</i></b> is a variable/constant/expression* (0 - 255) that specifies
|
||||
the number of cycles between auto-repeats. The rate is expressed in cycles
|
||||
of the <span class="keyword_in_text">BUTTON</span> routine. </li>
|
||||
<li value="5"><b><i>Workspace</i></b> is a byte variable used by <span class="keyword_in_text">BUTTON</span> for workspace.
|
||||
It must be cleared to 0 before being used by <span class="keyword_in_text">BUTTON</span> for the first time
|
||||
and should not be adjusted outside of the <span class="keyword_in_text">BUTTON</span> instruction. NOTE:
|
||||
All RAM is cleared to 0 by default upon power-up or reset of the BASIC
|
||||
Stamp. </li>
|
||||
<li value="6"><b><i>TargetState</i></b> is a variable/constant/expression* (0 or 1) that
|
||||
specifies which state the button should be in for a branch to occur (0=not
|
||||
pressed, 1=pressed).</li>
|
||||
<li value="7"><b><i>Address</i></b> is a label that specifies where to branch if the button
|
||||
is in the target state.</li>
|
||||
</ul>
|
||||
<p class="PlainText">*<img src="../../graphics/bs1note.gif" style="vertical-align: super;" /> Note: expressions are not allowed as arguments on the BS1. The range
|
||||
of the <i>Pin</i> argument on the BS1 is 0–7.</p>
|
||||
<h2>Explanation<br /></h2>
|
||||
<p class="PlainText">When you press a button or flip a switch, the contacts make or break a connection.
|
||||
A brief (1 to 20-ms) burst of noise occurs as the contacts scrape and bounce against
|
||||
each other. By scanning an input within a loop to ensure that the contact remains
|
||||
in a specified state for a minimum duration, spurious multiple inputs caused by
|
||||
contact noise can be eliminated. The <span class="keyword_in_text">BUTTON </span>instruction helps prevent this
|
||||
noise from being interpreted as more than one switch action; this is the function
|
||||
of the <i>Delay</i> parameter. (For a demonstration of switch bounce, see the demo
|
||||
program for the <a href="COUNT.htm" target="" title="" alt="" class="MCXref_0">COUNT</a> instruction.) <i>Delay</i>, combined
|
||||
with the <i>Rate</i> parameter, allows the programmer to control the rate at which
|
||||
multiple inputs are accepted by the BASIC Stamp.</p>
|
||||
<p class="PlainText"><span class="keyword_in_text">BUTTON</span> also lets PBASIC react to a button press the way your computer
|
||||
keyboard does to a key press. When you press a key, a character immediately appears
|
||||
on the screen. If you hold the key down, there's a delay, then a rapid-fire stream
|
||||
of characters appears on the screen. <span class="keyword_in_text">BUTTON</span>'s auto-repeat function can be
|
||||
set up to work much the same way. </p>
|
||||
<p class="PlainText"><span class="keyword_in_text">BUTTON</span> is designed for use inside a program loop. Each time through the
|
||||
loop, <span class="keyword_in_text">BUTTON</span> checks the state of the specified pin. When it first matches
|
||||
<i>DownState</i>, <span class="keyword_in_text">BUTTON</span> begins the <i>Delay</i> countdown for auto-repeat.
|
||||
Then, in accordance with <i>TargetState</i>, it either branches to address
|
||||
(TargetState = 1) or doesn't (TargetState = 0).</p>
|
||||
<p class="PlainText">If the switch stays in <i>DownState</i>, <span class="keyword_in_text">BUTTON</span> counts the number of
|
||||
program loops that execute. When this count equals <i>Delay</i>, <span class="keyword_in_text">BUTTON</span>once again triggers the action specified by <i>TargetState</i> and <i>Address</i>. Hereafter,
|
||||
if the switch remains in <i>DownState</i>, <span class="keyword_in_text">BUTTON</span> waits <i>Rate</i> number
|
||||
of cycles between actions. The <i>Workspace</i> variable is used by <span class="keyword_in_text">BUTTON</span>
|
||||
to keep track of how many cycles have occurred since the pin switched to
|
||||
<i>TargetState</i> or since the last auto-repeat.</p>
|
||||
<p class="PlainText"><span class="keyword_in_text">BUTTON</span> does not stop program execution. In order for its delay and auto
|
||||
repeat functions to work properly, <span class="keyword_in_text">BUTTON</span> must be executed from within a
|
||||
program loop.</p>
|
||||
<center>
|
||||
<img src="../../graphics/button_sch.gif" border="0" />
|
||||
</center>
|
||||
<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>
|
117
help/BasicStampHelp/Content/LanguageTopics/Commands/COMPARE.htm
Normal file
117
help/BasicStampHelp/Content/LanguageTopics/Commands/COMPARE.htm
Normal file
@ -0,0 +1,117 @@
|
||||
<?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>COMPARE</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">COMPARE</h1>
|
||||
<div class="ImagePlusCaption">
|
||||
<div class="Col2">
|
||||
<p>
|
||||
<img src="../../graphics/pgm_icon2px.gif" border="0" alt="BS2px icon" title="BS2px icon" />
|
||||
</p>
|
||||
</div>
|
||||
<p style="text-align: right;"><a href="../ExampleTopics/CompareEx.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">COMPARE Example</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: <span class="keyword_in_text">COMPARE</span> <![CDATA[ ]]><i>Mode,</i> <![CDATA[ ]]><i>Result</i></p>
|
||||
<h2>Function</h2>
|
||||
<p>Enable or disable comparator, compare voltages on P1 and P2 and retrieve
|
||||
comparison result to store in <i>Result</i>.
|
||||
|
||||
</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Mode</i></b> is a variable/constant/expression (0 – 2) that enables
|
||||
or disables the comparator (input pins P1 and P2) and determines if the
|
||||
optional comparator output pin (pin P0) is enabled or not. See the table
|
||||
below for an explanation of the <i>Mode</i> values.</li>
|
||||
<li value="2"><b><i>Result</i></b> is a variable (usually a bit) in which the
|
||||
comparison result is stored.</li>
|
||||
</ul>
|
||||
<h2>Quick Facts<br /></h2>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF">
|
||||
<td width="80" align="center"> </td>
|
||||
<td width="80%%" align="center">BS2px</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" rowspan="3" bgcolor="#CFCFCF"><i>Mode</i> Values</td>
|
||||
<td>0: Disables comparator.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1: Enables comparator with P0 as <i>Result</i> output.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>2: Enables comparator without P0 as <i>Result</i> output.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" rowspan="2" bgcolor="#CFCFCF"><i>Result</i> Values</td>
|
||||
<td>0: Voltage P1 > P2; P0 optionally outputs 0.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1: Voltage P1 < P2; P0 optionally outputs 1.</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText">The <span class="keyword_in_text">COMPARE</span> command enables or disables the built-in comparator
|
||||
hardware on the BS2px's I/O pins P0, P1, and P2. I/O pins P1 and P2 are
|
||||
the comparator inputs and P0 is optionally the comparator result output
|
||||
pin.</p>
|
||||
<p class="PlainText">By default, the comparator feature is disabled. Using the <span class="keyword_in_text">COMPARE</span> command with a <i>Mode</i> argument of 1 or 2 enables the comparator feature
|
||||
(using input pins P1 and P2) and returns the result of the comparison in
|
||||
<i>Result</i>. If <i>Mode</i> is 1, the result of the comparison is also
|
||||
output on I/O pin P0. The following is an example of the <span class="keyword_in_text">COMPARE </span>command:</p><pre class="BScode" xml:space="preserve">
|
||||
result VAR Bit
|
||||
|
||||
Main:
|
||||
COMPARE 1, result
|
||||
</pre>
|
||||
<p class="PlainText">This example enables the comparator (setting P0 to output the result,
|
||||
with P1 and P2 as the comparator inputs) and writes the result of the
|
||||
comparison into <i>result</i>. Both <i>Result </i>and the output pin P0
|
||||
will be 0 if the input voltage on P1 was greater than that of P2.
|
||||
<i>result</i> and the output pin P0 will be 1 if the input voltage on P1
|
||||
was less than that of P2.</p>
|
||||
<p class="PlainText">Note that the comparator hardware operates independently of the
|
||||
execution speed of the BS2px and will continue to run and update P0 if
|
||||
Mode = 1, even during sleep mode (execution of <span class="keyword_in_text">END</span>, <span class="keyword_in_text">NAP</span>,
|
||||
<span class="keyword_in_text">POLLWAIT</span> 8, or <span class="keyword_in_text">SLEEP</span> commands). To avoid spurious current
|
||||
draw during sleep mode, disable the comparator first.</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,208 @@
|
||||
<?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>CONFIGPIN</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">CONFIGPIN</h1>
|
||||
<div class="ImagePlusCaption">
|
||||
<div class="Col2">
|
||||
<p>
|
||||
<img src="../../graphics/pgm_icon2px.gif" border="0" alt="BS2px icon" title="BS2px icon" />
|
||||
</p>
|
||||
</div>
|
||||
<p style="text-align: right;"><a href="../ExampleTopics/ConfigpinEx.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">CONFIGPIN Example</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: <span class="keyword_in_text">CONFIGPIN</span> <![CDATA[ ]]><i>Mode</i>, <i>PinMask</i></p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Configure special properties of I/O pins.
|
||||
|
||||
</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Mode</i></b>  is a variable/constant/expression (0 – 3), or one
|
||||
of four predefined symbols, that specifies the I/O pin property to configure:
|
||||
Schmitt Trigger, Logic Threshold, Pull-up Resistor or Output Direction. See
|
||||
table below for an explanation of <i>Mode</i> values.</li>
|
||||
<li value="2"><b><i>PinMask</i></b>  is a variable/constant/expression (1 – 65535)
|
||||
that indicates how <i>Mode</i> is applied to I/O pins. Each bit of
|
||||
<i>PinMask</i> corresponds to an individual I/O pin. A high bit (1) enables
|
||||
the <i>Mode</i> and a low bit (0) disables the <i>Mode</i> on the
|
||||
corresponding I/O pin.</li>
|
||||
</ul>
|
||||
<h2>Quick Facts<br /></h2>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF">
|
||||
<td width="80" align="center"> </td>
|
||||
<td width="80%%" align="center">BS2px</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" rowspan="4" bgcolor="#CFCFCF"><i>Mode</i> Values</td>
|
||||
<td>0 (or SCHMITT): Schmitt Trigger</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1 (or THRESHOLD): Logic Threshold</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>2 (or PULLUP): Pull-up Resistor</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>3 (or DIRECTION): Output Direction</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
||||
<td align="center" colspan="1">
|
||||
<p colspan="1" align="center"><a href="INPUT.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">INPUT</a>, <a href="OUTPUT.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">OUTPUT</a></p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText">The <span class="keyword_in_text">CONFIGPIN</span> command enables or disables special I/O pin properties
|
||||
on all 16 I/O pins at once. There are four properties, or modes, available:
|
||||
Schmitt Trigger, Logic Threshold, Pull-up Resistor, and Output Direction.
|
||||
Each I/O pin on the BS2px contains special hardware dedicated to each of
|
||||
these properties.</p>
|
||||
<p class="PlainText">By default, all BASIC Stamp I/O pins are set to inputs. Enabling the
|
||||
Output Direction mode sets an I/O pin’s direction to output. Disabling
|
||||
the Output Direction mode sets an I/O pin’s direction to input. This has
|
||||
the same effect as using the <span class="keyword_in_text">OUTPUT</span> or <span class="keyword_in_text">INPUT</span> commands, or the
|
||||
DIRx = # assignment statement to configure I/O pin directions. The
|
||||
following is an example of the <span class="keyword_in_text">CONFIGPIN</span> command using the Output
|
||||
Direction mode:</p><pre class="BScode" xml:space="preserve">
|
||||
CONFIGPIN DIRECTION, %0000000100010011
|
||||
</pre>
|
||||
<p class="PlainText">Every high bit (1) in the <i>PinMask</i> argument enables the output direction
|
||||
for the corresponding I/O pin while every low bit (0) disables the output
|
||||
direction. In the above example, I/O pins 8, 4, 1, and 0 are set to the
|
||||
output direction and all other I/O pins are set to the input direction. This
|
||||
is similar to the following statement:</p><pre class="BScode" xml:space="preserve">
|
||||
DIRS = %0000000100010011
|
||||
</pre>
|
||||
<p class="PlainText">Pull-up resistors are commonly used in circuitry where a component, such
|
||||
as a button, provides an open/drain signal; the signal is either floating
|
||||
(open) or is driven to ground (drain). Since the BASIC Stamp input pins
|
||||
must always be connected to either 5 volts or ground (0 volts) in order to
|
||||
read a reliable logic state with them, a pull-up resistor is required on
|
||||
circuitry, such as the button circuit mentioned above, so that the signal is
|
||||
never left floating (electrically disconnected).</p>
|
||||
<p class="PlainText">The following example enables internal pull-up resistors on I/O pins 15,
|
||||
12, 6, and 3, and disables internal pull-up resistors on all other I/O pins:</p><pre class="BScode" xml:space="preserve">
|
||||
CONFIGPIN PULLUP, %1001000001001000
|
||||
</pre>
|
||||
<p class="PlainText">Note that the internal pull-up resistors are intentionally weak, about 20
|
||||
kΩ. Additionally, the internal pull-up resistors can be activated for all
|
||||
pins, regardless of pin direction, but really matter only when the
|
||||
associated pin is set to input mode.</p>
|
||||
<p class="PlainText">An input pin’s logic threshold determines the voltage levels that are
|
||||
interpreted as logic high (1) and logic low (0). Most microcontrollers, and
|
||||
other integrated circuits use one of two types of logic threshold: TTL Level
|
||||
or CMOS Level. The BASIC Stamp I/O pins are, by default, configured for TTL
|
||||
level logic thresholds. The figure below is an illustration of the difference
|
||||
between TTL and CMOS logic levels.</p>
|
||||
<table border="0">
|
||||
<tr>
|
||||
<td>
|
||||
<img src="../../graphics/level_ttl.gif" border="0">
|
||||
</img>
|
||||
</td>
|
||||
<td>         </td>
|
||||
<td>
|
||||
<img src="../../graphics/level_cmos.gif" border="0">
|
||||
</img>
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td><b>TTL Logic Level</b>
|
||||
</td>
|
||||
<td>   </td>
|
||||
<td><b>CMOS Logic Level</b>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p class="PlainText"> </p>
|
||||
<p class="PlainText">The logic threshold for TTL is 1.4 volts; a voltage below 1.4 is considered
|
||||
to be a logic 0 while a voltage above 1.4 is considered to be a logic 1. The
|
||||
logic threshold for CMOS is 50% of Vdd; a voltage below ½ Vdd is
|
||||
considered a logic 0 while a voltage above ½ Vdd is considered a logic 1.</p>
|
||||
<p class="PlainText">For the <span class="keyword_in_text">CONFIGPIN</span> command's THRESHOLD mode, a high bit (1) in the
|
||||
<i>PinMask</i> argument sets the corresponding I/O pin to CMOS threshold
|
||||
level, and a low bit sets it to a TTL threshold level. The following example
|
||||
sets CMOS threshold level on I/O pins 3, 2, 1, and 0, and TTL threshold
|
||||
level on all other I/O pins.</p><pre class="BScode" xml:space="preserve">
|
||||
CONFIGPIN THRESHOLD, %0000000000001111
|
||||
</pre>
|
||||
<p class="PlainText">The threshold level can be set for all pins, regardless of pin direction, but
|
||||
really matters only when the associated pin is set to input mode.</p>
|
||||
<p class="PlainText">Normally, if a signal on an input pin is somewhat noisy (the voltage level
|
||||
randomly rises and falls beyond the logic threshold boundary) then
|
||||
reading that pin’s input value will result in spurious highs and lows (1s
|
||||
and 0s). Schmitt Triggers are circuits that make inputs more steady and
|
||||
reliable by adding a region of hysteresis around the logic threshold that
|
||||
the signal must completely traverse before the logic level is interpreted as
|
||||
being changed. By default BASIC Stamp I/O pins are set to normal input
|
||||
mode, but the BS2px can be configured for Schmitt Trigger mode as well.
|
||||
The figure below illustrates Schmitt Trigger characteristics.</p>
|
||||
<table border="0">
|
||||
<tr>
|
||||
<td>
|
||||
<img src="../../graphics/level_schmitt.gif" border="0">
|
||||
</img>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p class="PlainText">In Schmitt Trigger mode, the threshold for a logic 0 is approximately 15%
|
||||
of Vdd and the threshold for a logic 1 is approximately 85% of Vdd. The
|
||||
input pin defaults to an unknown state until the initial voltage crosses a
|
||||
logic 0 or logic 1 boundary. Thereafter, the voltage must cross above 85%
|
||||
of Vdd to be interpreted as a logic 1 and must cross below 15% of Vdd to
|
||||
be interpreted as a logic 0. If the voltage transitions somewhere between
|
||||
the two thresholds, the interpreted logic state remains the same as the
|
||||
previous state.</p>
|
||||
<p class="PlainText">For the <span class="keyword_in_text">CONFIGPIN</span> command’s SCHMITT mode, a high bit (1) in the
|
||||
<i>PinMask</i> argument enables the Schmitt Trigger on the corresponding I/O
|
||||
pin and a low bit (0) disables the Schmitt Trigger. The following example
|
||||
sets Schmitt Triggers on I/O pins 7, 6, 5, and 4, and sets all other I/O pins
|
||||
to normal mode.</p><pre class="BScode" xml:space="preserve">
|
||||
CONFIGPIN SCHMITT, %0000000011110000
|
||||
</pre>
|
||||
<p class="PlainText">Schmitt Trigger mode can be activated for all pins, regardless of pin
|
||||
direction, but really matters only when the associated pin is set to input
|
||||
mode.</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>
|
141
help/BasicStampHelp/Content/LanguageTopics/Commands/COUNT.htm
Normal file
141
help/BasicStampHelp/Content/LanguageTopics/Commands/COUNT.htm
Normal file
@ -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="" 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>COUNT</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">COUNT</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" />
|
||||
</p>
|
||||
</div>
|
||||
<p style="text-align: right;"><a href="../ExampleTopics/CountEx.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">COUNT Example</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p>Syntax: <span class="keyword_in_text">COUNT</span> <![CDATA[ ]]><i>Pin</i>,<i> Duration</i>,<i> Variable</i></p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Count the number of cycles (0-1-0 or 1-0-1) on the specified pin during the <i>Duration</i> time frame and store that number in <i>Variable</i>.
|
||||
|
||||
</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Pin</i></b> is a variable/constant/expression (0 – 15) that specifies
|
||||
the I/O pin to use. This pin will be set to input mode.</li>
|
||||
<li value="2"><b><i>Duration</i></b> is a variable/constant/expression (1 – 65535) specifying
|
||||
the time during which to count. The unit of time for <i>Duration</i> is described
|
||||
below.</li>
|
||||
<li value="3"><b><i>Variable</i></b> is a variable (usually a Word) in which the count will
|
||||
be stored.</li>
|
||||
</ul>
|
||||
<h2>Quick Facts<br /></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">BS2 / 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">Units in <i>Duration</i></td>
|
||||
<td align="center">1 ms</td>
|
||||
<td align="center">400 µs</td>
|
||||
<td align="center">287 µs</td>
|
||||
<td align="center">720 µs</td>
|
||||
<td align="center">287 µs</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF"><i>Duration</i> range</td>
|
||||
<td align="center">1 ms to 65.535 s</td>
|
||||
<td align="center">400 µs to 26.214 s</td>
|
||||
<td align="center">287 µs to 18.809 s</td>
|
||||
<td align="center">720 µs to 47.180 s</td>
|
||||
<td align="center">287 µs to 18.809 s</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Minimum pulse width</td>
|
||||
<td align="center">4.16 µs</td>
|
||||
<td align="center">1.66 µs</td>
|
||||
<td align="center">1.20 µs</td>
|
||||
<td align="center">3.00 µs</td>
|
||||
<td align="center">1.20 µs</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Maximum frequency<br></br>(square wave)</td>
|
||||
<td align="center">120,000 Hz</td>
|
||||
<td align="center">300,000 Hz</td>
|
||||
<td align="center">416,700 Hz</td>
|
||||
<td align="center">166,667 Hz</td>
|
||||
<td align="center">416,700 Hz</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
||||
<td align="center" colspan="5">
|
||||
<p colspan="5" align="center"><a href="PULSIN.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">PULSIN</a>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText">The <span class="keyword_in_text">COUNT</span> instruction makes the <i>Pin</i> an input, then for the specified
|
||||
<i>duration</i>, counts cycles on that pin and stores the total in a variable. A
|
||||
cycle is a change in state from 1 to 0 to 1, or from 0 to 1 to 0.</p>
|
||||
<p class="PlainText">According to table above, <span class="keyword_in_text">COUNT</span> on the BS2 can respond to transitions
|
||||
(pulse widths) as small as 4.16 microseconds (µs). A cycle consists of two transitions
|
||||
(e.g., 0 to 1, then 1 to 0), so <span class="keyword_in_text">COUNT</span> (on the BS2) can respond to square
|
||||
waves with periods as short as 8.32 µs; up to 120 kilohertz (kHz) in frequency.
|
||||
For non-square waves (those whose high time and low time are unequal), the shorter
|
||||
of the high and low times must be at least 4.16 µs in width (on the BS2). Refer
|
||||
to the table for data on other BASIC Stamp modules.</p>
|
||||
<p class="PlainText">If you use <span class="keyword_in_text">COUNT</span> on slowly changing analog waveforms like sine waves,
|
||||
you may find that the value returned is higher than expected. This is because the
|
||||
waveform may pass through the BASIC Stamp’s 1.4-volt logic threshold slowly enough
|
||||
that noise causes false counts. You can fix this by passing the signal through
|
||||
a Schmitt Trigger, like one of the inverters of a 74HCT14. Or, you may use the
|
||||
BS2px’s built-in Schmitt-Trigger pin property; see
|
||||
<a href="CONFIGPIN.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">CONFIGPIN</a> for details. </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>
|
269
help/BasicStampHelp/Content/LanguageTopics/Commands/DATA.htm
Normal file
269
help/BasicStampHelp/Content/LanguageTopics/Commands/DATA.htm
Normal file
@ -0,0 +1,269 @@
|
||||
<?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>DATA</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">DATA</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" />
|
||||
</p>
|
||||
</div>
|
||||
<p style="text-align: right;"><a href="../ExampleTopics/DataEx.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">DATA Example</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: {<i>Symbol</i>} <span class="keyword_in_text">DATA</span>
|
||||
{@<i>Address</i>,} {Word} <i>DataItem </i>{,<i> DataItem ...</i>}</p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Write user data to the EEPROM location(s) during program download.
|
||||
|
||||
</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Symbol</i></b> is an optional, unique symbol name that will be
|
||||
automatically defined as a constant equal to the location number of the first
|
||||
data item.</li>
|
||||
<li value="2"><b><i>Address</i></b> is an optional starting location for subsequent
|
||||
<i>DataItems</i></li>
|
||||
<li value="3"><b><i>DataItem</i></b> is a constant/expression (0 - 65535) indicating a value
|
||||
or how to store a value.</li>
|
||||
</ul>
|
||||
<h2>Quick Facts</h2>
|
||||
<table cellpadding="4" cellspacing="0" border="1" style="caption-side: top;width: 100%;">
|
||||
<col />
|
||||
<col />
|
||||
<tr bgcolor="#CFCFCF">
|
||||
<td width="15%" align="center"> </td>
|
||||
<td width="85%" align="center">All BS2 Models</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Special Notes</td>
|
||||
<td>Writes values to EEPROM during download in blocks of 16 bytes. Writes byte- or word-sized values. Can be used to decrease program size.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
||||
<td align="center"><a href="READ.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">READ</a>, <a href="WRITE.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">WRITE</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText">When you download a program into the BASIC Stamp, it is stored in the EEPROM starting
|
||||
at the highest address (2047) and working towards the lowest address. Most programs
|
||||
don't use the entire EEPROM, so the lower portion is available for other uses.
|
||||
The <span class="keyword_in_text">DATA</span> directive allows you to define a set of data to store in the available
|
||||
EEPROM locations. It is called a "directive" rather than a "command" because it
|
||||
performs an activity at compile-time rather than at run-time (i.e.: the <span class="keyword_in_text">DATA</span>directive is not downloaded to the BASIC Stamp, but the data it contains is downloaded).</p>
|
||||
<p class="PlainText">The simplest form of the <span class="keyword_in_text">DATA</span> directive is something like the following:</p><pre class="BScode" xml:space="preserve">
|
||||
DATA 100, 200, 52, 45
|
||||
</pre>
|
||||
<p class="PlainText">This example, when downloaded, will cause the values 100, 200, 52 and 45 to be
|
||||
written to EEPROM locations 0, 1, 2 and 3, respectively. You can then use the
|
||||
<span class="keyword_in_text">READ</span> and <span class="keyword_in_text">WRITE</span> commands in your code to access these locations and
|
||||
the data you've stored there.</p>
|
||||
<p class="PlainText"><span class="keyword_in_text">DATA</span> uses a counter, called a pointer, to keep track of available EEPROM
|
||||
addresses. The value of the pointer is initially 0. When a program is downloaded,
|
||||
the <span class="keyword_in_text">DATA</span> directive stores the first byte value at the current pointer address,
|
||||
then increments (adds 1 to) the pointer. If the program contains more than one
|
||||
<span class="keyword_in_text">DATA</span> directive, subsequent <span class="keyword_in_text">DATA</span>s start with the pointer value left
|
||||
by the previous <span class="keyword_in_text">DATA</span>. For example, if the program contains:</p><pre class="BScode" xml:space="preserve">
|
||||
DATA 72, 69, 76, 76, 79
|
||||
DATA 104, 101, 108, 108, 111
|
||||
</pre>
|
||||
<p class="PlainText">The first <span class="keyword_in_text">DATA</span> directive will start at location 0 and increment the pointer
|
||||
for each data value it stores (1, 2, 3, 4, and 5). The second <span class="keyword_in_text">DATA</span> directive
|
||||
will start with the pointer value of 5 and work upward from there. As a result,
|
||||
the first 10 bytes of EEPROM will look like the following:</p>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr>
|
||||
<td width="20%" align="center" bgcolor="#CFCFCF" rowspan="2"> </td>
|
||||
<td align="center" bgcolor="#CFCFCF" colspan="10">EEPROM Location (address)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="8%" align="center" bgcolor="#CFCFCF">0</td>
|
||||
<td width="8%" align="center" bgcolor="#CFCFCF">1</td>
|
||||
<td width="8%" align="center" bgcolor="#CFCFCF">2</td>
|
||||
<td width="8%" align="center" bgcolor="#CFCFCF">3</td>
|
||||
<td width="8%" align="center" bgcolor="#CFCFCF">4</td>
|
||||
<td width="8%" align="center" bgcolor="#CFCFCF">5</td>
|
||||
<td width="8%" align="center" bgcolor="#CFCFCF">6</td>
|
||||
<td width="8%" align="center" bgcolor="#CFCFCF">7</td>
|
||||
<td width="8%" align="center" bgcolor="#CFCFCF">8</td>
|
||||
<td width="8%" align="center" bgcolor="#CFCFCF">9</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="20%" align="center" bgcolor="#CFCFCF">Contents</td>
|
||||
<td width="8%" align="center">72</td>
|
||||
<td width="8%" align="center">69</td>
|
||||
<td width="8%" align="center">76</td>
|
||||
<td width="8%" align="center">76</td>
|
||||
<td width="8%" align="center">79</td>
|
||||
<td width="8%" align="center">104</td>
|
||||
<td width="8%" align="center">101</td>
|
||||
<td width="8%" align="center">108</td>
|
||||
<td width="8%" align="center">108</td>
|
||||
<td width="8%" align="center">111</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p> </p>
|
||||
<p class="PlainText">What if you don't want to store values starting at location 0? Fortunately,
|
||||
the <span class="keyword_in_text">DATA</span> directive has an option to specify the next location to use. You
|
||||
can specify the next location number (to set the pointer to) by inserting a
|
||||
<i>DataItem</i> in the form @x ;where x is the location number. The following code
|
||||
writes the same data in the table above to locations 100 through 109:</p><pre class="BScode" xml:space="preserve">
|
||||
DATA @100, 72, 69, 76, 76, 79, 104, 101, 108, 108, 111
|
||||
</pre>
|
||||
<p class="PlainText">In this example, the first <i>DataItem </i>is @100. This tells the <span class="keyword_in_text">DATA</span> directive
|
||||
to store the following <i>DataItem</i>(s) starting at location 100. All the
|
||||
<i>DataItems</i> to the right of the @100 are stored in their respective locations
|
||||
(100, 101, 102... 109).</p>
|
||||
<p>In addition, the <span class="keyword_in_text">DATA</span> directive allows you to specify new starting locations
|
||||
at any time within the <i>DataItem</i> list. If, for example, you wanted to store
|
||||
56 at location 100 and 47 at location 150 (while leaving every other location intact),
|
||||
you could type the following:</p><pre class="BScode" xml:space="preserve">
|
||||
DATA @100, 56, @150, 47
|
||||
</pre>
|
||||
<p class="PlainText">If you have multiple <span class="keyword_in_text">DATA</span> directives in your program, it may be difficult
|
||||
to remember exactly what locations contain the desired data. For this reason, the
|
||||
<span class="keyword_in_text">DATA</span> directive can optionally be prefixed with a unique symbol name. This
|
||||
symbol becomes a constant that is set equal to the location number of the first
|
||||
byte of data within the directive. For example,</p><pre class="BScode" xml:space="preserve">
|
||||
MyNumbers DATA @100, 72, 73
|
||||
</pre>
|
||||
<p class="PlainText">This would store the values 72 and 73 starting with location 100 and will create
|
||||
a constant, called MyNumbers, which is set equal to 100. Your program can then
|
||||
use the MyNumbers constant as a reference to the start of the data within a <span class="keyword_in_text">READ</span>or <span class="keyword_in_text">WRITE</span> command. Each <span class="keyword_in_text">DATA</span> directive can have a unique symbol preceding
|
||||
it, allowing you to reference the data defined at different locations.</p>
|
||||
<p class="PlainText">There may be a time when you wish to reserve a section of EEPROM for use by your
|
||||
BASIC code, but not necessarily store data there to begin with. To do this, simply
|
||||
specify a <i>DataItem</i> within parentheses, as in:</p><pre class="BScode" xml:space="preserve">
|
||||
DATA @100, (20)
|
||||
</pre>
|
||||
<p class="PlainText">The above <span class="keyword_in_text">DATA</span> directive will reserve 20 bytes of EEPROM, starting with
|
||||
location 100. It doesn't store any values there, rather it simply leaves the data
|
||||
as it is and increments <span class="keyword_in_text">DATA</span>'s location pointer by 20. A good reason to
|
||||
do this is when you have a program already downloaded into the BASIC Stamp that
|
||||
has created or manipulated some data in EEPROM. To protect that section of EEPROM
|
||||
from being overwritten by your next program (perhaps a new version of the same
|
||||
program) you can reserve the space as shown above. The EEPROM's contents from
|
||||
locations 100 to 119 will remain intact. NOTE: This only "reserves" the space for
|
||||
the program you are currently downloading; the BASIC Stamp does not know to
|
||||
"reserve" the space for future programs. In other words, make sure use this
|
||||
feature of the <span class="keyword_in_text">DATA</span> directive in every program you download if you don't
|
||||
want to risk overwriting valuable EEPROM data.</p>
|
||||
<p class="PlainText">It is important to realize that EEPROM is not overwritten during programming
|
||||
unless it is needed for program storage, or is filled by a <span class="keyword_in_text">DATA</span> directive
|
||||
specifying data to be written. During downloading, EEPROM is always written in
|
||||
16-byte sections if, and only if, any location within that section needs writing. </p>
|
||||
<p class="PlainText"><span class="keyword_in_text">DATA</span> can also store the same number in a block of consecutive locations.
|
||||
This is similar to reserving a block of EEPROM, above, but with a value added before
|
||||
the first parenthesis. For example,</p><pre class="BScode" xml:space="preserve">
|
||||
DATA @100, 0 (20)
|
||||
</pre>
|
||||
<p class="PlainText">This statement writes the value 0 in all the EEPROM locations from 100 to 119.</p>
|
||||
<p>A common use for <span class="keyword_in_text">DATA</span> is to store strings; sequences of bytes representing
|
||||
text. PBASIC converts quoted text like "A" into the corresponding ASCII character
|
||||
code (65 in this case). To make data entry easier, you can place quotes around a
|
||||
whole chunk of text used in a <span class="keyword_in_text">DATA</span> directive, and PBASIC will understand
|
||||
it to mean a series of bytes (see the last line of code below). The following
|
||||
three <span class="keyword_in_text">DATA</span> directives are equivalent: </p><pre class="BScode" xml:space="preserve">
|
||||
DATA 72, 69, 76, 76, 79
|
||||
DATA "H", "E", "L", "L", "O"
|
||||
DATA "HELLO"
|
||||
</pre>
|
||||
<p class="PlainText">All three lines of code, above, will result in the numbers 72, 69, 76, 76, and
|
||||
79 being stored into EEPROM upon downloading. These numbers are simply the ASCII
|
||||
character codes for "H", "E", "L", "L", and "O", respectively. See the
|
||||
Example program link at the top for a demonstration of storing and
|
||||
reading multiple text strings.</p>
|
||||
<p class="PlainText">The EEPROM is organized as a sequential set of byte-sized memory locations.
|
||||
By default, the <span class="keyword_in_text">DATA</span> directive stores bytes into EEPROM. If you try to
|
||||
store a word-size value (ex: <span class="keyword_in_text">DATA</span> 1125) only the lower byte of the value
|
||||
will be stored. This does not mean that you can't store word-sized values, however.
|
||||
A word consists of two bytes, called a low-byte and a high-byte. If you wanted
|
||||
to store the value 1125 using the <span class="keyword_in_text">DATA</span> directive, simply insert the prefix
|
||||
"Word" before the number, as in:</p><pre class="BScode" xml:space="preserve">
|
||||
DATA Word 1125
|
||||
</pre>
|
||||
<p class="PlainText">The directive above will automatically break the word-size value into two bytes
|
||||
and store them into two sequential EEPROM locations (the low-byte first, followed
|
||||
by the high-byte, or "<i>Little Endian</i>"). In this case, the low-byte is 101
|
||||
and the high byte is 4 and they will be stored in locations 0 and 1, respectively.
|
||||
If you have multiple word-size values, you must prefix each value with "Word",
|
||||
as in:</p><pre class="BScode" xml:space="preserve">
|
||||
DATA Word 1125, Word 2000
|
||||
</pre>
|
||||
<p class="PlainText">To retrieve a word-size value, you'll need to use the Word modifier with
|
||||
<span class="keyword_in_text">READ</span> (only available in PBASIC 2.5 syntax). For example,</p><pre class="BScode" xml:space="preserve">
|
||||
' {$PBASIC 2.5}
|
||||
|
||||
result VAR Word
|
||||
|
||||
Storage:
|
||||
DATA Word 1125
|
||||
|
||||
Main:
|
||||
READ 0, Word result
|
||||
DEBUG DEC result
|
||||
END
|
||||
</pre>
|
||||
<p class="PlainText">This code would write the low-byte and high-byte of the number 1125 into locations
|
||||
0 and 1 during download. When the program runs, the <span class="keyword_in_text">READ</span> function (with
|
||||
the Word modifier) will retrieve the value out of EEPROM and then display the value
|
||||
on the screen. See the <a href="READ.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">READ</a> and <a href="WRITE.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">WRITE</a> commands for more information.</p>
|
||||
<p class="PlainText">Finally, a <i>DataItem</i> may be defined using a simple expression with the binary
|
||||
operators as shown below:</p><pre class="BScode" xml:space="preserve">
|
||||
MinLvl CON 10
|
||||
|
||||
myLvl VAR Byte
|
||||
|
||||
Level1 DATA MinLvl + 10
|
||||
Level2 DATA MinLvl * 5 + 21
|
||||
|
||||
Main:
|
||||
READ Level2, myLvl ' read EE location Level2
|
||||
DEBUG DEC myLvl ' show value of myLvl (71)
|
||||
END
|
||||
</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>
|
620
help/BasicStampHelp/Content/LanguageTopics/Commands/DEBUG.htm
Normal file
620
help/BasicStampHelp/Content/LanguageTopics/Commands/DEBUG.htm
Normal file
@ -0,0 +1,620 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns:MadCap="http://www.madcapsoftware.com/Schemas/MadCap.xsd" MadCap:lastBlockDepth="6" MadCap:lastHeight="94" MadCap:lastWidth="853" MadCap:disableMasterStylesheet="true" MadCap:tocPath="" MadCap:InPreviewMode="false" MadCap:PreloadImages="false" MadCap:RuntimeFileType="Topic" MadCap:TargetType="WebHelp" lang="en-us" xml:lang="en-us" MadCap:PathToHelpSystem="../../../" MadCap:HelpSystemFileName="Default.xml" MadCap:SearchType="Stem">
|
||||
<head><title>DEBUG</title>
|
||||
<link href="../../SkinSupport/MadCap.css" rel="stylesheet" />
|
||||
<link href="../../Resources/Stylesheets/BSE_Help.css" rel="stylesheet" />
|
||||
<script src="../../SkinSupport/MadCapAll.js" type="text/javascript">
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<h1 class="code">DEBUG</h1>
|
||||
<div class="ImagePlusCaption">
|
||||
<div class="Col2">
|
||||
<p>
|
||||
<img src="../../graphics/pgm_icon1.gif" border="0" alt="BS1 icon" title="BS1 icon" />
|
||||
<img src="../../graphics/pgm_icon2.gif" border="0" alt="BS2 icon" title="BS2 icon" />
|
||||
<img src="../../graphics/pgm_icon2e.gif" border="0" alt="BS2e icon" title="BS2e icon" />
|
||||
<img src="../../graphics/pgm_icon2sx.gif" border="0" alt="BS2sx icon" title="BS2sx icon" />
|
||||
<img src="../../graphics/pgm_icon2p.gif" border="0" alt="BS2p icon" title="BS2p icon" />
|
||||
<img src="../../graphics/pgm_icon2pe.gif" border="0" alt="BS2pe icon" title="BS2pe icon" />
|
||||
<img src="../../graphics/pgm_icon2px.gif" border="0" alt="BS2px icon" title="BS2px icon" />
|
||||
</p>
|
||||
</div>
|
||||
<p style="text-align: right;"><a href="../ExampleTopics/DebugEx.htm" target="" title="" alt="" class="MCXref_0">DEBUG Examples</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: <span class="keyword_in_text">DEBUG</span> <![CDATA[ ]]><i>OutputData </i>{, <i>OutputData</i>}</p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Display information on the PC screen within the BASIC Stamp editor program. This
|
||||
command can be used to display text or numbers in various formats on the PC screen
|
||||
in order to follow program flow (called debugging) or as part of the functionality
|
||||
of the BASIC Stamp application.
|
||||
</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>OutputData</i></b> is a variable/constant/expression* (0 - 65535) that
|
||||
specifies the information to output. Valid data can be ASCII characters (text
|
||||
strings and control characters), decimal numbers (0 - 65535), hexadecimal numbers
|
||||
($0000 - $FFFF) or binary numbers (up to %1111111111111111). Data can be
|
||||
modified with special formatters as explained below.</li>
|
||||
</ul>
|
||||
<p>*<img align="absmiddle" src="../../graphics/bs1note.gif" style="vertical-align: super;" /> Note: Expressions are not allowed as arguments on the BS1. The only
|
||||
constant allowed for the BS1 <span class="keyword_in_text">DEBUG</span> command is a text string.</p>
|
||||
<h2>Quick Facts<br /></h2>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF">
|
||||
<td width="16%" align="center"> </td>
|
||||
<td width="28%" align="center">BS1</td>
|
||||
<td width="28%" align="center">BS2, BS2e, BS2sx, BS2p, and BS2pe</td>
|
||||
<td width="28%" align="center">BS2px</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Serial Protocol</td>
|
||||
<td align="center">Asychronous 4800 baud, N, 8, 1<br></br>Inverted polarity,
|
||||
Raw Data<br></br>Custom packetized format</td>
|
||||
<td align="center">Asychronous 9600 baud, N, 8, 1<br></br>Inverted polarity,
|
||||
Raw Data</td>
|
||||
<td align="center">Asychronous 19.2 kBaud, N, 8, 1<br></br>Inverted polarity,
|
||||
Raw Data</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
||||
<td align="center" colspan="3">
|
||||
<p colspan="3" align="center"><a href="DEBUGIN.htm" target="" title="" alt="" class="MCXref_0">DEBUGIN</a>, <a href="SEROUT.htm" target="" title="" alt="" class="MCXref_0">SEROUT</a></p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText"><span class="keyword_in_text">DEBUG</span> provides a convenient way for your BASIC Stamp to send messages to
|
||||
the PC screen while running. The name "debug" suggests its most popular use;
|
||||
debugging programs by showing you the value of a variable or expression, or by
|
||||
indicating what portion of a program is currently executing. <span class="keyword_in_text">DEBUG</span> is also
|
||||
a great way to rehearse programming techniques. Throughout this manual, we use
|
||||
<span class="keyword_in_text">DEBUG</span> to give you immediate feedback on the effects of instructions. The
|
||||
following example demonstrates using the <span class="keyword_in_text">DEBUG</span> command to send the text
|
||||
string message "Hello World!". </p><pre class="BScode" xml:space="preserve">
|
||||
DEBUG "Hello, World!" ' test Message
|
||||
</pre>
|
||||
<p class="PlainText">After you download this one-line program, the BASIC Stamp Editor will open a
|
||||
Debug terminal on your PC screen and wait for a response from the BASIC Stamp.
|
||||
A moment later, the phrase "Hello World!" will appear. Note that if you close the
|
||||
Debug terminal, your program keeps executing, but you can't see the <span class="keyword_in_text">DEBUG</span>
|
||||
data anymore.</p>
|
||||
<p class="PlainText">Multiple pieces of data can be sent with one <span class="keyword_in_text">DEBUG</span> command by separating
|
||||
the data with commas (,). The following example produces exactly the same results
|
||||
as the example above.</p><pre class="BScode" xml:space="preserve">
|
||||
DEBUG "Hello, ", "World!" ' test Message
|
||||
</pre>
|
||||
<p class="PlainText"><span class="keyword_in_text">DEBUG</span> can also print and format numbers (values) from both constants
|
||||
and variables. Please note that formatting the <span class="keyword_in_text">DEBUG</span> output with the BS1
|
||||
differs significantly from formatting the <span class="keyword_in_text">DEBUG</span> output with the BS2 family.
|
||||
Please read the appropriate sections that follow carefully.</p>
|
||||
<p class="Tip" MadCap:autonum="Tip:  "><span class="autonumber"><span class="TipSpan">Tip:  </span></span><b>Don't let your BASIC Stamp be mistaken for a mouse! </b>
|
||||
<br />
|
||||
<br />Connecting USB-based boards to your PC may cause the BASIC Stamp to reset. If your BASIC Stamp program immediately starts sending serial data to the computer via a <span class="keyword_in_text">DEBUG</span> or <span class="keyword_in_text">SEROUT</span> command, your computer's operating system may mistake it for a mouse or other serial plug-and-play device. To avoid this, place a 1-second pause at the beginning of the program. </p>
|
||||
<h2>
|
||||
<img align="absmiddle" src="../../graphics/bs1_inline.gif" border="0" />  BASIC Stamp 1 Formatting</h2>
|
||||
<p class="PlainText">On the BS1, the <span class="keyword_in_text">DEBUG</span> command, by default, displays numbers in the format
|
||||
"symbol = value" (followed by a carriage return), using the decimal number system.
|
||||
For example: </p><pre class="BScode" xml:space="preserve">
|
||||
SYMBOL x = B2
|
||||
|
||||
Init:
|
||||
x = 75
|
||||
|
||||
Main:
|
||||
DEBUG x
|
||||
END
|
||||
</pre>
|
||||
<p class="PlainText">...displays "x = 75" on the screen. To display the value, in decimal, without
|
||||
the "x =" text, use the decimal formatter (#) before the variable name. For
|
||||
example, the following code displays "75" on the screen:</p><pre class="BScode" xml:space="preserve">
|
||||
SYMBOL x = B2
|
||||
|
||||
Init:
|
||||
x = 75
|
||||
|
||||
Main:
|
||||
DEBUG #x
|
||||
END
|
||||
</pre>
|
||||
<p class="PlainText">To display numbers in hexadecimal or binary form, use the $ or % formatter,
|
||||
respectively. The code below displays the same number in its hexadecimal and binary
|
||||
forms.</p><pre class="BScode" xml:space="preserve">
|
||||
SYMBOL x = B2
|
||||
|
||||
Init:
|
||||
x = 75
|
||||
|
||||
Main:
|
||||
DEBUG $x, %x
|
||||
END
|
||||
</pre>
|
||||
<p class="PlainText">After running the above code, "X = $4B" and "X = %01001011" should appear on the
|
||||
screen. To display hexadecimal ($) or binary (%) values without the "symbol = "
|
||||
preface, use the # modifier as shown below:</p><pre class="BScode" xml:space="preserve">
|
||||
SYMBOL x = B2
|
||||
|
||||
x = 75
|
||||
DEBUG #x, "as HEX is ", #$x ' displays "75 as HEX is $4B"
|
||||
</pre>
|
||||
<p class="PlainText">To display a number as its ASCII character equivalent, use the ASCII formatter
|
||||
(@). Typing <span class="keyword_in_text">DEBUG</span> @x (in place of the <span class="keyword_in_text">DEBUG</span> statement in the code
|
||||
above) would display "x = 'K'" on the screen.</p>
|
||||
<p class="PlainText">Two pre-defined symbols, CR and CLS, can be used to send a carriage-return or
|
||||
clear-screen command to the Debug Terminal. The CR symbol will cause the Debug
|
||||
Terminal to start a new line and the CLS symbol will cause the Debug Terminal to
|
||||
clear itself and place the cursor at the top-left corner of the screen. The
|
||||
following code demonstrates this.</p><pre class="BScode" xml:space="preserve">
|
||||
DEBUG "You can not see this.", CLS, "Here is line 1", CR, "Here is line 2"
|
||||
</pre>
|
||||
<p class="PlainText">When the above is run, the final result is "Here is line 1" on the first line
|
||||
of the screen and "Here is line 2" on the second line. You may or may not have
|
||||
seen "You can not see this." appear first. This is because it was immediately
|
||||
followed by a clear-screen symbol, CLS, which caused the display to clear the
|
||||
screen before displaying the rest of the information.</p>
|
||||
<p class="Tip" MadCap:autonum="Tip:  "><span class="autonumber"><span class="TipSpan">Tip:  </span></span><b>The rest of this discussion does not apply to the BASIC Stamp
|
||||
1.</b>
|
||||
</p>
|
||||
<h2>
|
||||
<img align="absmiddle" src="../../graphics/bsall_inline.gif" border="0" />  BASIC Stamp 2 Series Formatting</h2>
|
||||
<p class="PlainText">On the all BASIC Stamp models except the BS1, the <span class="keyword_in_text">DEBUG</span> command, by default,
|
||||
displays everything as ASCII characters. What if you want to display a number?
|
||||
You might think the following example would do this:</p><pre class="BScode" xml:space="preserve">
|
||||
x VAR Byte
|
||||
|
||||
Init:
|
||||
x = 65
|
||||
|
||||
Main:
|
||||
DEBUG x ' show value of x
|
||||
END
|
||||
</pre>
|
||||
<p class="PlainText">Since we set x equal to 65 (in line 2), you might expect the <span class="keyword_in_text">DEBUG</span> line
|
||||
to display "65" on the screen. Instead of "65", however, you'll see the letter
|
||||
"A" if you run this example. The problem is that we never told the BASIC Stamp
|
||||
how to output x, and it defaults to ASCII (the ASCII character at position 65 is
|
||||
"A"). Instead, we need to tell it to display the "decimal form" of the number in
|
||||
X. We can do this by using the decimal formatter (DEC) before the variable. The
|
||||
example below will display "65" on the screen.</p><pre class="BScode" xml:space="preserve">
|
||||
x VAR Byte
|
||||
|
||||
Init:
|
||||
x = 65
|
||||
|
||||
Main:
|
||||
DEBUG DEC x ' show decimal value of x
|
||||
END
|
||||
</pre>
|
||||
<p class="PlainText">In addition to decimal (DEC), <span class="keyword_in_text">DEBUG</span> can display numbers in hexadecimal
|
||||
(HEX) and binary (BIN). See the table below for a complete list of formatters.</p>
|
||||
<p>Expressions are allowed within the <span class="keyword_in_text">DEBUG</span> command arguments as well. In
|
||||
the above code, <span class="keyword_in_text">DEBUG</span> DEC x+25 would yield "90" and <span class="keyword_in_text">DEBUG</span> DEC
|
||||
x*10/2-3 would yield "322".</p>
|
||||
<p> </p>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF" align="center" valign="top">
|
||||
<td width="150">Formatter</td>
|
||||
<td width="80%">Description</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td>?</td>
|
||||
<td>Displays "symbol = x' + carriage return; where x is a number. Default
|
||||
format is decimal, but may be combined with conversion formatters (ex:
|
||||
BIN ? x to display "x = binary_number").</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td>ASC ?</td>
|
||||
<td>Displays "symbol = 'x'" + carriage return; where x is an ASCII character.</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td>DEC{1..5}</td>
|
||||
<td>Decimal, optionally fixed to 1 - 5 digits</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td>SDEC{1..5}</td>
|
||||
<td>Signed decimal, optionally fixed to 1 - 5 digits</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td>HEX{1..4}</td>
|
||||
<td>Hexadecimal, optionally fixed to 1 - 4 digits</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td>SHEX{1..4}</td>
|
||||
<td>Signed hexadecimal, optionally fixed to 1 - 4 digits </td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td>IHEX{1..4}</td>
|
||||
<td>Indicated hexadecimal, optionally fixed to 1 - 4 digits</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td>ISHEX{1..4}</td>
|
||||
<td>Signed, indicated hexadecimal, optionally fixed to 1 - 4 digits ($ prefix)</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td>BIN{1..16}</td>
|
||||
<td>Binary, optionally fixed to 1 - 16 digits</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td>SBIN{1..16}</td>
|
||||
<td>Signed binary, optionally fixed to 1 - 16 digits</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td>IBIN{1..16}</td>
|
||||
<td>Indicated binary, optionally fixed to 1 - 16 digits</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td>ISBIN{1..16}</td>
|
||||
<td>Signed, indicated binary, optionally fixed to 1 - 16 digits</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td>STR ByteArray</td>
|
||||
<td>ASCII string from bytearray until byte = 0.</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td>STR ByteArray {\L}</td>
|
||||
<td>ASCII string consisting of n bytes from bytearray.</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td>REP Byte\L</td>
|
||||
<td>Display ASCII character n times.</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p class="PlainText">As seen above, special versions of the DEC, HEX and BIN formatters allow for
|
||||
the display of indicated, signed and fixed-width numbers. The term "indicated"
|
||||
simply means that a special symbol is displayed, before the number, indicating
|
||||
what number system it belongs to. For example:</p><pre class="BScode" xml:space="preserve">
|
||||
x VAR Byte
|
||||
|
||||
Init:
|
||||
x = 65
|
||||
|
||||
Main:
|
||||
DEBUG HEX x ' show hexadecimal value of x
|
||||
END
|
||||
</pre>
|
||||
<p class="PlainText">...displays "41" (65, in decimal, is 41, in hexadecimal). You might see a problem
|
||||
here... unless you knew the number was supposed to be hexadecimal, you might think
|
||||
it was 41, in decimal... a totally different number. To help avoid this, use the
|
||||
IHEX formatter (the "I" stands for indicated). Changing the <span class="keyword_in_text">DEBUG</span> line to
|
||||
read: <span class="keyword_in_text">DEBUG</span> IHEX x would print "$41" on the screen. A similar formatter
|
||||
for binary also exists, IBIN, which prints a "%" before the number.</p>
|
||||
<p class="PlainText">Signed numbers are preceded with a space ( ) or a minus sign (-) to indicate a
|
||||
positive or negative number, respectively. Normally, any number displayed by the
|
||||
BASIC Stamp is shown in its unsigned (positive) form without any indicator. The
|
||||
signed formatters allow
|
||||
you to display the number as a signed (rather than unsigned) value.</p>
|
||||
<p class="Tip" MadCap:autonum="Tip:  "><span class="autonumber"><span class="TipSpan">Tip:  </span></span><b>Only
|
||||
Word-sized variables can be used for signed number display. </b>
|
||||
</p>
|
||||
<p class="PlainText">The code below
|
||||
demonstrates the difference in all three numbering schemes.</p><pre class="BScode" xml:space="preserve">
|
||||
x VAR Word
|
||||
|
||||
Init:
|
||||
x = -65
|
||||
|
||||
Main:
|
||||
DEBUG "Signed: ", SDEC x, " ", ISHEX x, " ", ISBIN x, CR
|
||||
DEBUG "Unsigned: ", DEC x, " ", IHEX x, " ", IBIN x
|
||||
END
|
||||
</pre>
|
||||
<p class="PlainText">This code will generate the display shown below:</p><pre>Signed: -65 -$41 -%1000001<br />Unsigned: 65471 $FFBF %1111111110111111
|
||||
</pre>
|
||||
<p class="PlainText">The signed form of the number -65 is shown in decimal, hexadecimal and then in
|
||||
binary on the top line. The unsigned form, in all three number systems, is shown
|
||||
on the bottom line. If the unsigned form looks strange to you, it's because negative
|
||||
numbers are stored in twos-compliment format within the BASIC Stamp. </p>
|
||||
<p class="PlainText">Suppose that your program contained several <span class="keyword_in_text">DEBUG</span> instructions showing
|
||||
the contents of different variables. You would want some way to tell them apart.
|
||||
One possible way is to do the following:</p><pre class="BScode" xml:space="preserve">
|
||||
x VAR Byte
|
||||
y VAR Byte
|
||||
|
||||
Init:
|
||||
x = 100
|
||||
y = 250
|
||||
|
||||
Main:
|
||||
DEBUG "X = ", DEC x, CR ' show decimal value of x
|
||||
DEBUG "Y = ", DEC y, CR ' show decimal value of y
|
||||
END
|
||||
</pre>
|
||||
<p class="PlainText">...but typing the name of the variables in quotes (for the display) can get a
|
||||
little tedious. A special formatter, the question mark (?), can save you a lot
|
||||
of time. The code below does exactly the same thing (with less typing):</p><pre class="BScode" xml:space="preserve">
|
||||
x VAR Byte
|
||||
y VAR Byte
|
||||
|
||||
Init:
|
||||
x = 100
|
||||
y = 250
|
||||
|
||||
Main:
|
||||
DEBUG DEC ? x ' show decimal value of x
|
||||
DEBUG DEC ? y ' show decimal value of y
|
||||
END
|
||||
</pre>
|
||||
<p class="PlainText">The display would look something like this:</p><pre>x = 100<br />y = 250
|
||||
</pre>
|
||||
<p class="PlainText">The ? formatter always displays data in the form "symbol = value" (followed by
|
||||
a carriage return). In addition, it defaults to displaying in decimal, so we really
|
||||
only needed to type: <span class="keyword_in_text">DEBUG</span> ? x for the above code. You can, of course,
|
||||
use any of the three number systems. For example: <span class="keyword_in_text">DEBUG</span> HEX ? x or
|
||||
<span class="keyword_in_text">DEBUG</span> BIN ? y. </p>
|
||||
<p class="PlainText">It's important to note that the "symbol" it displays is taken directly from what
|
||||
appears to the right of the ?. If you were to use an expression, for example:
|
||||
<span class="keyword_in_text">DEBUG</span> ? x*10/2+3 in the above code, the display would show: "x*10/2+3
|
||||
= 503". </p>
|
||||
<p class="PlainText">A special formatter, ASC, is also available for use only with the ? formatter
|
||||
to display ASCII characters, as in: <span class="keyword_in_text">DEBUG</span> ASC ? x.</p>
|
||||
<p class="PlainText">What if you need to display a table of data; multiple rows and columns? The
|
||||
Signed/Unsigned code (above) approaches this but, if you notice, the columns don't
|
||||
line up. The number formatters (DEC, HEX and BIN) have some useful variations to
|
||||
make the display fixed-width. Up to 5 digits can be displayed for decimal numbers.
|
||||
To fix the value to a specific number of decimal digits, you can use DEC1, DEC2,
|
||||
DEC3, DEC4 or DEC5. For example:</p><pre class="BScode" xml:space="preserve">
|
||||
x VAR Byte
|
||||
|
||||
Init:
|
||||
x = 165
|
||||
|
||||
Main:
|
||||
DEBUG DEC5 x ' show decimal value of x
|
||||
END ' in 5 digits
|
||||
</pre>
|
||||
<p class="PlainText">...displays "00165". Notice that leading zeros? The display is "fixed" to 5 digits,
|
||||
no more and no less. Any unused digits will be filled with zeros.</p>
|
||||
<p class="PlainText">Using DEC4 in the same code would display "0165". DEC3 would display "165".
|
||||
What would happen if we used DEC2? Regardless of the number, the BASIC Stamp will
|
||||
ensure that it is always the exact number of digits you specified. In this case,
|
||||
it would truncate the "1" and only display "65". </p>
|
||||
<p class="PlainText">Using the fixed-width version of the formatters in the Signed/Unsigned code
|
||||
above, may result in the following code:</p><pre class="BScode" xml:space="preserve">
|
||||
x VAR Word
|
||||
|
||||
Init:
|
||||
x = -65
|
||||
|
||||
Main:
|
||||
DEBUG "Signed: ", SDEC5 x, " ", ISHEX4 x, " ", ISBIN16 x, CR
|
||||
DEBUG "Unsigned: ", DEC5 x, " ", IHEX4 x, " ", IBIN16 x
|
||||
END
|
||||
</pre>
|
||||
<p>...and displays:</p><pre>Signed: -00065 -$0041 -%0000000001000001<br />Unsigned: 65471 $FFBF %1111111110111111
|
||||
</pre>
|
||||
<p class="PlainText">Note that the columns don't line up exactly (due to the extra "sign" characters
|
||||
in the first row), but it certainly looks better than the alternative.</p>
|
||||
<h3><a name="Displayi"></a>Displaying Strings (Byte Arrays)</h3>
|
||||
<p class="PlainText">If you have a string of characters to display (a byte array), you can use the
|
||||
STR formatter to do so. The STR formatter has two forms (as shown in the table above)
|
||||
for variable-width and fixed-width data. The example below is the variable-width
|
||||
form.</p><pre class="BScode" xml:space="preserve">
|
||||
alpha VAR Byte(5)
|
||||
|
||||
Init:
|
||||
alpha(0) = "A"
|
||||
alpha(1) = "B"
|
||||
alpha(2) = "C"
|
||||
alpha(3) = "D"
|
||||
alpha(4) = 0
|
||||
|
||||
Main:
|
||||
DEBUG STR alpha, CR ' display "ABCD"
|
||||
END
|
||||
</pre>
|
||||
<p class="PlainText">This code displays "ABCD" on the screen. In this form, the STR formatter displays
|
||||
each character contained in the byte array until it finds a character that is equal
|
||||
to 0 (value 0, not "0"). This is convenient for use with the <a href="SERIN.htm" target="" title="" alt="" class="MCXref_0">SERIN</a> command's STR
|
||||
formatter, which appends 0's to the end of variable-width character string inputs.
|
||||
NOTE: If your byte array doesn't end with 0, the BASIC Stamp will read and output
|
||||
all RAM register contents until it finds a 0 or until it cycles through all RAM
|
||||
locations.</p>
|
||||
<p class="PlainText">To specify a fixed-width format for the STR formatter, use the form STR alpha\n;
|
||||
where alpha is the byte array and n is the number of characters to print. Changing
|
||||
the <span class="keyword_in_text">DEBUG</span> line in the example above to: <span class="code_in_text">DEBUG STR alpha\2</span> would display
|
||||
"AB" on the screen.</p>
|
||||
<p class="PlainText">If you need to display the same ASCII character multiple times, the REP (repeat)
|
||||
formatter can help. REP takes the form: REP x\n ;where x is the character and
|
||||
n is the number of times to repeat it. For example:</p><pre class="BScode" xml:space="preserve">
|
||||
DEBUG REP "-"\10
|
||||
</pre>
|
||||
<p class="PlainText">...would display 10 hyphens on the screen, "<tt>----------</tt>". </p>
|
||||
<p class="PlainText">Since individual <span class="keyword_in_text">DEBUG</span> instructions can grow to be fairly complicated,
|
||||
and since a program can contain many <span class="keyword_in_text">DEBUG</span>s, you'll probably want to control
|
||||
the character positioning of the Debug Terminal screen. <span class="keyword_in_text">DEBUG</span> supports a
|
||||
number of different control characters, some with pre-defined symbols. The Debug
|
||||
Terminal in the Windows<sup>®</sup> version of the editor supports all the
|
||||
control characters shown below, while the DOS version only supports a few of them.</p>
|
||||
<p class="PlainText">Some of the control characters have pre-defined symbols associated with them.
|
||||
In your <span class="keyword_in_text">DEBUG</span> commands, you can use those symbols, for example: <span class="keyword_in_text">DEBUG</span>"Hello", CR displays "Hello" followed by a carriage return. You can always use
|
||||
the ASCII value for any of the control characters, however. For example: <span class="keyword_in_text">DEBUG</span>"Hello", 13 is exactly the same as the code above.</p>
|
||||
<p class="PlainText">The Move To control character is perhaps the most unique of the set. If the
|
||||
Debug Terminal receives this character, it expects to see an x and y position value
|
||||
to follow (in the next two characters received). The following line moves the
|
||||
cursor to column number 4 in row number 5 and displays "Hello":</p><pre class="BScode" xml:space="preserve">
|
||||
DEBUG CRSRXY, 4, 5, "Hello"
|
||||
</pre>
|
||||
<p class="PlainText">The upper-left cursor position is 0, 0 (that is column 0, line 0). The right-most
|
||||
cursor positions depend on the size of the Debug Terminal window (which is user
|
||||
adjustable). If a character position that is out of range is received, the Debug
|
||||
Terminal wraps back around to the opposite side of the screen.</p>
|
||||
<p class="PlainText">The Clear EOL (end of line) control character clears the characters that appear
|
||||
to the right of, and on, the cursor's current position. The cursor is not moved
|
||||
by this action.</p>
|
||||
<p class="PlainText">The Clear Down control character clears the characters that appear below, and
|
||||
on, the cursor's current line. The cursor is not moved by this action.</p>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF" align="center" valign="top">
|
||||
<td width="150">Name</td>
|
||||
<td width="75">Symbol</td>
|
||||
<td width="75">ASCII<br></br>Value</td>
|
||||
<td width="1000">Description</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td width="150">Clear Screen</td>
|
||||
<td width="75" align="center">CLS <sup>1</sup></td>
|
||||
<td width="75" align="center">0</td>
|
||||
<td width="1000">Clear the screen and place cursor at home position.</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td width="150">Home</td>
|
||||
<td width="75" align="center">HOME</td>
|
||||
<td width="75" align="center">1</td>
|
||||
<td width="1000">Place cursor at home in upper-left corner of the screen.</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td width="150">Move To (x, y)</td>
|
||||
<td width="75" align="center">CRSRXY <sup>2</sup></td>
|
||||
<td width="75" align="center">2</td>
|
||||
<td width="1000">Move cursor to specified location (column, line). Must be
|
||||
followed by two values (x and then y)</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td width="150">Cursor Left</td>
|
||||
<td width="75" align="center">CRSRLF <sup>2</sup></td>
|
||||
<td width="75" align="center">3</td>
|
||||
<td width="1000">Move cursor one character to left.</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td width="150">Cursor Right</td>
|
||||
<td width="75" align="center">CRSRRT <sup>2</sup></td>
|
||||
<td width="75" align="center">4</td>
|
||||
<td width="1000">Move cursor one character to right.</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td width="150">Cursor Up</td>
|
||||
<td width="75" align="center">CRSRUP <sup>2</sup></td>
|
||||
<td width="75" align="center">5</td>
|
||||
<td width="1000">Move cursor one character up.</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td width="150">Cursor Down</td>
|
||||
<td width="75" align="center">CRSRDN <sup>2</sup></td>
|
||||
<td width="75" align="center">6</td>
|
||||
<td width="1000">Move cursor one character down.</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td width="150">Bell</td>
|
||||
<td width="75" align="center">BELL</td>
|
||||
<td width="75" align="center">7</td>
|
||||
<td width="1000">Beep the PC speaker.</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td width="150">Backspace</td>
|
||||
<td width="75" align="center">BKSP</td>
|
||||
<td width="75" align="center">8</td>
|
||||
<td width="1000">Back up cursor to left one space.</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td width="150">Tab</td>
|
||||
<td width="75" align="center">TAB</td>
|
||||
<td width="75" align="center">9</td>
|
||||
<td width="1000">Tab to the next column.</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td width="150">Line Feed</td>
|
||||
<td width="75" align="center">LF</td>
|
||||
<td width="75" align="center">10</td>
|
||||
<td width="1000">Move cursor down one line.</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td width="150">Clear to End of Line</td>
|
||||
<td width="75" align="center">CLREOL <sup>2</sup></td>
|
||||
<td width="75" align="center">11</td>
|
||||
<td width="1000">Clear line contents to the right of cursor.</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td width="150">Clear Down</td>
|
||||
<td width="75" align="center">CLRDN <sup>2</sup></td>
|
||||
<td width="75" align="center">12</td>
|
||||
<td width="1000">Clear screen contents below cursor.</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td width="150">Carriage Return</td>
|
||||
<td width="75" align="center">CR <sup>1</sup></td>
|
||||
<td width="75" align="center">13</td>
|
||||
<td width="1000">Move cursor to the first column of the next line (shift any
|
||||
data on the right down to that line as well)</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td width="150">Move To Column X</td>
|
||||
<td width="75" align="center">CRSRX <sup>2</sup></td>
|
||||
<td width="75" align="center">14</td>
|
||||
<td width="1000">Move cursor to specified column. Must be followed by byte
|
||||
value (x) for the column (0 is the left-most column)</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td width="150">Move To Line Y</td>
|
||||
<td width="75" align="center">CRSRY <sup>2</sup></td>
|
||||
<td width="75" align="center">15</td>
|
||||
<td width="1000">Move cursor to specified line. Must be followed by byte
|
||||
value (y) for the line (0 is the top-most line)</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p><sup>1</sup> Supported by BS1 <span class="keyword_in_text">DEBUG </span>command (others not supported).<br /><sup>2</sup> This control character only works with the Windows<sup>®</sup>
|
||||
version of the editor software.</p>
|
||||
<p class="PlainText"> </p>
|
||||
<p class="PlainText">In the BS2 family, <span class="keyword_in_text">DEBUG</span> is actually a special case of the <span class="keyword_in_text">SEROUT</span>instruction. It is set for inverted (RS-232-compatible) serial output through the
|
||||
programming connector (the SOUT pin) at 9600 baud (BS2, BS2e, BS2sx, BS2p, and
|
||||
BS2pe) or 19.2 kBaud (BS2px), no parity, 8 data bits, and 1 stop bit.
|
||||
For example,</p><pre class="BScode" xml:space="preserve">
|
||||
DEBUG "Hello"
|
||||
</pre>
|
||||
<p class="PlainText">...is exactly like:</p><pre class="BScode" xml:space="preserve">
|
||||
SEROUT 16, $4054, ["Hello"]
|
||||
</pre>
|
||||
<p class="PlainText">in terms of function (on a BS2). The <span class="keyword_in_text">DEBUG</span> line actually takes less
|
||||
program space, and is obviously easier to type.</p>
|
||||
<p class="PlainText">You may view <span class="keyword_in_text">DEBUG</span>'s output using a terminal program set to the above
|
||||
parameters, but you may have to modify either your carrier board or the serial
|
||||
cable to temporarily disconnect pin 3 of the BASIC Stamp (pin 4 of the DB-9
|
||||
connector). See the <a href="SEROUT.htm" target="" title="" alt="" class="MCXref_0">SEROUT</a> command for more detail. </p>
|
||||
<p class="PlainText">Another method to decrease program space is to reduce the number of <span class="keyword_in_text">DEBUG</span>
|
||||
instructions by spreading <span class="keyword_in_text">DEBUG</span> data across multiple lines. To do this,
|
||||
each line that wraps around must end with a comma as in the example below:
|
||||
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
DEBUG "This is line 1", CR,
|
||||
"This is line 2"
|
||||
</pre>
|
||||
<p class="PlainText">The example above works identically to, but uses less program space than, this version:</p><pre class="BScode" xml:space="preserve">
|
||||
DEBUG "This is line 1", CR
|
||||
DEBUG "This is line 2"
|
||||
</pre>
|
||||
<p class="Tip" MadCap:autonum="Tip:  "><span class="autonumber"><span class="TipSpan">Tip:  </span></span>Note that spreading a <span class="keyword_in_text">DEBUG</span> statement across multiple lines requires the
|
||||
declaration of PBASIC 2.5 syntax.</p>
|
||||
<div class="Col2">
|
||||
<div class="MasterFoot">
|
||||
<p MadCap:conditions="BSEconditions.BSEWebHelp (Primary)-INCLUDE"><a href="../../HomeTopics/HomePage.htm">Go to Welcome page</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="Col2">
|
||||
<div class="MasterFoot">
|
||||
<p style="text-align: right;"><span class="ContactInfoProjectName">BASIC Stamp Help</span> <![CDATA[ ]]><span class="ContactInfoVersion#">Version 2.5.4</span> <![CDATA[ ]]></p>
|
||||
<p style="text-align: right;">Copyright © <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>
|
305
help/BasicStampHelp/Content/LanguageTopics/Commands/DEBUGIN.htm
Normal file
305
help/BasicStampHelp/Content/LanguageTopics/Commands/DEBUGIN.htm
Normal file
@ -0,0 +1,305 @@
|
||||
<?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>DEBUGIN</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">DEBUGIN</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;"><a href="../ExampleTopics/DebugDebuginEx.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">DEBUG / DEBUGIN Example</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: <span class="keyword_in_text">DEBUGIN</span> <![CDATA[ ]]><i>InputData</i></p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Retrieve information from the user via the Debug Terminal window within the BASIC Stamp editor program.
|
||||
|
||||
</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>InputData</i></b> is list of variables and formatters that tells
|
||||
<span class="keyword_in_text">DEBUGIN</span> what to do with incoming data. <span class="keyword_in_text">DEBUGIN</span> can store data in
|
||||
a variable or array, interpret numeric text (decimal, binary, or hex) and store
|
||||
the corresponding value in a variable, wait for a fixed or variable sequence of
|
||||
bytes, or ignore a specified number of bytes. These actions can be combined
|
||||
in any order in the <i>InputData</i> list.</li>
|
||||
</ul>
|
||||
<h2>Quick Facts<br /></h2>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF">
|
||||
<td width="20%" align="center"> </td>
|
||||
<td width="40%" align="center">BS2, BS2e, BS2sx, BS2p, and BS2pe</td>
|
||||
<td width="40%" align="center">BS2px</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Serial Protocol</td>
|
||||
<td align="center">Asychronous 9600 baud, N, 8, 1<br></br>Inverted polarity,
|
||||
Raw Data</td>
|
||||
<td align="center">Asychronous 19.2 kBaud, N, 8, 1<br></br>Inverted polarity,
|
||||
Raw Data</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
||||
<td align="center" colspan="2">
|
||||
<p colspan="2" align="center"><a href="DEBUG.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">DEBUG</a>, <a href="SERIN.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">SERIN</a></p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText"><span class="keyword_in_text">DEBUGIN</span> provides a convenient way for your BASIC Stamp accept input from
|
||||
the use via the Debug Terminal. <span class="keyword_in_text">DEBUGIN</span> can wait for, filter and
|
||||
convert incoming data in powerful ways, using the same techniques and modifiers
|
||||
as <a href="SERIN.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">SERIN</a>.
|
||||
|
||||
</p>
|
||||
<p class="PlainText">This simple example waits for a number from the user, then prints a message
|
||||
the specified number of times: </p><pre class="BScode" xml:space="preserve">
|
||||
lines VAR Nib
|
||||
idx VAR Nib
|
||||
|
||||
Main:
|
||||
DEBUG CLS, "How many lines to print (1 - 5)? --> "
|
||||
DEBUGIN DEC1 lines
|
||||
|
||||
IF ((lines >= 1) AND (lines <= 5)) THEN
|
||||
DEBUG CR, CR
|
||||
FOR idx = 1 TO lines ' print message specified times
|
||||
DEBUG DEC1 idx, ". "
|
||||
DEBUG "BASIC Stamp!", CR
|
||||
NEXT
|
||||
END ' end of program
|
||||
ELSE
|
||||
DEBUG CR, "Invalid entry!" ' warning message
|
||||
PAUSE 2000 ' wait 2 seconds
|
||||
GOTO Main ' get another entry
|
||||
ENDIF
|
||||
</pre>
|
||||
<p class="PlainText">After you download this program, the BASIC Stamp Editor will open a Debug
|
||||
Terminal on your PC screen and wait for an entry from the user. Since the DEC1
|
||||
modifier is used with <span class="keyword_in_text">DEBUGIN</span>, the program will ignore all keys except
|
||||
"0" - "9". If the value entered is between 1 and 5, the message will be printed,
|
||||
otherwise the program will display an "Invalid entry" message, then loop back
|
||||
and wait for another entry.</p>
|
||||
<p class="PlainText"><span class="keyword_in_text">DEBUGIN</span> is actually a special case of the <span class="keyword_in_text">SERIN</span> instruction. It
|
||||
is set for inverted (RS-232-compatible) serial output through the programming
|
||||
connector (the SIN pin) at 9600 baud (BS2, BS2e, BS2sx, BS2p, and BS2pe) or
|
||||
19.2 kBaud (BS2px), no parity, 8 data bits, and 1 stop bit.
|
||||
For example,</p><pre class="BScode" xml:space="preserve">
|
||||
DEBUGIN DEC1 lines
|
||||
</pre>
|
||||
<p class="PlainText">...is exactly like:</p><pre class="BScode" xml:space="preserve">
|
||||
SERIN 16, $4054, [DEC1 lines]
|
||||
</pre>
|
||||
<p class="PlainText">...in terms of function (on a BS2). The <span class="keyword_in_text">DEBUGIN</span> line actually takes less
|
||||
program space, and is obviously easier to type.</p>
|
||||
<p class="PlainText">The tables below list all the available conversion formatters and special
|
||||
formatters available to the <span class="keyword_in_text">DEBUGIN</span> command. See the
|
||||
<a href="SERIN.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">SERIN</a> command for additional information and examples
|
||||
of their use.</p>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF" align="center" valign="top">
|
||||
<td width="15%">Conversion Formatter</td>
|
||||
<td width="45%">Type of Number</td>
|
||||
<td width="30%">Numeric Characters Accepted</td>
|
||||
<td width="10%">Notes</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>DEC{1..5}</td>
|
||||
<td>Decimal, optionally limited to 1 - 5 digits</td>
|
||||
<td>0 through 9</td>
|
||||
<td>1</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>SDEC{1..5}</td>
|
||||
<td>Signed decimal, optionally limited to 1 - 5 digits</td>
|
||||
<td>-, 0 through 9</td>
|
||||
<td>1,2</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>HEX{1..4}</td>
|
||||
<td>Hexadecimal, optionally limited to 1 - 4 digits</td>
|
||||
<td>0 through 9, A through F</td>
|
||||
<td>1,3</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>SHEX{1..4}</td>
|
||||
<td>Signed hexadecimal, optionally limited to 1 - 4 digits </td>
|
||||
<td>-, 0 through 9, A through F</td>
|
||||
<td>1,2,3</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>IHEX{1..4}</td>
|
||||
<td>Indicated hexadecimal, optionally limited to 1 - 4 digits</td>
|
||||
<td>$, 0 through 9, A through F</td>
|
||||
<td>1,3,4</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>ISHEX{1..4}</td>
|
||||
<td>Signed, indicated hexadecimal, optionally limited to 1 - 4 digits</td>
|
||||
<td>-, $, 0 through 9, A through F</td>
|
||||
<td>1,2,3,4</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>BIN{1..16}</td>
|
||||
<td>Binary, optionally limited to 1 - 16 digits</td>
|
||||
<td>0, 1</td>
|
||||
<td>1</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>SBIN{1..16}</td>
|
||||
<td>Signed binary, optionally limited to 1 - 16 digits</td>
|
||||
<td>-, 0, 1</td>
|
||||
<td>1,2</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>IBIN{1..16}</td>
|
||||
<td>Indicated binary, optionally limited to 1 - 16 digits</td>
|
||||
<td>%, 0, 1</td>
|
||||
<td>1,4</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>ISBIN{1..16}</td>
|
||||
<td>Signed, indicated binary, optionally limited to 1 - 16 digits</td>
|
||||
<td>-, %, 0, 1</td>
|
||||
<td>1,2,4</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>NUM</td>
|
||||
<td>Generic numeric input; hex or binary number must be indicated</td>
|
||||
<td>$, %, 0 through 9, A through F</td>
|
||||
<td>1,3,4</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>SNUM</td>
|
||||
<td>Similar to NUM with value treated as signed with range -32768 to +32767</td>
|
||||
<td>-, $, %, 0 through 9, A through F</td>
|
||||
<td>1,2,3,4</td>
|
||||
</tr>
|
||||
</table>
|
||||
<ol>
|
||||
<li value="1">All numeric conversions will continue to accept new data until receiving
|
||||
either the specified number of digits (ex: three digits for DEC3) or a
|
||||
non-numeric character.</li>
|
||||
<li value="2">To be recognized as part of a number, the minus sign (-) must immediately
|
||||
precede a numeric character. The minus sign character occurring in non-numeric
|
||||
text is ignored and any character (including a space) between a minus and a
|
||||
number causes the minus to be ignored.</li>
|
||||
<li value="3">The hexadecimal formatters are not case-sensitive; "a" through "f" means
|
||||
the same as "A" through "F".</li>
|
||||
<li value="4">Indicated hexadecimal and binary formatters ignore all characters, even
|
||||
valid numerics, until they receive the appropriate prefix ($ for hexadecimal,
|
||||
% for binary). The indicated formatters can differentiate between text and
|
||||
hexadecimal (ex: ABC would be interpreted by HEX as a number but IHEX would
|
||||
ignore it unless expressed as $ABC). Likewise, the binary version can
|
||||
distinguish the decimal number 10 from the binary number %10. A prefix
|
||||
occurring in non-numeric text is ignored, and any character (including a
|
||||
space) between a prefix and a number causes the prefix to be ignored. Indicated,
|
||||
signed formatters require that the minus sign come before the prefix, as
|
||||
in -$1B45.</li>
|
||||
</ol>
|
||||
<p> </p>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF" align="center" valign="top">
|
||||
<td width="150">Special Formatter</td>
|
||||
<td>Action</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">STR ByteArray \L {\E}</td>
|
||||
<td>Input a character string of length L into an array. If specified, an end
|
||||
character E causes the string input to end before reaching length L.
|
||||
Remaining bytes are filled with 0s (zeros).</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">WAITSTR ByteArray {\L}</td>
|
||||
<td>Wait for a sequence of bytes matching a string stored in an array variable,
|
||||
optionally limited to L characters. If the optional L argument is left off,
|
||||
the end of the array-string must be marked by a byte containing a zero (0).</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">SKIP Length</td>
|
||||
<td>Ignore Length bytes of characters.</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p> </p>
|
||||
<p>
|
||||
<img src="../../graphics/bs2ppepx_inline.gif" border="0" />
|
||||
<br />
|
||||
</p>
|
||||
<p>
|
||||
<br />
|
||||
</p>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF" align="center" valign="top">
|
||||
<td width="150">Special Formatter</td>
|
||||
<td>Action</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">SPSTR L</td>
|
||||
<td>Buffer length L bytes (up to 126) of serial characters to Scratchpad RAM,
|
||||
starting at location 0. Use <a href="GET.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">GET</a> to retrieve the
|
||||
characters.</td>
|
||||
</tr>
|
||||
</table><pre class="BScode" xml:space="preserve">
|
||||
idx VAR Nib
|
||||
char VAR Byte
|
||||
|
||||
Setup:
|
||||
DEBUG CLS, "Enter (4-character) passcode: "
|
||||
|
||||
Main:
|
||||
DEBUGIN SPSTR 4
|
||||
DEBUG CLS, "Checking: "
|
||||
FOR idx = 0 TO 3
|
||||
GET idx, char
|
||||
DEBUG char
|
||||
NEXT
|
||||
END
|
||||
</pre>
|
||||
<p class="PlainText">The example above will redirect four characters from the Debug Terminal
|
||||
input to Scratchpad locations 0 - 3.</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>
|
148
help/BasicStampHelp/Content/LanguageTopics/Commands/DO_LOOP.htm
Normal file
148
help/BasicStampHelp/Content/LanguageTopics/Commands/DO_LOOP.htm
Normal file
@ -0,0 +1,148 @@
|
||||
<?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>DO…LOOP</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">DO…LOOP</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;"><a href="../ExampleTopics/DoLoopEx.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">DO...LOOP Example</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax:</p>
|
||||
<p class="PlainText"><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> }<br />     <i>Statement(s)</i><br />   <span class="keyword_in_text">LOOP</span> { <span class="keyword_in_text">WHILE</span> | <span class="keyword_in_text">UNTIL</span> <![CDATA[ ]]><i>condition(s)</i> }
|
||||
</p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Create a repeating loop that executes the program lines between <span class="keyword_in_text">DO</span> and
|
||||
<span class="keyword_in_text">LOOP</span>, optionally testing before or after the loop statements
|
||||
|
||||
</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Condition</i></b> is an optional variable/constant/expression (0 -
|
||||
65535) which determines whether the loop will run or terminate.</li>
|
||||
<li value="2"><b><i>Statement</i></b> is any valid PBASIC statement.</li>
|
||||
</ul>
|
||||
<h2>Quick Facts<br /></h2>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr>
|
||||
<td width="26%" align="center" bgcolor="#CFCFCF"> </td>
|
||||
<td width="64%" align="center" bgcolor="#CFCFCF">BS2 Family</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Maximum nested loops</td>
|
||||
<td align="center">16</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">WHILE <i>Condition</i> evaluation</td>
|
||||
<td align="center">Run loop if <i>Condition</i> evaluates as True (1)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">UNTIL <i>Condition</i> evaluation</td>
|
||||
<td align="center">Terminate loop if <i>Condition</i> evaluates as True (1)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
||||
<td align="center" colspan="1">
|
||||
<p colspan="1" align="center"><a href="EXIT.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">EXIT</a>, <a href="FOR_NEXT.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">FOR…NEXT</a></p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText"><span class="keyword_in_text">DO...LOOP</span> loops let your program execute a series of instructions
|
||||
indefinitely, or until a specified condition terminates the loop. The simplest
|
||||
form is shown here: </p><pre class="BScode" xml:space="preserve">
|
||||
Error_Message:
|
||||
DO
|
||||
DEBUG "Error...", CR
|
||||
PAUSE 2000
|
||||
LOOP
|
||||
</pre>
|
||||
<p class="PlainText">In this example the error message will be printed on the
|
||||
<a href="DEBUG.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">DEBUG</a> screen every two seconds until the BASIC Stamp is
|
||||
reset. Simple <span class="keyword_in_text">DO...LOOP</span> loops can be terminated with
|
||||
<a href="EXIT.htm" class="MCXref_0" xrefformat="{paratext}">EXIT</a>. For example:</p><pre class="BScode" xml:space="preserve">
|
||||
Error_Message:
|
||||
DO
|
||||
DEBUG "Error...", CR
|
||||
PAUSE 1000
|
||||
IF (AckPin = 0) THEN EXIT ' wait for user button press
|
||||
LOOP
|
||||
GOTO Initialize ' re-initialize system
|
||||
</pre>
|
||||
<p class="PlainText">In this case the loop will continue until the pin named AckPin is pulled low,
|
||||
then the loop will terminate and continue at the line <span class="code_in_text">GOTO Initialize</span>.</p>
|
||||
<p class="PlainText">More often than not, you will want to test some condition to determine whether
|
||||
the loop code should run or continue to run. A loop that tests the condition before
|
||||
running loop code is constructed like this:</p><pre class="BScode" xml:space="preserve">
|
||||
reps VAR Nib
|
||||
|
||||
Print_Stars:
|
||||
DO WHILE (reps < 3) ' test before loop statements
|
||||
DEBUG "*"
|
||||
reps = reps + 1
|
||||
LOOP
|
||||
</pre>
|
||||
<p class="PlainText">In this program the loop code <span class="code_in_text">DEBUG "*"</span> will not run unless the <span class="keyword_in_text">WHILE</span>
|
||||
condition evaluates as True. Another way to write the loop is like this:</p><pre class="BScode" xml:space="preserve">
|
||||
reps VAR Nib
|
||||
|
||||
Print_Stars:
|
||||
DO
|
||||
DEBUG "*"
|
||||
reps = reps + 1
|
||||
LOOP UNTIL (reps >= 3) ' test after loop statements
|
||||
</pre>
|
||||
<p class="PlainText">The difference is that with this loop, the loop statements will always run at
|
||||
least once before the condition is tested and will continue to as long as the
|
||||
<span class="keyword_in_text">UNTIL</span> condition evaluates as False.</p>
|
||||
<p class="PlainText">Note that <span class="keyword_in_text">WHILE</span> (loop runs while True) and <span class="keyword_in_text">UNTIL</span> (loop runs until
|
||||
True) tests can be interchanged, but are generally used as illustrated above.
|
||||
</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>
|
201
help/BasicStampHelp/Content/LanguageTopics/Commands/DTMFOUT.htm
Normal file
201
help/BasicStampHelp/Content/LanguageTopics/Commands/DTMFOUT.htm
Normal file
@ -0,0 +1,201 @@
|
||||
<?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>DTMFOUT</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">DTMFOUT</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" />
|
||||
</p>
|
||||
</div>
|
||||
<p style="text-align: right;"><a href="../ExampleTopics/DtmfoutEx.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">DTMFOUT Example</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: <span class="keyword_in_text">DTMFOUT</span> <![CDATA[ ]]><i>Pin</i>, {<i>OnTime</i>,<i> OffTime</i>,} [<i>Tone
|
||||
</i>{,<i> Tone...</i>}]</p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Generate dual-tone, multi-frequency tones (DTMF, i.e., telephone "touch" tones).
|
||||
|
||||
</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Pin</i></b> is a variable/constant/expression (0 - 15) that specifies
|
||||
the I/O pin to use. This pin will be set to output mode during generation of
|
||||
tones and set to input mode afterwards.</li>
|
||||
<li value="2"><b><i>OnTime</i></b> is an optional variable/constant/expression (0 - 65535)
|
||||
specifying a duration of the tone. The unit of time and the default time for
|
||||
<i>OnTime</i> is described below. </li>
|
||||
<li value="3"><b><i>OffTime</i></b> is an optional variable/constant/expression (0 - 65535)
|
||||
specifying the length of silent pause after a tone (or between tones, if
|
||||
multiple tones are specified). The unit of time and the default time for
|
||||
<i>OffTime</i> is described below.</li>
|
||||
<li value="4"><b><i>Tone</i></b> is a variable/constant/expression (0 - 15) specifying the
|
||||
DTMF tone to generate. Tones 0 through 11 correspond to the standard layout
|
||||
of the telephone keypad, while 12 through 15 are the fourth-column tones used
|
||||
by phone test equipment and in ham-radio applications. </li>
|
||||
</ul>
|
||||
<h2>Quick Facts<br /></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">BS2 / 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">Default <i>OnTime</i></td>
|
||||
<td align="center">200 ms</td>
|
||||
<td align="center">80 ms</td>
|
||||
<td align="center">55 ms</td>
|
||||
<td align="center">196 ms</td>
|
||||
<td align="center">34 ms</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Default <i>OffTime</i></td>
|
||||
<td align="center">50 ms</td>
|
||||
<td align="center">50 ms</td>
|
||||
<td align="center">50 ms</td>
|
||||
<td align="center">50 ms</td>
|
||||
<td align="center">50 ms</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Units in <i>OnTime</i></td>
|
||||
<td align="center">1 ms</td>
|
||||
<td align="center">0.4 ms</td>
|
||||
<td align="center">0.265 ms</td>
|
||||
<td align="center">1 ms</td>
|
||||
<td align="center">0.166 ms</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Units in <i>OffTime</i></td>
|
||||
<td align="center">1 ms</td>
|
||||
<td align="center">1 ms</td>
|
||||
<td align="center">1 ms</td>
|
||||
<td align="center">1 ms</td>
|
||||
<td align="center">1 ms</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
||||
<td align="center" colspan="5">
|
||||
<p colspan="5" align="center"><a href="SOUND.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">SOUND</a>,  <a href="FREQOUT.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">FREQOUT</a></p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText">DTMF tones are used to dial the phone or remotely control certain radio equipment.
|
||||
The BASIC Stamp can generate these tones digitally using the <span class="keyword_in_text">DTMFOUT</span>
|
||||
instruction. </p>
|
||||
<p class="PlainText">This figure shows how to connect an audio amplifier or speaker to hear these
|
||||
tones:</p>
|
||||
<center>
|
||||
<img src="../../graphics/freqout_sch.gif" border="0">
|
||||
</img>
|
||||
</center>
|
||||
<p class="PlainText">...and this figure shows how to connect the BASIC Stamp to the phone line:</p>
|
||||
<center>
|
||||
<img src="../../graphics/daa_sch.gif" border="0">
|
||||
</img>
|
||||
</center>
|
||||
<p class="PlainText">The following <span class="keyword_in_text">DTMFOUT</span> instruction will generate DTMF tones on I/O pin 0:
|
||||
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
' Call Parallax
|
||||
DTMFOUT 0, [1, 9, 1, 6, 6, 2, 4, 8, 3, 3, 3]
|
||||
</pre>
|
||||
<p class="PlainText">If the BASIC Stamp is connected to the phone line properly, the above command
|
||||
would be equivalent to dialing 1-916-624-8333 from a phone keypad. If you wanted
|
||||
to slow the pace of the dialing to accommodate a noisy phone line or radio link,
|
||||
you could use the optional <i>OnTime</i> and <i>OffTime</i> values:
|
||||
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
' Call Parallax; dial slowly.
|
||||
DTMFOUT 0, 500, 100, [1, 9, 1, 6, 6, 2, 4, 8, 3, 3, 3]
|
||||
</pre>
|
||||
<p>In this example, on a BS2 the<i>OnTime</i> is set to 500 ms (1/2 second) and <i>OffTime</i> to 100 ms (1/10th second).</p>
|
||||
<p> </p>
|
||||
<center>
|
||||
<table cellpadding="4" cellspacing="0" border="1">
|
||||
<tr>
|
||||
<td align="center" width="75" bgcolor="#CFCFCF">Tone Value</td>
|
||||
<td align="center" width="250" bgcolor="#CFCFCF">Corresponding Telephone Key</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">0 - 9</td>
|
||||
<td align="center">Digits 0 through 9</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">10</td>
|
||||
<td align="center">Star (*)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">11</td>
|
||||
<td align="center">Pound (#)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">12 - 15</td>
|
||||
<td align="center">Fourth column tones A through D</td>
|
||||
</tr>
|
||||
</table>
|
||||
</center>
|
||||
<p class="PlainText"> </p>
|
||||
<p class="PlainText">The BASIC Stamp microcontroller is a purely digital device. DTMF tones are analog
|
||||
waveforms, consisting of a mixture of two sine waves at different audio frequencies.
|
||||
So how does a digital device generate analog output? The BASIC Stamp creates and
|
||||
mixes the sine waves mathematically, then uses the resulting stream of numbers to
|
||||
control the duty cycle of a very fast pulse-width modulation (PWM) routine. So
|
||||
what's actually coming out of the I/O pin is a rapid stream of pulses. The purpose
|
||||
of the filtering arrangements shown in the figures above is to smooth out the
|
||||
high-frequency PWM, leaving only the lower frequency audio behind. </p>
|
||||
<p class="PlainText">Keep this in mind if you want to interface a BASIC Stamp module's DTMF output to radios
|
||||
and other equipment that could be adversely affected by the presence of
|
||||
high-frequency
|
||||
noise on the input. Make sure to filter the DTMF output thoroughly. The circuits
|
||||
above are only a starting point; you may want to use an active low-pass filter
|
||||
with a roll-off point around 2 kHz.</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>
|
205
help/BasicStampHelp/Content/LanguageTopics/Commands/EEPROM.htm
Normal file
205
help/BasicStampHelp/Content/LanguageTopics/Commands/EEPROM.htm
Normal file
@ -0,0 +1,205 @@
|
||||
<?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>EEPROM</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">EEPROM</h1>
|
||||
<div class="ImagePlusCaption">
|
||||
<div class="Col2">
|
||||
<p>
|
||||
<img src="../../graphics/pgm_icon1.gif" border="0" alt="BS1 icon" title="BS1 icon" /><span class="code_in_text"> {PBASIC 1.0}</span>
|
||||
</p>
|
||||
</div>
|
||||
<p style="text-align: right;"><a href="../ExampleTopics/EepromEx.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">EEPROM Example</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: <span class="keyword_in_text">EEPROM</span> {<i>Location</i>,} (<i> DataItem
|
||||
</i>{,<i> DataItem</i>,...})</p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Write data to the EEPROM during program download.</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Location</i></b> is an optional variable/constant (0 - 255) that
|
||||
specifies the starting location in the EEPROM at which data should be stored.
|
||||
If no location is given, data is written starting at the next available
|
||||
location.</li>
|
||||
<li value="2"><b><i>DataItem</i></b> is a constant (0 - 255) to be stored in EEPROM.</li>
|
||||
</ul>
|
||||
<h2>Quick Facts</h2>
|
||||
<table cellpadding="4" cellspacing="0" border="1" style="caption-side: top;width: 100%;">
|
||||
<col />
|
||||
<col />
|
||||
<tr bgcolor="#CFCFCF">
|
||||
<td width="15%" align="center"> </td>
|
||||
<td width="85%" align="center">BS1</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Special Notes</td>
|
||||
<td>Writes values to EEPROM during download. Can be used to decrease program size.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
||||
<td>
|
||||
<p colspan="2" align="center"><a href="READ.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">READ</a>, <a href="WRITE.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">WRITE</a></p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText">When you download a program into the BASIC Stamp 1, it is stored in the EEPROM
|
||||
starting at the highest address (255) and working towards the lowest address. Most
|
||||
programs don't use the entire EEPROM, so the lower portion is available for other
|
||||
uses. The <span class="keyword_in_text">EEPROM</span> directive allows you to define a set of data to store in
|
||||
the available EEPROM locations. It is called a "directive" rather than a "command"
|
||||
because it performs an activity at compile-time rather than at run-time (i.e., the
|
||||
<span class="keyword_in_text">EEPROM</span> directive is not downloaded to the BASIC Stamp 1, but the data it
|
||||
contains is downloaded).</p>
|
||||
<p>The simplest form of the <span class="keyword_in_text">EEPROM</span> directive is something like the following:</p><pre class="BScode" xml:space="preserve">
|
||||
EEPROM (100, 200, 52, 45)
|
||||
</pre>
|
||||
<p class="PlainText">This example, when downloaded, will cause the values 100, 200, 52 and 45 to be
|
||||
written to EEPROM locations 0, 1, 2 and 3, respectively. You can then use the
|
||||
<span class="keyword_in_text">READ</span> and <span class="keyword_in_text">WRITE</span> commands in your code to access these locations and
|
||||
the data you've stored there</p>
|
||||
<p class="PlainText">The <span class="keyword_in_text">EEPROM</span> directive uses a counter, called a pointer, to keep track of
|
||||
available EEPROM addresses. The value of the pointer is initially 0. When a program
|
||||
is downloaded, the <span class="keyword_in_text">EEPROM</span> directive stores the first byte value at the current
|
||||
pointer address, then increments (adds 1 to) the pointer. If the program contains
|
||||
more than one <span class="keyword_in_text">EEPROM</span> directive, subsequent <span class="keyword_in_text">EEPROM</span> directives start
|
||||
with the pointer value left by the previous <span class="keyword_in_text">EEPROM</span> directive. For example,
|
||||
if the program contains:</p><pre class="BScode" xml:space="preserve">
|
||||
EEPROM (72, 69, 76, 76, 79)
|
||||
EEPROM (104, 101, 108, 108, 111)
|
||||
</pre>
|
||||
<p class="PlainText">The first <span class="keyword_in_text">EEPROM</span> directive will start at location 0 and increment the
|
||||
pointer for each data value it stores (1, 2, 3, 4 and 5). The second <span class="keyword_in_text">EEPROM</span>directive will start with the pointer value of 5 and work upward from there. As
|
||||
a result, the first 10 bytes of EEPROM will look like the following:</p>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr>
|
||||
<td width="20%" align="center" bgcolor="#CFCFCF" rowspan="2"> </td>
|
||||
<td align="center" bgcolor="#CFCFCF" colspan="10">EEPROM Location (address)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="8%" align="center" bgcolor="#CFCFCF">0</td>
|
||||
<td width="8%" align="center" bgcolor="#CFCFCF">1</td>
|
||||
<td width="8%" align="center" bgcolor="#CFCFCF">2</td>
|
||||
<td width="8%" align="center" bgcolor="#CFCFCF">3</td>
|
||||
<td width="8%" align="center" bgcolor="#CFCFCF">4</td>
|
||||
<td width="8%" align="center" bgcolor="#CFCFCF">5</td>
|
||||
<td width="8%" align="center" bgcolor="#CFCFCF">6</td>
|
||||
<td width="8%" align="center" bgcolor="#CFCFCF">7</td>
|
||||
<td width="8%" align="center" bgcolor="#CFCFCF">8</td>
|
||||
<td width="8%" align="center" bgcolor="#CFCFCF">9</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="20%" align="center" bgcolor="#CFCFCF">Contents</td>
|
||||
<td width="8%" align="center">72</td>
|
||||
<td width="8%" align="center">69</td>
|
||||
<td width="8%" align="center">76</td>
|
||||
<td width="8%" align="center">76</td>
|
||||
<td width="8%" align="center">79</td>
|
||||
<td width="8%" align="center">104</td>
|
||||
<td width="8%" align="center">101</td>
|
||||
<td width="8%" align="center">108</td>
|
||||
<td width="8%" align="center">108</td>
|
||||
<td width="8%" align="center">111</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p class="PlainText">What if you don't want to store values starting at location 0? Fortunately,
|
||||
the <span class="keyword_in_text">EEPROM</span> directive has an option to specify the next location to use.
|
||||
You can specify the next location number (to set the pointer to) by using the
|
||||
optional <i>Location</i> argument before the list of <i>DataItems</i>. The following
|
||||
code writes the same data in the table above to locations 50 through 59:</p><pre class="BScode" xml:space="preserve">
|
||||
EEPROM 50, (72, 69, 76, 76, 79, 104, 101, 108, 108, 111)
|
||||
</pre>
|
||||
<p class="PlainText">In this example, the <i>Location</i> argument is given and tells the <span class="keyword_in_text">EEPROM</span>directive to store the following <i>DataItem</i>(s) starting at location 50. The
|
||||
<i>DataItems</i> in the list are stored in their respective locations (50, 51,
|
||||
52... 59).</p>
|
||||
<p class="PlainText">It is important to realize that the entire BASIC Stamp 1 EEPROM is overwritten
|
||||
during programming. Any EEPROM location not containing a PBASIC program or
|
||||
<i>DataItems</i> from an <span class="keyword_in_text">EEPROM</span> directive is written with a 0. </p>
|
||||
<p class="PlainText">A common use for EEPROM is to store strings; sequences of bytes representing
|
||||
text. PBASIC converts quoted text like "A" into the corresponding ASCII character
|
||||
code (65 in this case). To make data entry easier, you can place quotes around a
|
||||
whole chunk of text used in a <span class="keyword_in_text">EEPROM</span> directive, and PBASIC will understand
|
||||
it to mean a series of bytes (see the last line of code below). The following three
|
||||
<span class="keyword_in_text">EEPROM</span> directives are equivalent: </p><pre class="BScode" xml:space="preserve">
|
||||
EEPROM (72, 69, 76, 76, 79)
|
||||
EEPROM ("H", "E", "L", "L", "O")
|
||||
EEPROM ("HELLO")
|
||||
</pre>
|
||||
<p class="PlainText">All three lines of code, above, will result in the numbers 72, 69, 76, 76, and
|
||||
79 being stored into EEPROM upon downloading. These numbers are simply the ASCII
|
||||
character codes for "H", "E", "L", "L", and "O", respectively. See the
|
||||
Example program above for a demonstration of storing and
|
||||
reading multiple text strings.</p>
|
||||
<p class="PlainText">The EEPROM is organized as a sequential set of byte-sized memory locations.
|
||||
The <span class="keyword_in_text">EEPROM</span> directive only stores bytes into EEPROM. If you try to store
|
||||
a word-size value, for example: <span class="keyword_in_text">EEPROM</span> (1125), only the lower byte of the
|
||||
value will be stored (in this case, 101). This does not mean that you can't store
|
||||
word-sized values, however. A word consists of two bytes, called a low-byte and
|
||||
a high-byte. If you wanted to store the value 1125 using the <span class="keyword_in_text">EEPROM</span> directive
|
||||
you'll have to calculate the low-byte and the high-byte and insert them in the
|
||||
list in the proper order, as in:</p><pre class="BScode" xml:space="preserve">
|
||||
EEPROM (101, 4)
|
||||
</pre>
|
||||
<p class="PlainText">The directive above will store the two bytes into two sequential EEPROM
|
||||
locations (the low-byte first, followed by the high-byte). We calculated this in
|
||||
the following manner: 1) high-byte is INT(value / 256) and 2) low-byte is value -
|
||||
(high-byte * 256).</p>
|
||||
<p class="PlainText">To retrieve a word-size value, you'll need to use two <span class="keyword_in_text">READ</span> commands and
|
||||
a word-size variable. For example,</p><pre class="BScode" xml:space="preserve">
|
||||
SYMBOL result = W1 ' word-sized variable
|
||||
SYMBOL resLo = B2 ' B2 is low-byte of W1
|
||||
SYMBOL resHi = B3 ' B3 is high-byte of W1
|
||||
|
||||
EEPROM (101, 4)
|
||||
|
||||
Main:
|
||||
READ 0, resLo
|
||||
READ 1, resHi
|
||||
DEBUG #result
|
||||
END
|
||||
</pre>
|
||||
<p class="PlainText">This code would write the low-byte and high-byte of the number 1125 into
|
||||
locations 0 and 1 during download. When the program runs, the two <span class="keyword_in_text">READ</span>commands will read the low-byte and high-byte out of EEPROM (reconstructing it in
|
||||
a word-size variable) and then display the value on the screen. See the <a href="READ.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">READ</a>
|
||||
and <a href="WRITE.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">WRITE</a> commands for more
|
||||
information.</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>
|
127
help/BasicStampHelp/Content/LanguageTopics/Commands/END.htm
Normal file
127
help/BasicStampHelp/Content/LanguageTopics/Commands/END.htm
Normal file
@ -0,0 +1,127 @@
|
||||
<?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>END</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">END</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">Syntax: <span class="keyword_in_text">END</span></p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">End the program, placing the BASIC Stamp into low-power mode indefinitely. This
|
||||
is equivalent to having a program that does not loop continuously; once the BASIC
|
||||
Stamp reaches the end of the PBASIC program, it enters low-power mode indefinitely.
|
||||
The <span class="keyword_in_text">END</span> command is optional, but recommended.</p>
|
||||
<h2>Quick Facts</h2>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr align="center" bgcolor="#CFCFCF">
|
||||
<td width="23%"> </td>
|
||||
<td width="11%">BS1</td>
|
||||
<td width="11%">BS2</td>
|
||||
<td width="11%">BS2e</td>
|
||||
<td width="11%">BS2sx</td>
|
||||
<td width="11%">BS2p</td>
|
||||
<td width="11%">BS2pe</td>
|
||||
<td width="11%">BS2px</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td bgcolor="#CFCFCF">Approximate current draw @ 5 VDC during Run *</td>
|
||||
<td>1 mA</td>
|
||||
<td>3 mA</td>
|
||||
<td>25 mA</td>
|
||||
<td>60 mA</td>
|
||||
<td>40 mA</td>
|
||||
<td>15 mA</td>
|
||||
<td>55 mA</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td bgcolor="#CFCFCF">Approximate current draw @ 5 VDC during END *</td>
|
||||
<td>25 µA</td>
|
||||
<td>50 µA</td>
|
||||
<td>200 µA</td>
|
||||
<td>500 µA</td>
|
||||
<td>350 µA</td>
|
||||
<td>36 µA</td>
|
||||
<td>450 µA</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
||||
<td align="center" colspan="1">
|
||||
<p colspan="1" align="center"><a href="NAP.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">NAP</a>, <a href="SLEEP.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">SLEEP</a></p>
|
||||
</td>
|
||||
<td align="center" colspan="3">
|
||||
<p colspan="3" align="center"><a href="NAP.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">NAP</a>, <a href="SLEEP.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">SLEEP</a>, <a href="STOP.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">STOP</a></p>
|
||||
</td>
|
||||
<td align="center" colspan="3">
|
||||
<p colspan="3" align="center"><a href="NAP.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">NAP</a>, <a href="SLEEP.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">SLEEP</a>, <a href="STOP.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">STOP</a>, <a href="POLLWAIT.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">POLLWAIT</a></p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p>*Note: This is an approximate value, not including loads on the I/O pins</p>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText"><span class="keyword_in_text">END</span> puts the BASIC Stamp into its inactive, low-power mode. In this
|
||||
mode the Stamp's current draw (excluding loads driven by the I/O pins) is
|
||||
reduced to the amount shown above. <span class="keyword_in_text">END</span> keeps the BASIC Stamp
|
||||
inactive until the reset line is activated, the power is cycled off and back on
|
||||
or the PC downloads another program.</p>
|
||||
<p class="PlainText">During execution of power conserving commands (<span class="keyword_in_text">END</span>, <span class="keyword_in_text">NAP</span>, <span class="keyword_in_text">POLLWAIT</span>, and <span class="keyword_in_text">SLEEP</span>), current will occasionally be interrupted
|
||||
on I/O pins for about 18 ms durations (60 µs on the BS2pe). The reason is that the
|
||||
watchdog-timer reset that awakens the BASIC Stamp during these commands also causes all of the pins to
|
||||
switch to input mode for approximately 18 ms (60 µs on the BS2pe). When the interpreter
|
||||
firmware regains control of the processor, it restores the I/O direction dictated
|
||||
by your program.</p>
|
||||
<p class="PlainText">If you plan to use <span class="keyword_in_text">END</span>, <span class="keyword_in_text">NAP</span>, <span class="keyword_in_text">POLLWAIT</span>, or <span class="keyword_in_text">SLEEP</span> in your programs,
|
||||
make sure that your loads can tolerate these power outages. The simplest solution
|
||||
is often to connect resistors high or low (to +5V or ground) as appropriate to
|
||||
ensure a continuing supply of current during the reset. </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>
|
105
help/BasicStampHelp/Content/LanguageTopics/Commands/EXIT.htm
Normal file
105
help/BasicStampHelp/Content/LanguageTopics/Commands/EXIT.htm
Normal file
@ -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="" 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>EXIT</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">EXIT</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" />
|
||||
</p>
|
||||
</div>
|
||||
<p style="text-align: right;"><a href="../ExampleTopics/ExitEx.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">EXIT Example</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: <span class="keyword_in_text">EXIT</span></p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Causes the immediate termination of a loop construct
|
||||
(<a href="FOR_NEXT.htm" class="MCXref_0" xrefformat="{paratext}">FOR…NEXT</a>, <a href="DO_LOOP.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">DO…LOOP</a>).
|
||||
|
||||
</p>
|
||||
<h2>Quick Facts</h2>
|
||||
<table cellpadding="4" cellspacing="0" border="1" style="caption-side: top;width: 100%;">
|
||||
<col />
|
||||
<col />
|
||||
<tr bgcolor="#CFCFCF">
|
||||
<td width="15%" align="center"> </td>
|
||||
<td width="85%" align="center">All BS2 Models</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Maximum EXITs per loop</td>
|
||||
<td align="center">16</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
||||
<td align="center"><a href="FOR_NEXT.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">FOR…NEXT</a>, <a href="DO_LOOP.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">DO…LOOP</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText">The <span class="keyword_in_text">EXIT</span> command allows a program to terminate a loop structure before
|
||||
the loop limit test is executed. While not required, <span class="keyword_in_text">EXIT</span> is usually
|
||||
used as part of an <span class="keyword_in_text">IF...THEN</span> construct to test a secondary condition for
|
||||
terminating a loop, or for testing a termination condition of an unconditional
|
||||
<span class="keyword_in_text">DO...LOOP</span> structure.</p><pre class="BScode" xml:space="preserve">
|
||||
col VAR Byte
|
||||
row VAR Byte
|
||||
|
||||
Main:
|
||||
FOR col = 0 TO 3
|
||||
FOR row = 0 TO 15
|
||||
IF (row > 9) THEN EXIT
|
||||
DEBUG CRSRXY, (col * 8), row, DEC row, CR
|
||||
NEXT
|
||||
NEXT
|
||||
END
|
||||
</pre>
|
||||
<p class="PlainText">In this program, the <span class="code_in_text">FOR row = 0 TO 15</span> loop will not run past nine because
|
||||
the <span class="code_in_text">IF (row > 9) THEN EXIT</span> contained within will force the loop to terminate
|
||||
when row is greater than nine. Note that the <span class="keyword_in_text">EXIT</span> command only terminates
|
||||
the loop that contains it. In this program, the outer loop (col) will continue to
|
||||
run until complete.</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>
|
391
help/BasicStampHelp/Content/LanguageTopics/Commands/FOR_NEXT.htm
Normal file
391
help/BasicStampHelp/Content/LanguageTopics/Commands/FOR_NEXT.htm
Normal file
@ -0,0 +1,391 @@
|
||||
<?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>FOR…NEXT</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">FOR…NEXT</h1>
|
||||
<div class="ImagePlusCaption">
|
||||
<div class="Col2">
|
||||
<p>
|
||||
<img src="../../graphics/pgm_icon1.gif" border="0" alt="BS1 icon" title="BS1 icon" />
|
||||
<img src="../../graphics/pgm_icon2.gif" border="0" alt="BS2 icon" title="BS2 icon" />
|
||||
<img src="../../graphics/pgm_icon2e.gif" border="0" alt="BS2e icon" title="BS2e icon" />
|
||||
<img src="../../graphics/pgm_icon2sx.gif" border="0" alt="BS2sx icon" title="BS2sx icon" />
|
||||
<img src="../../graphics/pgm_icon2p.gif" border="0" alt="BS2p icon" title="BS2p icon" />
|
||||
<img src="../../graphics/pgm_icon2pe.gif" border="0" alt="BS2pe icon" title="BS2pe icon" />
|
||||
<img src="../../graphics/pgm_icon2px.gif" border="0" alt="BS2px icon" title="BS2px icon" />
|
||||
</p>
|
||||
</div>
|
||||
<p style="text-align: right;"><a href="../ExampleTopics/ForNextEx.htm" target="" title="" alt="" class="MCXref_0">FOR...NEXT Examples</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax <img align="absmiddle" src="../../graphics/mini_1.gif" /> :
|
||||
<span class="keyword_in_text">FOR</span> <![CDATA[ ]]><i>Counter = StartValue</i> <![CDATA[ ]]><span class="keyword_in_text">TO</span> <![CDATA[ ]]><i>EndValue </i>{<span class="keyword_in_text">STEP </span>{-}<i> StepValue</i>} ... <span class="keyword_in_text">NEXT</span><i><![CDATA[ ]]></i>{<i>Counter</i>}</p>
|
||||
<p class="PlainText">Syntax <img align="absmiddle" src="../../graphics/mini_2.gif" /> : <span class="keyword_in_text">FOR</span> <![CDATA[ ]]><i>Counter = StartValue</i> <![CDATA[ ]]><span class="keyword_in_text">TO</span> <![CDATA[ ]]><i>EndValue </i>{<span class="keyword_in_text">STEP</span><i> StepValue</i>}<i><![CDATA[ ]]></i>... <span class="keyword_in_text">NEXT</span></p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Create a repeating loop that executes the program lines between <span class="keyword_in_text">FOR</span> and
|
||||
<span class="keyword_in_text">NEXT</span>, incrementing or decrementing <i>Counter</i> according to <i>StepValue</i> until the value of the <i>Counter</i> variable passes the <i>EndValue</i>.
|
||||
|
||||
</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Counter</i></b> is a variable (usually a byte or a word) used as a
|
||||
counter.</li>
|
||||
<li value="2"><b><i>StartValue</i></b> is a variable/constant/expression* (0 - 65535) that
|
||||
specifies the initial value of the variable (<i>Counter</i>).</li>
|
||||
<li value="3"><b><i>EndValue</i></b> is a variable/constant/expression* (0 - 65535) that
|
||||
specifies the end value of the variable (<i>Counter</i>). When the value
|
||||
of Counter is outside of the range <i>StartValue</i> to <i>EndValue</i>, the
|
||||
<span class="keyword_in_text">FOR...NEXT</span> loop stops executing and the program goes on to the instruction
|
||||
after <span class="keyword_in_text">NEXT</span>.</li>
|
||||
<li value="4"><b><i>StepValue</i></b> is an optional variable/constant/expression* (0 -
|
||||
65535) by which the <i>Counter</i> increases or decreases with each iteration
|
||||
through the <span class="keyword_in_text">FOR...NEXT</span> loop. On the BS1, use a minus sign (-)†
|
||||
in front of the <i>StepValue</i> to indicate a negative step. On all other
|
||||
BASIC Stamp models, if <i>StartValue</i> is larger than <i>EndValue</i>, PBASIC
|
||||
understands <i>StepValue</i> to be negative, even though no minus sign is used.</li>
|
||||
</ul>
|
||||
<p class="PlainText">*<img src="../../graphics/bs1note.gif" style="vertical-align: super;" /> Note: expressions are not allowed as arguments on the BS1.</p>
|
||||
<p class="PlainText">†<img src="../../graphics/bs1note.gif" style="vertical-align: super;" /> Note: Use a minus sign to indicate negative <i>StepValues</i> on the BS1.</p>
|
||||
<h2>Quick Facts</h2>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr>
|
||||
<td width="26%" align="center" bgcolor="#CFCFCF"> </td>
|
||||
<td width="37%" align="center" bgcolor="#CFCFCF">BS1</td>
|
||||
<td width="37%" align="center" bgcolor="#CFCFCF">BS2 Family</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Max. nested commands</td>
|
||||
<td align="center">8</td>
|
||||
<td align="center">16</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">To decrement counter variable</td>
|
||||
<td align="center">Set <i>StartValue</i> > <i>EndValue</i><br></br>and enter
|
||||
negative <i>StepValue</i> *</td>
|
||||
<td align="center">Set <i>StartValue</i> > <i>EndValue</i></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF"><i>Counter</i> comparison</td>
|
||||
<td align="center">Exit loop if <i>Counter</i> exceeds <i>EndValue</i></td>
|
||||
<td align="center">Exit loop if <i>Counter</i> outside of range set by
|
||||
<i>StartValue</i> to <i>EndValue</i></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
||||
<td align="center" colspan="1">
|
||||
<p colspan="1" align="center">None</p>
|
||||
</td>
|
||||
<td align="center" colspan="1">
|
||||
<p colspan="1" align="center"><a href="DO_LOOP.htm" target="" title="" alt="" class="MCXref_0">DO…LOOP</a>, <a href="EXIT.htm" target="" title="" alt="" class="MCXref_0">EXIT</a></p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p>*Note: Direction (ie: increment/decrement) cannot be changed at runtime.</p>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText"><span class="keyword_in_text">FOR...NEXT</span> loops let your program execute a series of instructions for a
|
||||
specified number of repetitions (called iterations). By default, each time through
|
||||
the loop, the counter variable is incremented by 1. It will continue to loop until
|
||||
the result of the counter is outside of the range set by <i>StartValue</i> and
|
||||
<i>EndValue</i>. Also, <span class="keyword_in_text">FOR...NEXT</span> loops always execute at least once. The
|
||||
simplest form is shown here: </p>
|
||||
<p>
|
||||
<img src="../../graphics/bs1_inline.gif" border="0">
|
||||
</img>
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
SYMBOL reps = B2 ' FOR...NEXT loop counter
|
||||
|
||||
Main:
|
||||
FOR reps = 1 TO 3 ' repeat with Reps = 1, 2, 3
|
||||
DEBUG "*" ' print * on the screen
|
||||
NEXT
|
||||
END
|
||||
</pre>
|
||||
<p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0">
|
||||
</img>
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
reps VAR Nib ' FOR...NEXT loop counter
|
||||
|
||||
Main:
|
||||
FOR reps = 1 TO 3 ' repeat with Reps = 1, 2, 3
|
||||
DEBUG "*" ' print * on the screen
|
||||
NEXT
|
||||
END
|
||||
</pre>
|
||||
<p class="PlainText">In the above code, the <span class="keyword_in_text">FOR</span> command sets Reps = 1. Then the <span class="keyword_in_text">DEBUG</span>
|
||||
line (within the <span class="keyword_in_text">FOR...NEXT</span> loop) is executed; printing an asterisk (*) on
|
||||
the screen. When the BASIC Stamp sees the <span class="keyword_in_text">NEXT</span> command, it goes back to
|
||||
the previous <span class="keyword_in_text">FOR</span> command, adds 1 to Reps and compares the result to the
|
||||
range set by <i>StartValue</i> and <i>EndValue</i>. If reps is still within range,
|
||||
it executes the code in the loop again. Each time the <span class="keyword_in_text">FOR...NEXT</span> loop
|
||||
executes, the value of reps is updated (incremented by 1) and the code within the
|
||||
loop (the <span class="keyword_in_text">DEBUG</span> line) is executed; printing another asterisk on the screen.
|
||||
This code will run through the loop three times; setting reps to 1, 2 and 3, and
|
||||
printing three asterisks on the screen. After the third loop, again the BASIC
|
||||
Stamp goes back up to the <span class="keyword_in_text">FOR</span> command, adds 1 to reps and compares the result
|
||||
(4 in this case) to the range. Since the range is 1 to 3 and the value is 4 (outside
|
||||
the range) the <span class="keyword_in_text">FOR...NEXT</span> loop is done and the BASIC Stamp will jump down
|
||||
to the first line of code following the <span class="keyword_in_text">NEXT</span> command.</p>
|
||||
<p class="PlainText">You can view the changing values of reps by including the reps variable in a
|
||||
<span class="keyword_in_text">DEBUG</span> command within the loop: </p>
|
||||
<p>
|
||||
<img src="../../graphics/bs1_inline.gif" border="0">
|
||||
</img>
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
SYMBOL reps = B2 ' FOR...NEXT loop counter
|
||||
|
||||
Main:
|
||||
FOR reps = 1 TO 3 ' repeat with Reps = 1, 2, 3
|
||||
DEBUG #reps, CR ' print number on the screen
|
||||
NEXT
|
||||
END
|
||||
</pre>
|
||||
<p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0">
|
||||
</img>
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
reps VAR Nib ' FOR...NEXT loop counter
|
||||
|
||||
Main:
|
||||
FOR reps = 1 TO 3 ' repeat with Reps = 1, 2, 3
|
||||
DEBUG DEC reps, CR ' print number on the screen
|
||||
NEXT
|
||||
END
|
||||
</pre>
|
||||
<p class="PlainText">Running this example should display "1" , "2", and "3" on the screen.</p>
|
||||
<p class="PlainText"><span class="keyword_in_text">FOR...NEXT</span> can also be made to decrement (rather than increment) the
|
||||
counter variable. The BS1 does this when you specify a negative <i>StepValue</i>(as well as a <i>StartValue</i> that is greater than the <i>EndValue</i>). All
|
||||
other BASIC Stamp models do this automatically when the <i>StartValue</i> is greater
|
||||
than the <i>EndValue</i>. Examples of both are shown below:</p>
|
||||
<p>
|
||||
<img src="../../graphics/bs1_inline.gif" border="0">
|
||||
</img>
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
SYMBOL reps = B2 ' FOR...NEXT loop counter
|
||||
|
||||
Main:
|
||||
FOR reps = 3 TO 1 STEP -1 ' repeat with Reps = 3, 2, 1
|
||||
DEBUG #reps, CR ' print number on the screen
|
||||
NEXT
|
||||
END
|
||||
</pre>
|
||||
<p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0">
|
||||
</img>
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
reps VAR Nib ' FOR...NEXT loop counter
|
||||
|
||||
Main:
|
||||
FOR reps = 3 TO 1 ' repeat with Reps = 3, 2, 1
|
||||
DEBUG DEC reps, CR ' print number on the screen
|
||||
NEXT
|
||||
END
|
||||
</pre>
|
||||
<p class="PlainText">Note that the code for the BS2 series did not use the optional <span class="keyword_in_text">STEP</span> argument.
|
||||
This is because we wanted to decrement by positive 1 anyway (the default unit)
|
||||
and the BASIC Stamp realizes it needs to decrement because the <i>StartValue</i>is greater than the <i>EndValue</i>. A negative <i>StepValue</i> on the BS2 series
|
||||
would be treated as its positive, two's complement counterpart. For example, -1
|
||||
in two's complement is 65535. So the following code executes only once: </p><pre class="BScode" xml:space="preserve">
|
||||
reps VAR Nib ' FOR...NEXT loop counter
|
||||
|
||||
Main:
|
||||
FOR reps = 3 TO 1 STEP -1 ' decrement 3 by 65535
|
||||
DEBUG DEC reps, CR ' print number on the screen
|
||||
NEXT
|
||||
END
|
||||
</pre>
|
||||
<p class="PlainText">The above code would run through the loop once with <i>reps</i> set to 3. The second
|
||||
time around, it would decrement <i>reps</i> by 65535 (-1 is 65535 in two's complement)
|
||||
effectively making the number -65532 (4 in two's complement) which is outside the
|
||||
range of the loop.</p>
|
||||
<p>All the arguments in the <span class="keyword_in_text">FOR...NEXT</span> command can be constants, variables
|
||||
or expressions (on the BS2 series). This leads to some interesting uses. For
|
||||
example, if you make the <i>StartValue</i> and <i>EndValue</i> a variable, and
|
||||
change their values within the loop, you'll change the behavior of the loop itself.
|
||||
Try the following:</p><pre class="BScode" xml:space="preserve">
|
||||
reps VAR Byte ' counter for the FOR/NEXT loop
|
||||
startVal VAR Byte
|
||||
endVal VAR Byte
|
||||
|
||||
Setup:
|
||||
startVal = 1 ' initialize startVal to 1
|
||||
endVal = 3 ' initialize endVal to 3
|
||||
|
||||
Main:
|
||||
FOR reps = startVal TO endVal ' repeat for 1 to 3
|
||||
DEBUG DEC reps, CR
|
||||
IF (reps = 3) THEN ' if reps = 3 then swap startVal and endVal
|
||||
startVal = 3 ' otherwise continue loop
|
||||
endVal = 1
|
||||
ENDIF
|
||||
NEXT
|
||||
</pre>
|
||||
<p class="PlainText">Here the loop starts with a range of 1 to 3. First, the <span class="keyword_in_text">DEBUG</span> line
|
||||
prints the value of <i>reps</i>. Then the <span class="keyword_in_text">IF...THEN</span> line makes a decision; if
|
||||
<i>reps</i> is equal to 3, then swap the order of <i>startVal</i> and <i>endVal</i>,
|
||||
otherwise continue the loop execution. The next time through the loop (after
|
||||
<i>startVal</i> and <i>endVal</i> have been swapped), <i>reps</i> will be decremented
|
||||
instead of incremented because <i>startVal</i> is greater than <i>endVal</i>.
|
||||
The result is a display on the screen of the numbers 1, 2, 3, 2, 1.</p>
|
||||
<p class="PlainText">The following example uses the value of <i>reps</i> as the <i>StepValue</i>. This
|
||||
creates a display of power's of 2 (1, 2, 4, 8, 16, 32, 64, etc):</p>
|
||||
<p>
|
||||
<img src="../../graphics/bs1_inline.gif" border="0">
|
||||
</img>
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
SYMBOL reps = B2 ' FOR...NEXT loop counter
|
||||
|
||||
Main:
|
||||
FOR reps = 1 TO 256 STEP reps ' each loop add current value of Reps
|
||||
DEBUG reps ' show reps in Debug window.
|
||||
NEXT
|
||||
END
|
||||
</pre>
|
||||
<p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0">
|
||||
</img>
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
reps VAR Byte ' FOR...NEXT loop counter
|
||||
|
||||
Main:
|
||||
FOR reps = 1 TO 256 STEP reps ' each loop add current value of Reps
|
||||
DEBUG ? DEC reps ' show reps in debug window.
|
||||
NEXT
|
||||
END
|
||||
</pre>
|
||||
<p class="PlainText">There is a potential bug that you should be careful to avoid. The BASIC Stamp
|
||||
uses unsigned 16-bit integer math for any math operation it performs, regardless
|
||||
of the size of values or variables. The maximum value the BASIC Stamp can internally
|
||||
calculate is 65535 (the largest 16-bit number). If you add 1 to 65535, you get 0
|
||||
as the 16-bit register rolls over (like a car's odometer does when you exceed
|
||||
the maximum mileage it can display). Similarly, if you subtract 1 from 0, you'll
|
||||
get 65535 as the 16-bit register rolls under (a rollover in the opposite direction).</p>
|
||||
<p class="PlainText">If you write a <span class="keyword_in_text">FOR...NEXT</span> loop who's <i>StepValue</i> would cause the
|
||||
counter variable to go past 65535, this rollover may cause the loop to execute
|
||||
more times than you expect. Try the following example: </p>
|
||||
<p>
|
||||
<img src="../../graphics/bs1_inline.gif" border="0">
|
||||
</img>
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
SYMBOL reps = W1 ' FOR...NEXT loop counter
|
||||
|
||||
Main:
|
||||
FOR reps = 0 TO 65535 STEP 3000 ' each loop add 3000
|
||||
DEBUG reps ' show reps in debug window
|
||||
NEXT
|
||||
END
|
||||
</pre>
|
||||
<p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0">
|
||||
</img>
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
SYMBOL reps = W1 ' FOR...NEXT loop counter
|
||||
|
||||
Main:
|
||||
FOR reps = 0 TO 65535 STEP 3000 ' each loop add 3000
|
||||
DEBUG reps ' show reps in debug window
|
||||
NEXT
|
||||
END
|
||||
</pre>
|
||||
<p class="PlainText">The value of <i>reps</i> increases by 3000 each trip through the loop. As it approaches
|
||||
the <i>EndValue</i>, an interesting thing happens; <i>reps</i> is: 57000, 60000, 63000,
|
||||
464, 3464... It passes the <i>EndValue</i>, rolls over and keeps going. That's
|
||||
because the result of the calculation 63000 + 3000 exceeds the maximum capacity
|
||||
of a 16-bit number and then rolls over to 464. When the result of 464 is tested
|
||||
against the range ("Is <i>reps</i> > 0 and is <i>reps</i> < 65500?") it passes the test and the
|
||||
loop continues. </p>
|
||||
<p class="PlainText">A similar symptom can be seen in a program whose <i>EndValue</i> is mistakenly
|
||||
set higher than what the counter variable can hold. The example below uses a
|
||||
byte-sized variable, but the <i>EndValue</i> is set to a number greater than what
|
||||
will fit in a byte:</p>
|
||||
<p>
|
||||
<img src="../../graphics/bs1_inline.gif" border="0">
|
||||
</img>
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
SYMBOL reps = W1 ' FOR...NEXT loop counter
|
||||
|
||||
Main:
|
||||
FOR reps = 0 TO 300 ' each loop add 1
|
||||
DEBUG reps ' show reps in debug window
|
||||
NEXT
|
||||
END
|
||||
</pre>
|
||||
<p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0">
|
||||
</img>
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
reps VAR Byte ' FOR...NEXT loop counter
|
||||
|
||||
Main:
|
||||
FOR reps = 0 TO 300 ' each loop add 1
|
||||
DEBUG DEC ? reps ' show reps in debug window
|
||||
NEXT
|
||||
END
|
||||
</pre>
|
||||
<p class="PlainText">Here, <i>reps</i> is a byte variable; which can only hold the number range 0 to 255.
|
||||
The <i>EndValue</i> is set to 300, however; greater than 255. This code will loop
|
||||
endlessly because when reps is 255 and the <span class="keyword_in_text">FOR...NEXT</span> loop adds 1, reps
|
||||
becomes 0 (bytes will rollover after 255 just like words will rollover after 65535).
|
||||
The result, 0, is compared against the range (0 - 255) and it is found to be within
|
||||
the range, so the <span class="keyword_in_text">FOR...NEXT</span> loop continues.</p>
|
||||
<p class="PlainText">It's important to realize that on the BS2 series, the test is against the entire
|
||||
range, not just the <i>EndValue</i>. The code below is a slight modification of
|
||||
the previous example (the <i>StartValue</i> is 10 instead of 0) and will not loop
|
||||
endlessly.</p>
|
||||
<p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0">
|
||||
</img>
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
reps VAR Byte ' FOR...NEXT loop counter
|
||||
|
||||
Main:
|
||||
FOR reps = 10 TO 300 ' each loop add 1
|
||||
DEBUG DEC ? reps ' show reps in debug window
|
||||
NEXT
|
||||
END
|
||||
</pre>
|
||||
<p class="PlainText"><i>Reps</i> still rolls over to 0, as before, however, this time it is outside the
|
||||
range of 10 to 255. The loop stops, leaving <i>reps</i> at 0. Note that this code is
|
||||
still in error since <i>reps</i> will never reach 300 until it is declared as a Word.</p>
|
||||
<p class="PlainText">NOTE: On the BS1, the loop will continue until <i>Counter</i> has gone past
|
||||
<i>EndValue</i>. The rollover error will still occur if the BS1 cannot determine
|
||||
if <i>Counter</i> went past <i>EndValue</i>.</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>
|
138
help/BasicStampHelp/Content/LanguageTopics/Commands/FREQOUT.htm
Normal file
138
help/BasicStampHelp/Content/LanguageTopics/Commands/FREQOUT.htm
Normal file
@ -0,0 +1,138 @@
|
||||
<?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>FREQOUT</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">FREQOUT</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" />
|
||||
</p>
|
||||
</div>
|
||||
<p style="text-align: right;"><a href="../ExampleTopics/FreqoutEx.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">FREQOUT Example</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: <span class="keyword_in_text">FREQOUT</span> <![CDATA[ ]]><i>Pin</i>,<i> Duration</i>,<i> Freq1 </i>{,<i> Freq2</i>}</p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Generate one or two sine-wave tones for a specified duration.
|
||||
|
||||
</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Pin</i></b> a variable/constant/expression (0 - 15) that specifies the
|
||||
I/O pin to use. This pin will be set to output mode.</li>
|
||||
<li value="2"><b><i>Duration</i></b> a variable/constant/expression (0 - 65535) specifying
|
||||
the amount of time to generate the tone(s). The unit of time for Duration is
|
||||
described in the table below.</li>
|
||||
<li value="3"><b><i>Freq1</i></b> is a variable/constant/expression (0 - 32767) specifying
|
||||
frequency of the first tone. The unit of <i>Freq1</i> is described in the table
|
||||
below.</li>
|
||||
<li value="4"><b><i>Freq2</i></b> is an optional argument exactly like <i>Freq1</i>. When specified,
|
||||
two frequencies will be mixed together on the specified I/O pin.</li>
|
||||
</ul>
|
||||
<p class="PlainText">Note: See <a href="SOUND.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">SOUND</a> for the BS1.</p>
|
||||
<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">BS2 and 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">Units in <i>Duration</i></td>
|
||||
<td align="center">1 ms</td>
|
||||
<td align="center">0.4 ms</td>
|
||||
<td align="center">0.265 ms</td>
|
||||
<td align="center">1 ms</td>
|
||||
<td align="center">0.166 ms</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Units in <i>Freq1</i> and <i>Freq2</i></td>
|
||||
<td align="center">1 Hz</td>
|
||||
<td align="center">2.5 Hz</td>
|
||||
<td align="center">3.77 Hz</td>
|
||||
<td align="center">1.51 Hz</td>
|
||||
<td align="center">6.03 Hz</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Range of frequency</td>
|
||||
<td align="center">0 to 32767 Hz</td>
|
||||
<td align="center">0 to 81.917 kHz</td>
|
||||
<td align="center">0 to 123.531 kHz</td>
|
||||
<td align="center">0 to 49.478 kHz</td>
|
||||
<td align="center">0 to 197.585 kHz</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
||||
<td align="center" colspan="5">
|
||||
<p colspan="5" align="center"><a href="DTMFOUT.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">DTMFOUT</a>, <a href="PWM.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">PWM</a></p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText"><span class="keyword_in_text">FREQOUT</span> generates one or two sine waves using a pulse-width modulation
|
||||
algorithm. The circuits in the figure below work by filtering out the
|
||||
high-frequency PWM used to generate the sine waves. <span class="keyword_in_text">FREQOUT</span> works over a
|
||||
very wide range of frequencies so at the upper end of its range, those PWM
|
||||
filters will also filter out most of the desired frequency. You may find it
|
||||
necessary to reduce values of the parallel capacitors shown in the circuit, or
|
||||
to devise a custom active filter for your application. </p>
|
||||
<center>
|
||||
<img src="../../graphics/freqout_sch.gif" width="387" height="385" border="0">
|
||||
</img>
|
||||
</center>
|
||||
<p class="PlainText"> </p>
|
||||
<p class="PlainText">Here's a simple <span class="keyword_in_text">FREQOUT</span> command: </p><pre class="BScode" xml:space="preserve">
|
||||
FREQOUT 2, 1000, 2500
|
||||
</pre>
|
||||
<p class="PlainText">On the BS2, this command generates a 2500 Hz tone for 1 second (1000 ms) on
|
||||
I/O pin 2. See the table above for timing data on other BASIC Stamp models.</p>
|
||||
<p class="PlainText">To play two tones on the same I/O pin at once:</p><pre class="BScode" xml:space="preserve"> FREQOUT 2, 1000, 2500, 3000</pre>
|
||||
<p class="PlainText">This will generate a 2500 Hz and 3000 Hz tone (on the BS2) for 1 second. The frequencies will mix together for a chord- or bell-like sound. To generate a silent pause, specify frequency value(s) of 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>
|
181
help/BasicStampHelp/Content/LanguageTopics/Commands/GET.htm
Normal file
181
help/BasicStampHelp/Content/LanguageTopics/Commands/GET.htm
Normal file
@ -0,0 +1,181 @@
|
||||
<?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>GET</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">GET</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/GetPutEx.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">GET / PUT Examples</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: <span class="keyword_in_text">GET</span> <![CDATA[ ]]><i>Location</i>,<i><![CDATA[ ]]></i>{Word}<i> Variable
|
||||
</i>{,<i><![CDATA[ ]]></i>{Word}<i> Variable ...</i>}</p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Read value(s) from Scratchpad RAM, starting at <i>Location</i> and store in
|
||||
<i>Variable(s)*</i>.
|
||||
|
||||
</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Location</i></b> is a variable/constant/expression (0 – 63 for Bs2e
|
||||
and BS2sx, and 0 – 135 for BS2p, BS2pe, and BS2px) that specifies the Scratchpad
|
||||
RAM location to read from.</li>
|
||||
<li value="2"><b><i>Variable</i></b> is a variable (usually a byte; unless using the optional <i>Word</i> modifier) to store the
|
||||
value into. </li>
|
||||
</ul>
|
||||
<p>*Note: The optional arguments require PBASIC 2.5.</p>
|
||||
<h2>Quick Facts</h2>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr>
|
||||
<td width="24%" align="center" bgcolor="#CFCFCF"> </td>
|
||||
<td width="38%" align="center" bgcolor="#CFCFCF">BS2e and BS2sx</td>
|
||||
<td width="38%" align="center" bgcolor="#CFCFCF">BS2p, BS2pe, and BS2px</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Scratchpad RAM size and organization</td>
|
||||
<td align="center">64 bytes (0 – 63). Organized as bytes only.</td>
|
||||
<td align="center">136 bytes (0 – 135). Organized as bytes only.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">General purpose locations</td>
|
||||
<td align="center">0 - 62</td>
|
||||
<td align="center">0 – 126</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Special use location</td>
|
||||
<td align="center">Current program slot number in read-only location 63.</td>
|
||||
<td align="center">Current program slot number in lowest nibble of read-only location 127. Current read/write slot number in highest nibble of location 127. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Additional locations</td>
|
||||
<td align="center">None</td>
|
||||
<td align="center">Locations 128 - 135 (read-only) hold state of polled input pins.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
||||
<td align="center"><a href="PUT.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">PUT</a>
|
||||
</td>
|
||||
<td align="center"><a href="PUT.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">PUT</a>, <a href="STORE.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">STORE</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">PBASIC 2.5 Syntax Options</td>
|
||||
<td align="center" colspan="2">
|
||||
<p colspan="2" align="center">Multiple sequential variables may be read from the Scratchpad RAM. </p>
|
||||
<p colspan="2" align="center">The optional Word modifier may be specified to retrieve 16-bit values.</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText">By default, the <span class="keyword_in_text">GET</span> command reads a byte-sized value from the specified
|
||||
Scratchpad RAM location and stores it into variable. All values in all locations
|
||||
can be retrieved from within any of the eight program slots.</p>
|
||||
<p class="PlainText">Scratchpad RAM is useful for passing data to programs in other program
|
||||
slots and for additional workspace. It is different than regular RAM in
|
||||
that symbol names cannot be assigned directly to locations and each
|
||||
location is always configured as a byte only. The following code will read
|
||||
the value at location 25, store it in a variable called <i>temp</i> and display
|
||||
it:</p>
|
||||
<p class="PlainText">The following example illustrates this:</p><pre class="BScode" xml:space="preserve">
|
||||
temp VAR Byte
|
||||
|
||||
Main:
|
||||
GET 25, temp
|
||||
DEBUG DEC temp
|
||||
END
|
||||
</pre>
|
||||
<p class="PlainText">When using the $PBASIC 2.5 directive, multiple sequential variables may be read
|
||||
from the Scratchpad RAM, starting at <i>Location</i>, and the Word modifier may
|
||||
be specified for 16-bit values.</p>
|
||||
<p>
|
||||
<img src="../../graphics/bsesxppepx_inline.gif" border="0">
|
||||
</img>
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
' {$PBASIC 2.5}
|
||||
|
||||
value VAR Word
|
||||
value2 VAR Word
|
||||
addr VAR Word ' EEPROM address
|
||||
test VAR Byte ' test byte read back
|
||||
|
||||
Main:
|
||||
value = $11
|
||||
value2 = $2003
|
||||
PUT 0, value, Word value2 ' write value to SP location 0
|
||||
' and value2 to SP locations 1 & 2
|
||||
|
||||
value = $FF ' modify variables
|
||||
value2 = $FFFF
|
||||
|
||||
GET 0, value, Word value2 ' retrieve from Scratchpad
|
||||
|
||||
DEBUG HEX2 ? value ' display
|
||||
DEBUG HEX4 ? value2
|
||||
END
|
||||
</pre>
|
||||
<p class="PlainText">The low nibble of location 63 (BS2e and BS2sx) and location 127 (BS2p,
|
||||
BS2pe, and BS2px) is a special, read-only location that always contains the
|
||||
number of the currently running program slot. On the BS2p, BS2pe, and BS2px,
|
||||
the high nibble of location 127 also contains the current program slot that
|
||||
will be used for the <span class="keyword_in_text">READ</span> and <span class="keyword_in_text">WRITE</span> commands. See the
|
||||
demo program for an example of use.</p>
|
||||
<p>
|
||||
<img src="../../graphics/bsppepx_inline.gif" border="0">
|
||||
</img>
|
||||
</p>
|
||||
<p class="PlainText">On the BS2p and BS2pe, the state of polled input pins can be retrieved from
|
||||
upper Scratchpad locations:</p>
|
||||
<ul>
|
||||
<li value="1">128 : MAINIO pins 0 - 7</li>
|
||||
<li value="2">129 : MAINIO pins 8 - 15</li>
|
||||
<li value="3">130 : AUXIO pins 0 - 7</li>
|
||||
<li value="4">131 : AUXIO pins 8 - 15</li>
|
||||
</ul>
|
||||
<p class="PlainText">This information can be used to determine which input pin (or pins) has
|
||||
triggered a polled event.</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>
|
156
help/BasicStampHelp/Content/LanguageTopics/Commands/GOSUB.htm
Normal file
156
help/BasicStampHelp/Content/LanguageTopics/Commands/GOSUB.htm
Normal file
@ -0,0 +1,156 @@
|
||||
<?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>GOSUB</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">GOSUB</h1>
|
||||
<div class="ImagePlusCaption">
|
||||
<div class="Col2">
|
||||
<p>
|
||||
<img src="../../graphics/pgm_icon1.gif" border="0" alt="BS1 icon" title="BS1 icon" />
|
||||
<img src="../../graphics/pgm_icon2.gif" border="0" alt="BS2 icon" title="BS2 icon" />
|
||||
<img src="../../graphics/pgm_icon2e.gif" border="0" alt="BS2e icon" title="BS2e icon" />
|
||||
<img src="../../graphics/pgm_icon2sx.gif" border="0" alt="BS2sx icon" title="BS2sx icon" />
|
||||
<img src="../../graphics/pgm_icon2p.gif" border="0" alt="BS2p icon" title="BS2p icon" />
|
||||
<img src="../../graphics/pgm_icon2pe.gif" border="0" alt="BS2pe icon" title="BS2pe icon" />
|
||||
<img src="../../graphics/pgm_icon2px.gif" border="0" alt="BS2px icon" title="BS2px icon" />
|
||||
</p>
|
||||
</div>
|
||||
<p style="text-align: right;"><a href="../ExampleTopics/GosubEx.htm" target="" title="" alt="" class="MCXref_0">GOSUB Examples</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: <span class="keyword_in_text">GOSUB</span> <![CDATA[ ]]><i>Address</i></p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Store the address of the next instruction after <span class="keyword_in_text">GOSUB</span>, then go to the point
|
||||
in the program specified by <i>Address</i>; with the intention of returning to the
|
||||
stored address.
|
||||
|
||||
</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Address</i></b> is a label that specifies where to go.</li>
|
||||
</ul>
|
||||
<h2>Quick Facts</h2>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr>
|
||||
<td width="24%" align="center" bgcolor="#CFCFCF"> </td>
|
||||
<td width="38%" align="center" bgcolor="#CFCFCF">BS1*</td>
|
||||
<td width="38%" align="center" bgcolor="#CFCFCF">BS2 Family</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Maximum GOSUBs per program</td>
|
||||
<td align="center">16</td>
|
||||
<td align="center">255</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Maximum nested GOSUBs</td>
|
||||
<td align="center">4</td>
|
||||
<td align="center">4</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
||||
<td align="center"><a href="GOTO.htm" target="" title="" alt="" class="MCXref_0">GOTO</a>
|
||||
</td>
|
||||
<td align="center"><a href="ON_GOSUB.htm" target="" title="" alt="" class="MCXref_0">ON...GOSUB</a>, <a href="GOTO.htm" target="" title="" alt="" class="MCXref_0">GOTO</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
<p> </p>
|
||||
<P>*<img src="../../graphics/bs1note.gif" style="vertical-align: super;" /> Note: Using <span class="keyword_in_text">GOSUB</span> on the BS1 requires variables B12 and B13 (W6) making them unavailable for general program use.</P>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText"><span class="keyword_in_text">GOSUB</span> is a close relative of <span class="keyword_in_text">GOTO</span>, in fact, its name means, "GO
|
||||
to a SUBroutine". When a PBASIC program reaches a <span class="keyword_in_text">GOSUB</span>, the program
|
||||
executes the code beginning at the specified address label. Unlike <span class="keyword_in_text">GOTO</span>,
|
||||
<span class="keyword_in_text">GOSUB</span> also stores the address of the instruction immediately following
|
||||
itself. When the program encounters a <span class="keyword_in_text">RETURN</span> command, it interprets it
|
||||
to mean, "go to the instruction that follows the most recent <span class="keyword_in_text">GOSUB</span>." In
|
||||
other words, a <span class="keyword_in_text">GOSUB</span> makes the BASIC Stamp do a similar operation as
|
||||
you do when you see a table or figure reference in this manual; 1) you
|
||||
remember where you are, 2) you go to the table or figure and read the
|
||||
information there, and 3) when you've reached the end of it, you "return"
|
||||
to the place you were reading originally.</p>
|
||||
<h3>GOSUB Can Save EEPROM (Program) Space</h3>
|
||||
<p class="PlainText"><span class="keyword_in_text">GOSUB</span> is mainly used to execute the same piece of code from multiple
|
||||
locations. If you have, for example, a block of three lines of code that need
|
||||
to be run from 10 different locations in your entire program you could
|
||||
simple copy and paste those three lines to each of those 10 locations. This
|
||||
would amount to a total of 30 lines of repetitive code (and extra space
|
||||
wasted in the program memory). A better solution is to place those three
|
||||
lines in a separate routine, complete with it's own label and followed by a
|
||||
<span class="keyword_in_text">RETURN</span> command, then just use a <span class="keyword_in_text">GOSUB</span> command at each of the 10
|
||||
locations to access it. This technique can save a lot of program space.</p>
|
||||
<p class="PlainText">Try the example below:
|
||||
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
Main:
|
||||
GOSUB Hello
|
||||
DEBUG "How are you?", CR
|
||||
END
|
||||
|
||||
Hello:
|
||||
DEBUG "Hello my friend.", CR
|
||||
RETURN
|
||||
</pre>
|
||||
<p class="PlainText">The above code will start out by executing a <span class="keyword_in_text">GOSUB </span>to the section of code beginning with the label Hello. It will print "Hello my friend." on the screen then <span class="keyword_in_text">RETURN </span>to the line after the <span class="keyword_in_text">GOSUB</span>...which prints "How are you?" and <span class="keyword_in_text">END</span>s.</p>
|
||||
<h3>Watch Out For Subroutines That Your Program Can "Fall Into"</h3>
|
||||
<p class="PlainText">There's another interesting lesson here; what would happen if we removed
|
||||
the <span class="keyword_in_text">END</span> command from this example? Since the BASIC Stamp reads the
|
||||
code from left to right / top to bottom (like the English language) once it
|
||||
had returned to and run the "How are you?" line, it would naturally "fall
|
||||
into" the Hello routine again. Additionally, at the end of the Hello routine,
|
||||
it would see the <span class="keyword_in_text">RETURN</span> again (although it didn't <span class="keyword_in_text">GOSUB</span> to that
|
||||
routine this time) and because there wasn't a previous place to return to, the
|
||||
BASIC Stamp will start the entire program over again. This would cause
|
||||
an endless loop. The important thing to remember here is to always make
|
||||
sure your program doesn't allow itself to "fall into" a subroutine.</p>
|
||||
<p>*<img src="../../graphics/bs1note.gif" style="vertical-align: super;"></img> Note: On the BS1, a <span class="keyword_in_text">RETURN</span> without a <span class="keyword_in_text">GOSUB</span> will return
|
||||
the program to the last <span class="keyword_in_text">GOSUB</span> (or will end the program if no <span class="keyword_in_text">GOSUB</span>was executed).</p>
|
||||
<h3>GOSUB Limitations</h3>
|
||||
<p class="PlainText">Only a limited number of <span class="keyword_in_text">GOSUB</span>s are allowed per program (as shown in above),
|
||||
and they may be nested only four levels deep. In other words, the subroutine that's
|
||||
the destination of a <span class="keyword_in_text">GOSUB</span> can contain a <span class="keyword_in_text">GOSUB</span> to another subroutine,
|
||||
and so on, to a maximum depth (total number of <span class="keyword_in_text">GOSUB</span>s before the first
|
||||
<span class="keyword_in_text">RETURN</span>) of four. Any deeper, and the program will "forget" its way back to
|
||||
the starting point (the instruction following the very first <span class="keyword_in_text">GOSUB</span>).</p>
|
||||
<p class="PlainText">When <span class="keyword_in_text">GOSUB</span>s are nested, each <span class="keyword_in_text">RETURN</span> takes the program back to the
|
||||
instruction after the most-recent <span class="keyword_in_text">GOSUB</span>. As is mentioned above, if the
|
||||
BASIC Stamp encounters a <span class="keyword_in_text">RETURN</span> without a previous <span class="keyword_in_text">GOSUB</span>, the
|
||||
entire program starts over from the beginning. Take care to avoid these
|
||||
phenomena.</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>
|
105
help/BasicStampHelp/Content/LanguageTopics/Commands/GOTO.htm
Normal file
105
help/BasicStampHelp/Content/LanguageTopics/Commands/GOTO.htm
Normal file
@ -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="" 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>GOTO</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">GOTO</h1>
|
||||
<div class="ImagePlusCaption">
|
||||
<div class="Col2">
|
||||
<p>
|
||||
<img src="../../graphics/pgm_icon1.gif" border="0" alt="BS1 icon" title="BS1 icon" />
|
||||
<img src="../../graphics/pgm_icon2.gif" border="0" alt="BS2 icon" title="BS2 icon" />
|
||||
<img src="../../graphics/pgm_icon2e.gif" border="0" alt="BS2e icon" title="BS2e icon" />
|
||||
<img src="../../graphics/pgm_icon2sx.gif" border="0" alt="BS2sx icon" title="BS2sx icon" />
|
||||
<img src="../../graphics/pgm_icon2p.gif" border="0" alt="BS2p icon" title="BS2p icon" />
|
||||
<img src="../../graphics/pgm_icon2pe.gif" border="0" alt="BS2pe icon" title="BS2pe icon" />
|
||||
<img src="../../graphics/pgm_icon2px.gif" border="0" alt="BS2px icon" title="BS2px icon" />
|
||||
</p>
|
||||
</div>
|
||||
<p style="text-align: right;"><a href="../ExampleTopics/GotoEx.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">GOTO Example</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: <span class="keyword_in_text">GOTO</span> <![CDATA[ ]]><i>Address</i></p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Jump the point in the program specified by <i>Address</i>.
|
||||
|
||||
</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Address</i></b> is a label that specifies where to go.</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 align="center" bgcolor="#CFCFCF">BS1</td>
|
||||
<td align="center" bgcolor="#CFCFCF">All BS2 Models</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
||||
<td align="center">
|
||||
<p align="CENTER"><a href="BRANCH.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">BRANCH</a>, <a href="GOSUB.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">GOSUB</a></p>
|
||||
</td>
|
||||
<td align="center">
|
||||
<p align="CENTER"><a href="ON_GOTO.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">ON...GOTO</a>, <a href="BRANCH.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">BRANCH</a>, <a href="GOSUB.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">GOSUB</a></p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Max. GOTOs<br />per program</td>
|
||||
<td align="center" colspan="2">Unlimited, but good programming practices suggest minimizing the use of <span class="keyword_in_text">GOTO</span>.</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText">The <span class="keyword_in_text">GOTO</span> command makes the BASIC Stamp execute the code that starts at the
|
||||
specified <i>Address</i> location. The BASIC Stamp reads PBASIC code from
|
||||
left-to-right, top-to-bottom, just like in the English language. The <span class="keyword_in_text">GOTO</span>command forces the BASIC Stamp to jump to another section of code.</p>
|
||||
<p class="PlainText">A common use for <span class="keyword_in_text">GOTO</span> is to create endless loops; programs that repeat
|
||||
a group of instructions over and over. For example:
|
||||
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
Hello:
|
||||
DEBUG "Hi", CR
|
||||
PAUSE 500
|
||||
GOTO Hello
|
||||
</pre>
|
||||
<p class="PlainText">The above code will print "Hi" on the screen, over and over again. The
|
||||
<span class="code_in_text">GOTO Hello</span> line simply tells it to go back to the code that begins with
|
||||
the label Hello.</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>
|
109
help/BasicStampHelp/Content/LanguageTopics/Commands/HIGH.htm
Normal file
109
help/BasicStampHelp/Content/LanguageTopics/Commands/HIGH.htm
Normal file
@ -0,0 +1,109 @@
|
||||
<?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>HIGH</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">HIGH</h1>
|
||||
<div class="ImagePlusCaption">
|
||||
<div class="Col2">
|
||||
<p>
|
||||
<img src="../../graphics/pgm_icon1.gif" border="0" alt="BS1 icon" title="BS1 icon" />
|
||||
<img src="../../graphics/pgm_icon2.gif" border="0" alt="BS2 icon" title="BS2 icon" />
|
||||
<img src="../../graphics/pgm_icon2e.gif" border="0" alt="BS2e icon" title="BS2e icon" />
|
||||
<img src="../../graphics/pgm_icon2sx.gif" border="0" alt="BS2sx icon" title="BS2sx icon" />
|
||||
<img src="../../graphics/pgm_icon2p.gif" border="0" alt="BS2p icon" title="BS2p icon" />
|
||||
<img src="../../graphics/pgm_icon2pe.gif" border="0" alt="BS2pe icon" title="BS2pe icon" />
|
||||
<img src="../../graphics/pgm_icon2px.gif" border="0" alt="BS2px icon" title="BS2px icon" />
|
||||
</p>
|
||||
</div>
|
||||
<p style="text-align: right;"><a href="../ExampleTopics/HighLowEx.htm" target="" title="" alt="" class="MCXref_0">HIGH / LOW Example</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: <span class="keyword_in_text">HIGH</span> <![CDATA[ ]]><i>Pin</i></p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Make the specified pin an output and high.
|
||||
|
||||
</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Pin</i></b> is a variable/constant/expression (0 - 15) that specifies
|
||||
which I/O pin to set high. This pin will be placed into output mode.</li>
|
||||
</ul>
|
||||
<p class="PlainText">*<img src="../../graphics/bs1note.gif" style="vertical-align: super;" /> Note: expressions are not allowed as arguments on the BS1. The range
|
||||
of the <i>Pin</i> argument on the BS1 is 0–7.</p>
|
||||
<h2>Quick Facts</h2>
|
||||
<table cellpadding="4" cellspacing="0" border="1" style="caption-side: top;width: 100%;">
|
||||
<col />
|
||||
<col />
|
||||
<tr bgcolor="#CFCFCF">
|
||||
<td width="15%" align="center"> </td>
|
||||
<td width="85%" align="center">BS1 and all BS2 models</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
||||
<td>
|
||||
<p align="center"><a href="LOW.htm" target="" title="" alt="" class="MCXref_0">LOW</a>, <a href="TOGGLE.htm" target="" title="" alt="" class="MCXref_0">TOGGLE</a></p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p> </p>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText">The <span class="keyword_in_text">HIGH</span> command sets the specified pin to 1 (a +5 volt level) and then
|
||||
sets its mode to output. For example:
|
||||
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
 HIGH 6
|
||||
</pre>
|
||||
<p class="PlainText">...does exactly the same thing as:</p>
|
||||
<p>
|
||||
<img src="../../graphics/bs1_inline.gif" border="0" />
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
 PIN6 = 1
|
||||
 DIR6 = 1
|
||||
</pre>
|
||||
<p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0">
|
||||
</img>
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
 OUT6 = 1
|
||||
 DIR6 = 1
|
||||
</pre>
|
||||
<p class="PlainText">Using the <span class="keyword_in_text">HIGH</span> command is faster in this case.</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>
|
366
help/BasicStampHelp/Content/LanguageTopics/Commands/I2CIN.htm
Normal file
366
help/BasicStampHelp/Content/LanguageTopics/Commands/I2CIN.htm
Normal file
@ -0,0 +1,366 @@
|
||||
<?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>I2CIN</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">I2CIN</h1>
|
||||
<div class="ImagePlusCaption">
|
||||
<div class="Col2">
|
||||
<p>
|
||||
<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/I2cInOutEx.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">I2CIN / I2COUT Example</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: <span class="keyword_in_text">I2CIN</span> <![CDATA[ ]]><i>Pin</i>,<i> SlaveID</i>,<i><![CDATA[ ]]></i>{<i>Address </i>{\<i>LowAddress</i>},} [<i>InputData</i>]</p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Receive data from a device using the I<sup>2</sup>C<sup>®</sup> protocol.
|
||||
|
||||
</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Pin</i></b> is a variable/constant/expression (0 or 8) that specifies
|
||||
which I/O pins to use. I<sup>2</sup>C devices require two I/O pins to communicate.
|
||||
The <i>Pin</i> argument serves a double purpose; specifying the first pin (for
|
||||
connection to the devices's SDA pin) and, indirectly, the other required pin (for
|
||||
connection to the devices's SCL pin). See explanation below. Both I/O pins will
|
||||
be toggled between output and input mode during the <span class="keyword_in_text">I2CIN</span> command and both
|
||||
will be set to input mode by the end of the <span class="keyword_in_text">I2CIN</span> command.</li>
|
||||
<li value="2"><b><i>SlaveID</i></b> is a variable/constant/expression (0 - 255) indicating
|
||||
the unique ID of the I<sup>2</sup>C device.</li>
|
||||
<li value="3"><b><i>Address</i></b> is a variable/constant/expression (0 - 255) indicating
|
||||
the desired address within the I<sup>2</sup>C device to receive data from. The
|
||||
<i>Address</i> argument may be used with the optional <i>LowAddress</i> argument
|
||||
to indicate a word-sized address value. Note that some devices like the
|
||||
PCF8574 do not require an internal address, so this parameter is optional (BS2p
|
||||
firmware 1.3 or later is required to omit the <i>Address</i> parameter).</li>
|
||||
<li value="4"><b><i>LowAddress</i></b> is a variable/constant/expression (0 - 255)
|
||||
indicating the low-byte of the word-sized address within the I<sup>2</sup>C
|
||||
device to receive data from. This argument must be used along with the
|
||||
<i>Address</i> argument.</li>
|
||||
<li value="5"><b><i>InputData</i></b> is a list of variables and modifiers that tells
|
||||
<span class="keyword_in_text">I2CIN</span> what to do with incoming data. <span class="keyword_in_text">I2CIN</span> can store data in a
|
||||
variable or array, interpret numeric text (decimal, binary, or hex) and store
|
||||
the corresponding value in a variable, wait for a fixed or variable sequence
|
||||
of bytes, or ignore a specified number of bytes. These actions can be combined
|
||||
in any order in the <i>InputData</i> list.</li>
|
||||
</ul>
|
||||
<h2>Quick Facts</h2>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF">
|
||||
<td align="center"> </td>
|
||||
<td align="center" colspan="2">BS2p, BS2pe, and BS2px</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="250" align="center" bgcolor="#CFCFCF">Value of <i>Pin</i></td>
|
||||
<td width="40%" align="center">0</td>
|
||||
<td width="40%" align="center">8</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">I/O Pin Arrangement</td>
|
||||
<td>0: Serial Data (SDA) pin<br></br>1: Serial Clock (SCL) pin</td>
|
||||
<td>8: Serial Data (SDA) pin<br></br>9: Serial Clock (SCL) pin</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Transmission Rate</td>
|
||||
<td colspan="2">Approximately 81 kBits/sec (BS2p), 45 kBits/sec (BS2pe),
|
||||
83 kBits/sec (BS2px) -- not including overhead.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Special Notes</td>
|
||||
<td colspan="2">Both the SDA and SCL pins must have 4.7 kΩ
|
||||
pull-up resisters.<br /> The I2CIN command does not allow for multiple masters.<br /> The BASIC Stamp cannot operate as an I<sup>2</sup>C slave device.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
||||
<td align="center" colspan="2">
|
||||
<p colspan="2" align="center"><a href="I2COUT.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">I2COUT</a>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText">The I<sup>2</sup>C protocol is a form of synchronous serial communication
|
||||
developed by Philips Semiconductor. It only requires two I/O pins and both
|
||||
pins can be shared between multiple I<sup>2</sup>C devices. The <span class="keyword_in_text">I2CIN</span>command allows the BASIC Stamp to receive data from an I<sup>2</sup>C device.</p>
|
||||
<p class="PlainText">The following is an example of the <span class="keyword_in_text">I2CIN</span> command:</p><pre class="BScode" xml:space="preserve">
|
||||
result VAR Byte
|
||||
|
||||
Main:
|
||||
I2CIN 0, $A1, 0, [result]
|
||||
STOP
|
||||
</pre>
|
||||
<p class="PlainText">This code will transmit a "read" command to an I<sup>2</sup>C device (connected
|
||||
to I/O pins 0 and 1) and then will receive one byte and store it in the variable
|
||||
<i>result</i>. Though it may seem strange, the <span class="keyword_in_text">I2CIN</span> command first transmits
|
||||
some data and then receives data. It must first transmit information (ID, read/write
|
||||
and address) in order to tell the I<sup>2</sup>C device what information it would
|
||||
like to receive. The exact information transmitted ($A1, 0) depends on the
|
||||
I<sup>2</sup>C device that is being used.</p>
|
||||
<p class="PlainText">The example above will read a byte of data from location 0 of a 24LC16B EEPROM
|
||||
from Microchip. The figure below shows the proper wiring for this example to work.
|
||||
The <i>SlaveID</i> argument ($A1) is both the ID of the chip and the command to
|
||||
read from the chip; the 1 means read. The <i>Address</i> argument (0) is the EEPROM
|
||||
location to read from. Note that the <span class="keyword_in_text">I2CIN</span> command will make up to eight
|
||||
attempts to connect to the addressed device. If the device does not properly
|
||||
respond, the <span class="keyword_in_text">I2CIN</span> command will timeout and the <i>InputData</i> will
|
||||
remain unchanged.</p>
|
||||
<p class="PlainText"><b>Note</b>: The 4.7 kΩ resisters are required for the <span class="keyword_in_text">I2CIN</span>command to function properly.</p>
|
||||
<center>
|
||||
<img src="../../graphics/24lc16_sch.gif" width="262" height="234" border="0">
|
||||
</img>
|
||||
</center>
|
||||
<p class="PlainText">The <span class="keyword_in_text">I2CIN</span> command's <i>InputData</i> argument is similar to the
|
||||
<span class="keyword_in_text">SERIN</span> command's <i>InputData</i> argument. This means data can be received
|
||||
as ASCII character values, decimal, hexadecimal and binary translations and string
|
||||
data as in the examples below. (Assume the 24LC16B EEPROM is used and it has the
|
||||
string, "Value: 3A:101" stored, starting at location 0).</p><pre class="BScode" xml:space="preserve">
|
||||
value VAR Byte(13)
|
||||
|
||||
Main:
|
||||
I2CIN 0, $A1, 0, [value] ' receive ASCII code for "V"
|
||||
I2CIN 0, $A1, 0, [DEC value] ' receive number 3
|
||||
I2CIN 0, $A1, 0, [HEX value] ' receive number $3A
|
||||
I2CIN 0, $A1, 0, [BIN value] ' receive number %101
|
||||
I2CIN 0, $A1, 0, [STR value\13] ' receive string "Value: 3A:101"
|
||||
STOP
|
||||
</pre>
|
||||
<p class="PlainText">The tables below list all the available conversion formatters and special
|
||||
formatters available to the <span class="keyword_in_text">I2CIN</span> command. See the <a href="SERIN.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">SERIN</a> command for additional information and examples
|
||||
of their use.</p>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF" align="center" valign="top">
|
||||
<td width="15%">Conversion Formatter</td>
|
||||
<td width="45%">Type of Number</td>
|
||||
<td width="30%">Numeric Characters Accepted</td>
|
||||
<td width="10%">Notes</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>DEC{1..5}</td>
|
||||
<td>Decimal, optionally limited to 1 - 5 digits</td>
|
||||
<td>0 through 9</td>
|
||||
<td>1</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>SDEC{1..5}</td>
|
||||
<td>Signed decimal, optionally limited to 1 - 5 digits</td>
|
||||
<td>-, 0 through 9</td>
|
||||
<td>1,2</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>HEX{1..4}</td>
|
||||
<td>Hexadecimal, optionally limited to 1 - 4 digits</td>
|
||||
<td>0 through 9, A through F</td>
|
||||
<td>1,3</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>SHEX{1..4}</td>
|
||||
<td>Signed hexadecimal, optionally limited to 1 - 4 digits </td>
|
||||
<td>-, 0 through 9, A through F</td>
|
||||
<td>1,2,3</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>IHEX{1..4}</td>
|
||||
<td>Indicated hexadecimal, optionally limited to 1 - 4 digits</td>
|
||||
<td>$, 0 through 9, A through F</td>
|
||||
<td>1,3,4</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>ISHEX{1..4}</td>
|
||||
<td>Signed, indicated hexadecimal, optionally limited to 1 - 4 digits</td>
|
||||
<td>-, $, 0 through 9, A through F</td>
|
||||
<td>1,2,3,4</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>BIN{1..16}</td>
|
||||
<td>Binary, optionally limited to 1 - 16 digits</td>
|
||||
<td>0, 1</td>
|
||||
<td>1</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>SBIN{1..16}</td>
|
||||
<td>Signed binary, optionally limited to 1 - 16 digits</td>
|
||||
<td>-, 0, 1</td>
|
||||
<td>1,2</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>IBIN{1..16}</td>
|
||||
<td>Indicated binary, optionally limited to 1 - 16 digits</td>
|
||||
<td>%, 0, 1</td>
|
||||
<td>1,4</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>ISBIN{1..16}</td>
|
||||
<td>Signed, indicated binary, optionally limited to 1 - 16 digits</td>
|
||||
<td>-, %, 0, 1</td>
|
||||
<td>1,2,4</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>NUM</td>
|
||||
<td>Generic numeric input; hex or binary number must be indicated</td>
|
||||
<td>$, %, 0 through 9, A through F</td>
|
||||
<td>1,3,4</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>SNUM</td>
|
||||
<td>Similar to NUM with value treated as signed with range -32768 to +32767</td>
|
||||
<td>-, $, %, 0 through 9, A through F</td>
|
||||
<td>1,2,3,4</td>
|
||||
</tr>
|
||||
</table>
|
||||
<ol>
|
||||
<li value="1">All numeric conversions will continue to accept new data until receiving
|
||||
either the specified number of digits (ex: three digits for DEC3) or a non-numeric
|
||||
character.</li>
|
||||
<li value="2">To be recognized as part of a number, the minus sign (-) must immediately
|
||||
precede a numeric character. The minus sign character occurring in non-numeric
|
||||
text is ignored and any character (including a space) between a minus and a number
|
||||
causes the minus to be ignored.</li>
|
||||
<li value="3">The hexadecimal formatters are not case-sensitive; "a" through "f" means
|
||||
the same as "A" through "F".</li>
|
||||
<li value="4">Indicated hexadecimal and binary formatters ignore all characters, even valid
|
||||
numerics, until they receive the appropriate prefix ($ for hexadecimal, % for
|
||||
binary). The indicated formatters can differentiate between text and hexadecimal
|
||||
(ex: ABC would be interpreted by HEX as a number but IHEX would ignore it unless
|
||||
expressed as $ABC). Likewise, the binary version can distinguish the decimal
|
||||
number 10 from the binary number %10. A prefix occurring in non-numeric text
|
||||
is ignored, and any character (including a space) between a prefix and a number
|
||||
causes the prefix to be ignored. Indicated, signed formatters require that the
|
||||
minus sign come before the prefix, as in -$1B45.</li>
|
||||
</ol>
|
||||
<p> </p>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF" align="center" valign="top">
|
||||
<td width="20%">Special Formatter</td>
|
||||
<td width="80%">Action</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">STR ByteArray \L {\E}</td>
|
||||
<td>Input a character string of length L into an array. If specified, an end
|
||||
character E causes the string input to end before reaching length L. Remaining
|
||||
bytes are filled with 0s (zeros).</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">WAITSTR ByteArray {\L}</td>
|
||||
<td>Wait for a sequence of bytes matching a string stored in an array variable,
|
||||
optionally limited to L characters. If the optional L argument is left off,
|
||||
the end of the array-string must be marked by a byte containing a zero (0).</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">SKIP Length</td>
|
||||
<td>Ignore Length bytes of characters.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">SPSTR Length</td>
|
||||
<td>Buffer Length bytes (up to 126) of serial characters to Scratchpad RAM,
|
||||
starting at location 0. Use <a href="GET.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">GET</a> to retrieve the characters.</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p> </p>
|
||||
<p class="PlainText">The I<sup>2</sup>C protocol has a well-defined standard for the information
|
||||
passed at the start of each transmission. First of all, any information sent must
|
||||
be transmitted in units of one byte (8-bits). The first byte, we call the
|
||||
<i>SlaveID</i>, is an 8-bit pattern whose upper 7-bits contain the unique ID of
|
||||
the device you wish to communicate with. The lowest bit indicates whether this
|
||||
is a write operation (0) or a read operation (1). Here is the <i>SlaveID</i> <![CDATA[ ]]>format:</p>
|
||||
<center>
|
||||
<table cellpadding="4" cellspacing="0" border="1">
|
||||
<tr align="center" bgcolor="#CFCFCF">
|
||||
<td width="35">7</td>
|
||||
<td width="35">6</td>
|
||||
<td width="35">5</td>
|
||||
<td width="35">4</td>
|
||||
<td width="35">3</td>
|
||||
<td width="35">2</td>
|
||||
<td width="35">1</td>
|
||||
<td width="35">0</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>A<sub>6</sub></td>
|
||||
<td>A<sub>5</sub></td>
|
||||
<td>A<sub>4</sub></td>
|
||||
<td>A<sub>3</sub></td>
|
||||
<td>A<sub>2</sub></td>
|
||||
<td>A<sub>1</sub></td>
|
||||
<td>A<sub>0</sub></td>
|
||||
<td>R/W</td>
|
||||
</tr>
|
||||
</table>
|
||||
</center>
|
||||
<p> </p>
|
||||
<p class="PlainText">The second byte, immediately following the <i>SlaveID</i>, is the <i>Address</i>.
|
||||
It indicates the 8-bit address (within the device) containing the data you would
|
||||
like to receive.</p>
|
||||
<p class="PlainText">Some devices require more than eights bits of address. For this case, the optional
|
||||
<i>LowAddress</i> argument can be used for the low-byte of the required address.
|
||||
When using the <i>LowAddress</i> argument, the <i>Address</i> argument is effectively
|
||||
the high-byte of the address value. For example, if the entire address value is
|
||||
2050, use 8 for the Address argument and 2 for the <i>LowAddress</i> argument
|
||||
(8 * 256 + 2 = 2050).</p>
|
||||
<p class="PlainText">Following the last address byte is the first byte of data. This data byte may
|
||||
be transmitted or received by the BASIC Stamp. In the case of the <span class="keyword_in_text">I2CIN</span>command, this data byte is transmitted by the device and received by the BASIC
|
||||
Stamp. Additionally, multiple data bytes can follow the address, depending on the
|
||||
I<sup>2</sup>C device. Note that every device has different limitations regarding
|
||||
how may contiguous bytes they can receive or transmit in one session. Be aware of
|
||||
these device limitations and program accordingly.</p>
|
||||
<p class="PlainText">Every I<sup>2</sup>C transmission session begins with a Start Condition and
|
||||
ends with a Stop Condition. Additionally, immediately after every byte is
|
||||
transmitted, an extra clock cycle is used to send or receive an acknowledgment
|
||||
signal (ACK). All of these operations are automatically taken care of by the
|
||||
<span class="keyword_in_text">I2CIN</span> command so that you need not be concerned with them. The general
|
||||
I<sup>2</sup>C transmission format is shown below.</p>
|
||||
<center>
|
||||
<img src="../../graphics/i2c_packet.gif" width="531" height="245" border="0">
|
||||
</img>
|
||||
</center>
|
||||
<p class="PlainText">Since the <span class="keyword_in_text">I2CIN</span> command is intended for input only, it actually overrides
|
||||
the "R/W" bit (bit 0) in the <i>SlaveID</i> argument. This is done so that it can
|
||||
use the I<sup>2</sup>C protocol's "Combined Format" for receiving data. Put simply,
|
||||
this means a command such as:
|
||||
|
||||
</p><pre class="BScode" xml:space="preserve"> I2CIN 0, $A1, 10, [result]</pre>
|
||||
<p class="PlainText">...actually transmits $A0, then 10, then $A1 and then it reads the data back from the device. The $A0 means "write", the 10 is the address to write to and, finally, the $A1 indicates a change of direction; to "read" the location, instead. Even though the <span class="keyword_in_text">I2CIN</span> command really doesn't care what the value of the <i>SlaveID</i>'s LSB is, it is suggested that you still set it appropriately for clarity.
|
||||
</p>
|
||||
<p class="PlainText">Also note that the <span class="keyword_in_text">I2CIN</span> command does not support multiple I<sup>2</sup>C
|
||||
masters and the BASIC Stamp cannot operate as an I<sup>2</sup>C slave device.</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>
|
327
help/BasicStampHelp/Content/LanguageTopics/Commands/I2COUT.htm
Normal file
327
help/BasicStampHelp/Content/LanguageTopics/Commands/I2COUT.htm
Normal file
@ -0,0 +1,327 @@
|
||||
<?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>I2COUT</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">I2COUT</h1>
|
||||
<div class="ImagePlusCaption">
|
||||
<div class="Col2">
|
||||
<p>
|
||||
<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/I2cInOutEx.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">I2CIN / I2COUT Example</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: <span class="keyword_in_text">I2COUT</span> <![CDATA[ ]]><i>Pin</i>,<i> SlaveID</i>,<i><![CDATA[ ]]></i>{<i>Address </i>{\<i>LowAddress</i>},} [<i>OutputData</i>]</p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Send data to a device using the I<sup>2</sup>C<sup>®</sup> protocol.
|
||||
|
||||
</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Pin</i></b> is a variable/constant/expression (0 or 8) that specifies
|
||||
which I/O pins to use. I<sup>2</sup>C devices require two I/O pins to communicate.
|
||||
The <i>Pin</i> argument serves a double purpose; specifying the first pin (for
|
||||
connection to the device's SDA pin) and, indirectly, the other required pin (for
|
||||
connection to the device's SCL pin). See explanation below. Both I/O pins will be
|
||||
toggled between output and input mode during the <span class="keyword_in_text">I2COUT</span> command and both
|
||||
will be set to input mode by the end of the <span class="keyword_in_text">I2COUT</span> command.</li>
|
||||
<li value="2"><b><i>SlaveID</i></b> is a variable/constant/expression (0 - 255) indicating
|
||||
the unique ID of the I<sup>2</sup>C device.</li>
|
||||
<li value="3"><b><i>Address</i></b> is a variable/constant/expression (0 - 255) indicating
|
||||
the desired address within the I<sup>2</sup>C device to send data to. The
|
||||
<i>Address</i> argument may be used with the optional <i>LowAddress</i> argument
|
||||
to indicate a word-sized address value. Note that some devices like the
|
||||
PCF8574 do not require an internal address, so this parameter is optional (BS2p
|
||||
firmware 1.3 or later is required to omit the <i>Address</i> parameter).</li>
|
||||
<li value="4"><b><i>LowAddress</i></b> is a variable/constant/expression (0 - 255) indicating
|
||||
the low-byte of the word-sized address within the I<sup>2</sup>C device to send
|
||||
data to. This argument must be used along with the <i>Address</i> argument.</li>
|
||||
<li value="5"><b><i>OutputData</i></b> is a list of variables, constants, expressions and
|
||||
formatters that tells <span class="keyword_in_text">I2COUT</span> how to format outgoing data. <span class="keyword_in_text">I2COUT</span>can transmit individual or repeating bytes, convert values into decimal,
|
||||
hexadecimal or binary text representations, or transmit strings of bytes from
|
||||
variable arrays. These actions can be combined in any order in the
|
||||
<i>OutputData</i> list.</li>
|
||||
</ul>
|
||||
<h2>Quick Facts</h2>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF">
|
||||
<td align="center"> </td>
|
||||
<td align="center" colspan="2">BS2p, BS2pe, and BS2px</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="250" align="center" bgcolor="#CFCFCF">Value of <i>Pin</i></td>
|
||||
<td width="40%" align="center">0</td>
|
||||
<td width="40%" align="center">8</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">I/O Pin Arrangement</td>
|
||||
<td>0: Serial Data (SDA) pin<br></br>1: Serial Clock (SCL) pin</td>
|
||||
<td>8: Serial Data (SDA) pin<br></br>9: Serial Clock (SCL) pin</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Transmission Rate</td>
|
||||
<td colspan="2">Approximately 81 kBits/sec (BS2p), 45 kBits/sec (BS2pe),
|
||||
83 kBits/sec (BS2px) -- not including overhead.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Special Notes</td>
|
||||
<td colspan="2">Both the SDA and SCL pins must have 4.7 kΩ pull-up
|
||||
resistors.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
||||
<td align="center" colspan="2">
|
||||
<p colspan="2" align="center"><a href="I2CIN.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">I2CIN</a>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText">The I<sup>2</sup>C protocol is a form of synchronous serial communication developed
|
||||
by Philips Semiconductor. It only requires two I/O pins and both pins can be
|
||||
shared between multiple I<sup>2</sup>C devices. The <span class="keyword_in_text">I2COUT</span> command allows
|
||||
the BASIC Stamp to send data to an I<sup>2</sup>C device.</p>
|
||||
<p class="PlainText">The following is an example of the <span class="keyword_in_text">I2COUT</span> command:</p><pre class="BScode" xml:space="preserve"> I2COUT 0, $A0, 5, [100]</pre>
|
||||
<p class="PlainText">This code will transmit a "write" command to an I<sup>2</sup>C device (connected
|
||||
to I/O pins 0 and 1), followed by an address of 5 and finally will transmit the
|
||||
number 100.</p>
|
||||
<p class="PlainText">The example above will write a byte of data to location 5 of a 24LC16B EEPROM from
|
||||
Microchip. The figure below shows the proper wiring for this example to work. The
|
||||
<i>SlaveID</i> argument ($A0) is both the ID of the chip and the command to write to
|
||||
the chip; the 0 means write. The <i>Address</i> argument (5) is the EEPROM location
|
||||
to write to.</p>
|
||||
<p class="PlainText"><b>Note</b>: The 4.7 kΩ resisters are required for the <span class="keyword_in_text">I2COUT</span>
|
||||
command to function properly.</p>
|
||||
<center>
|
||||
<img src="../../graphics/24lc16_sch.gif" border="0">
|
||||
</img>
|
||||
</center>
|
||||
<p class="PlainText">The <span class="keyword_in_text">I2COUT</span> command's <i>OutputData</i> argument is similar to the
|
||||
<span class="keyword_in_text">DEBUG</span> and <span class="keyword_in_text">SEROUT</span> command's <i>OutputData</i> argument. This means
|
||||
data can be sent as literal text, ASCII character values, repetitive values,
|
||||
decimal, hexadecimal and binary translations and string data as in the examples
|
||||
below. (Assume the 24LC16B EEPROM is being used).</p><pre class="BScode" xml:space="preserve">
|
||||
value VAR Byte
|
||||
|
||||
Setup:
|
||||
value = 65
|
||||
|
||||
Main:
|
||||
I2COUT 0, $A0, 0, [value] ' send ASCII character "A"
|
||||
I2COUT 0, $A0, 0, [REP value\5] ' send "A" five times, i.e., "AAAAA"
|
||||
I2COUT 0, $A0, 0, [DEC value] ' send "6" and "5"
|
||||
I2COUT 0, $A0, 0, [HEX value] ' send "4" and "1"
|
||||
I2COUT 0, $A0, 0, [BIN value] ' send "1000001"
|
||||
END
|
||||
</pre>
|
||||
<p class="PlainText">The tables below list all the available conversion formatters and special
|
||||
formatters available to the <span class="keyword_in_text">I2COUT</span> command. See the <a href="DEBUG.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">DEBUG</a> and <a href="SEROUT.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">SEROUT</a> commands for
|
||||
additional information and examples of their use.</p>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF" align="center" valign="top">
|
||||
<td width="20%">Conversion Formatter</td>
|
||||
<td width="70%">Type of Number</td>
|
||||
<td width="10%">Notes</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>DEC{1..5}</td>
|
||||
<td align="left">Decimal, optionally fixed to 1 - 5 digits</td>
|
||||
<td>1</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>SDEC{1..5}</td>
|
||||
<td align="left">Signed decimal, optionally fixed to 1 - 5 digits</td>
|
||||
<td>1,2</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>HEX{1..4}</td>
|
||||
<td align="left">Hexadecimal, optionally fixed to 1 - 4 digits</td>
|
||||
<td>1</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>SHEX{1..4}</td>
|
||||
<td align="left">Signed hexadecimal, optionally fixed to 1 - 4 digits </td>
|
||||
<td>1,2</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>IHEX{1..4}</td>
|
||||
<td align="left">Indicated hexadecimal, optionally fixed to 1 - 4 digits</td>
|
||||
<td>1</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>ISHEX{1..4}</td>
|
||||
<td align="left">Signed, indicated hexadecimal, optionally fixed to 1 - 4
|
||||
digits ($ prefix)</td>
|
||||
<td>1,2</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>BIN{1..16}</td>
|
||||
<td align="left">Binary, optionally fixed to 1 - 16 digits</td>
|
||||
<td>1</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>SBIN{1..16}</td>
|
||||
<td align="left">Signed binary, optionally fixed to 1 - 16 digits</td>
|
||||
<td>1,2</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>IBIN{1..16}</td>
|
||||
<td align="left">Indicated binary, optionally fixed to 1 - 16 digits</td>
|
||||
<td>1</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>ISBIN{1..16}</td>
|
||||
<td align="left">Signed, indicated binary, optionally fixed to 1 - 16 digits</td>
|
||||
<td>1,2</td>
|
||||
</tr>
|
||||
</table>
|
||||
<ol>
|
||||
<li value="1">Fixed-digit formatters like DEC4 will pad the number with leading 0s if
|
||||
necessary; ex: DEC4 65 sends 0065. If a number is larger than the specified
|
||||
number of digits, the leading digits will be dropped; ex: DEC4 56422 sends
|
||||
6422.</li>
|
||||
<li value="2">Signed modifiers work under two's complement rules.</li>
|
||||
</ol>
|
||||
<p> </p>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF" align="center" valign="top">
|
||||
<td width="20%">Special Formatter</td>
|
||||
<td width="80%">Action</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">?</td>
|
||||
<td>Displays "symbol = x' + carriage return; where x is a number. Default
|
||||
format is decimal, but may be combined with conversion formatters (ex: BIN
|
||||
? x to display "x = binary_number").</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">ASC ?</td>
|
||||
<td>Displays "symbol = 'x'" + carriage return; where x is an ASCII character.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">STR ByteArray {\L}</td>
|
||||
<td>Send character string from an array. The optional \L argument can be used
|
||||
to limit the output to L characters, otherwise, characters will be sent up to
|
||||
the first byte equal to 0 or the end of RAM space is reached.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">REP Byte\L</td>
|
||||
<td>Send a string consisting of Byte repeated L times (ex: REP "X"\10
|
||||
sends "XXXXXXXXXX").</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p> </p>
|
||||
<p class="PlainText">The I<sup>2</sup>C protocol has a well-defined standard for the information
|
||||
passed at the start of each transmission. First of all, any information sent must
|
||||
be transmitted in units of one byte (8-bits). The first byte, we call the
|
||||
<i>SlaveID</i>, is an 8-bit pattern whose upper 7-bits contain the unique ID of
|
||||
the device you wish to communicate with. The lowest bit indicates whether this
|
||||
is a write operation (0) or a read operation (1). Here is the <i>SlaveID</i> <![CDATA[ ]]>format:</p>
|
||||
<center>
|
||||
<table cellpadding="4" cellspacing="0" border="1">
|
||||
<tr align="center" bgcolor="#CFCFCF">
|
||||
<td width="35">7</td>
|
||||
<td width="35">6</td>
|
||||
<td width="35">5</td>
|
||||
<td width="35">4</td>
|
||||
<td width="35">3</td>
|
||||
<td width="35">2</td>
|
||||
<td width="35">1</td>
|
||||
<td width="35">0</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>A<sub>6</sub></td>
|
||||
<td>A<sub>5</sub></td>
|
||||
<td>A<sub>4</sub></td>
|
||||
<td>A<sub>3</sub></td>
|
||||
<td>A<sub>2</sub></td>
|
||||
<td>A<sub>1</sub></td>
|
||||
<td>A<sub>0</sub></td>
|
||||
<td>R/W</td>
|
||||
</tr>
|
||||
</table>
|
||||
</center>
|
||||
<p> </p>
|
||||
<p class="PlainText">The second byte, immediately following the <i>SlaveID</i>, is the <i>Address</i>.
|
||||
It indicates the 8-bit address (within the device) where the <i>OutputData</i> is
|
||||
to be written (the first location if more than one byte is written). Note that
|
||||
the <i>Address</i> argument is optional and may be left unspecified for devices
|
||||
that don't require an address parameter.</p>
|
||||
<p class="PlainText">Some devices require more than eights bits of address. For this case, the optional
|
||||
<i>LowAddress</i> argument can be used for the low-byte of the required address.
|
||||
When using the <i>LowAddress</i> argument, the <i>Address</i> argument is
|
||||
effectively the high-byte of the address value. For example, if the entire
|
||||
address value is 2050, use 8 for the <i>Address</i> argument and 2 for the
|
||||
<i>LowAddress</i> argument (8 * 256 + 2 = 2050).</p>
|
||||
<p class="PlainText">Following the last address byte is the first byte of data. This data byte may
|
||||
be transmitted or received by the BASIC Stamp. In the case of the <span class="keyword_in_text">I2COUT</span>
|
||||
command, this data byte is transmitted by the BASIC Stamp and received by the
|
||||
device. Additionally, multiple data bytes can follow the address, depending on
|
||||
the I<sup>2</sup>C device. Note that every device has different limitations
|
||||
regarding how may contiguous bytes they can receive or transmit in one session.
|
||||
Be aware of these device limitations and program accordingly.</p>
|
||||
<p class="PlainText">Every I<sup>2</sup>C transmission session begins with a Start Condition and
|
||||
ends with a Stop Condition. Additionally, immediately after every byte is
|
||||
transmitted, an extra clock cycle is used to send or receive an acknowledgment
|
||||
signal (ACK). All of these operations are automatically taken care of by the
|
||||
<span class="keyword_in_text">I2CIN</span> command so that you need not be concerned with them. The general
|
||||
I<sup>2</sup>C transmission format is shown below.</p>
|
||||
<center>
|
||||
<img src="../../graphics/i2c_packet.gif" border="0">
|
||||
</img>
|
||||
</center>
|
||||
<p> </p>
|
||||
<p class="PlainText">Since the <span class="keyword_in_text">I2COUT</span> command is intended for output only, it actually
|
||||
overrides the "R/W" bit (bit 0) in the <i>SlaveID</i> argument. This is done to
|
||||
avoid device conflicts should the value be mistyped. Put simply, this means
|
||||
commands such as:
|
||||
|
||||
</p><pre class="BScode" xml:space="preserve"> I2COUT 0, $A0, 10, [0] </pre>
|
||||
<p class="PlainText">...and:</p><pre class="BScode" xml:space="preserve"> I2COUT 0, $A1, 10, [0]</pre>
|
||||
<p class="PlainText">...both transmit the same thing ($A0, then 10, then the data). Even though the
|
||||
<span class="keyword_in_text">I2COUT</span> command really doesn't care what the value of the <i>SlaveID</i>'s
|
||||
LSB is, it is suggested that you still set it appropriately for clarity.</p>
|
||||
<p class="PlainText">Also note that the <span class="keyword_in_text">I2COUT</span> command does not support multiple I<sup>2</sup>C
|
||||
masters and the BASIC Stamp cannot operate as an I<sup>2</sup>C slave device.</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>
|
453
help/BasicStampHelp/Content/LanguageTopics/Commands/IF_THEN.htm
Normal file
453
help/BasicStampHelp/Content/LanguageTopics/Commands/IF_THEN.htm
Normal file
@ -0,0 +1,453 @@
|
||||
<?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>IF…THEN</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">IF…THEN</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" /><span class="code_in_text"> {PBASIC 1.0} {PBASIC 2.0}</span>
|
||||
</p>
|
||||
</div>
|
||||
<p style="text-align: right;"><a href="../ExampleTopics/IfThenEx.htm" target="" title="" alt="" class="MCXref_0">IF...THEN Examples</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax:
|
||||
<b>IF</b> <![CDATA[ ]]><i>Condition</i> <![CDATA[ ]]><b>THEN</b> <![CDATA[ ]]><i>Address</i></p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Evaluate <i>Condition</i> and, if it is true, go to the point in the program marked
|
||||
by <i>Address</i>.
|
||||
|
||||
</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Condition</i></b> is a statement, such as "x = 7" that can be evaluated
|
||||
as True or False. The <i>Condition</i> can be a very simple or very complex
|
||||
relationship, as described below.</li>
|
||||
<li value="2"><b><i>Address</i></b> is a label that specifies where to go in the event that
|
||||
<i>Condition</i> is true.</li>
|
||||
</ul>
|
||||
<p class="PlainText">Note: See <a href="IF_THEN_ELSE.htm" target="" title="" alt="" class="MCXref_0">IF…THEN…ELSE</a> for all BS2 models and PBASIC 2.5.</p>
|
||||
<h2>Quick Facts</h2>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr>
|
||||
<td width="20%" align="center" bgcolor="#CFCFCF"> </td>
|
||||
<td width="30%" align="center" bgcolor="#CFCFCF">BS1</td>
|
||||
<td width="30%" align="center" bgcolor="#CFCFCF">BS2 Family</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Comparison operators</td>
|
||||
<td align="center">=, <>, >, <, >=, <=</td>
|
||||
<td align="center">=, <>, >, <, >=, <=</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Conditional Logic Operators</td>
|
||||
<td align="center">AND, OR</td>
|
||||
<td align="center">NOT, AND, OR, XOR</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Format of <i>Condition</i></td>
|
||||
<td align="center"><i>Variable Comparison Value</i>;<br /> where <i>Value</i> is a variable or constant</td>
|
||||
<td align="center"><i>Value1 Comparison Value2</i>;<br /> where <i>Value1</i> and <i>Value2</i> can be any of variable, constant or expression</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Parentheses</td>
|
||||
<td align="center">Not Allowed</td>
|
||||
<td align="center">Allowed</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
||||
<td align="center" colspan="1">
|
||||
<p colspan="1" align="center">None</p>
|
||||
</td>
|
||||
<td align="center" colspan="1">
|
||||
<p colspan="1" align="center"><a href="IF_THEN_ELSE.htm" target="" title="" alt="" class="MCXref_0">IF…THEN…ELSE</a>, <a href="SELECT_CASE.htm" target="" title="" alt="" class="MCXref_0">SELECT...CASE</a></p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText"><span class="keyword_in_text">IF...THEN</span> is PBASIC's primary decision maker. It tests a condition and, if
|
||||
that condition is true, goes to a point in the program specified by an address label.
|
||||
The condition that <span class="keyword_in_text">IF...THEN</span> tests is written as a mixture of comparison
|
||||
and logic operators. The available comparison operators are: </p>
|
||||
<center>
|
||||
<table cellpadding="4" cellspacing="0" border="1">
|
||||
<tr>
|
||||
<td width="130" align="center" bgcolor="#CFCFCF">Comparison Operator Symbol</td>
|
||||
<td width="170" align="center" bgcolor="#CFCFCF">Definition</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">=</td>
|
||||
<td align="center">Equal</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><></td>
|
||||
<td align="center">Not Equal</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">></td>
|
||||
<td align="center">Greater Than</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><</td>
|
||||
<td align="center">Less Than</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">>=</td>
|
||||
<td align="center">Greater Than or Equal To</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><=</td>
|
||||
<td align="center">Less Than or Equal To</td>
|
||||
</tr>
|
||||
</table>
|
||||
</center>
|
||||
<p> </p>
|
||||
<p class="PlainText">Comparisons are always written in the form: <i>Value1 Comparison Value2</i>. The
|
||||
values to be compared can be any combination of variables (any size), constants,
|
||||
or expressions. </p>
|
||||
<p class="PlainText">
|
||||
<img src="../../graphics/bs1note.gif" style="vertical-align: super;" /> Note: On the BS1, expressions are not allowed as arguments, and
|
||||
<i>Value1</i> (to the left of comparison) must be a variable.</p>
|
||||
<p class="PlainText">The following example is an <span class="keyword_in_text">IF...THEN</span> command with a simple condition:</p><pre class="BScode" xml:space="preserve">
|
||||
IF 10 < 200 THEN Main
|
||||
</pre>
|
||||
<p class="PlainText">This code will compare the number 10 to the number 200. If 10 is less than 200,
|
||||
the condition is true. In this case, 10 is less than 200 (and always will be),
|
||||
so the program will jump (or <span class="keyword_in_text">GOTO</span>) the label called Main. Of course, this
|
||||
is a silly example (10 is always less than 200 so this line will always cause a
|
||||
jump to Main). Most of the time, you'll use at least one variable in your condition:</p>
|
||||
<p>
|
||||
<img src="../../graphics/bs1_inline.gif" border="0">
|
||||
</img>
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
SYMBOL value = W1
|
||||
|
||||
Main:
|
||||
PULSIN 0, 1, value
|
||||
DEBUG #value, CR
|
||||
IF value < 4000 THEN Main
|
||||
DEBUG "Value was greater than 4000!"
|
||||
END
|
||||
</pre>
|
||||
<p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0">
|
||||
</img>
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
value VAR Word
|
||||
|
||||
Main:
|
||||
PULSIN 0, 1, value
|
||||
DEBUG DEC value, CR
|
||||
IF (value < 4000) THEN Main
|
||||
DEBUG "Value was greater than 4000!"
|
||||
END
|
||||
</pre>
|
||||
<p class="PlainText">Here, the BASIC Stamp will look for and measure a pulse on I/O pin 0, then compare
|
||||
the result, value, against 4000. If value is less than (<) 4000, it will jump
|
||||
back to Main. Each time through the loop, it displays the measured value and once
|
||||
it is greater than or equal to 4000, it displays, "Value was greater than 4000!"</p>
|
||||
<p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0">
|
||||
</img>
|
||||
</p>
|
||||
<p class="PlainText">On the BS2, BS2e, BS2sx, BS2p, and BS2pe, the values can be expressions as well.
|
||||
This leads to very flexible and sophisticated comparisons. The <span class="keyword_in_text">IF...THEN</span>
|
||||
statement below is functionally the same as the one in the program above:</p><pre class="BScode" xml:space="preserve">
|
||||
IF (value < (45 * 100 - (25 * 20))) THEN Main
|
||||
</pre>
|
||||
<p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0">
|
||||
</img>
|
||||
</p>
|
||||
<p class="PlainText">Here the BASIC Stamp evaluates the expression: 45 * 100 = 4500, 25 * 20 = 500,
|
||||
and 4500 - 500 = 4000. Then the BASIC Stamp performs the comparison: is value <
|
||||
4000? Another example that is functionally the same:</p><pre class="BScode" xml:space="preserve">
|
||||
IF ((value / 100) < 40) THEN Main
|
||||
</pre>
|
||||
<p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0">
|
||||
</img>
|
||||
</p>
|
||||
<p class="PlainText">It's important to realize that all comparisons are performed using unsigned,
|
||||
16-bit math. This can lead to strange results if you mix signed and unsigned numbers
|
||||
in <span class="keyword_in_text">IF...THEN</span> conditions. Watch what happens here when we include a signed
|
||||
number (-99):</p><pre class="BScode" xml:space="preserve">
|
||||
IF (-99 < 100) THEN Is_Less
|
||||
DEBUG "Greater than or equal to 100"
|
||||
END
|
||||
|
||||
Is_Less:
|
||||
DEBUG "Less than 100"
|
||||
END
|
||||
|
||||
|
||||
</pre>
|
||||
<p class="PlainText">Although -99 is obviously less than 100, the program will say it is greater.
|
||||
The problem is that -99 is internally represented as the two's complement value
|
||||
65437, which (using unsigned math) is greater than 100. This phenomena will occur
|
||||
whether or not the negative value is a constant, variable or expression. </p>
|
||||
<p class="PlainText"><span class="keyword_in_text">IF...THEN</span> supports the conditional logic operators NOT, AND, OR, and XOR.
|
||||
See the table below for a list of the operators and their effects. NOTE: The NOT
|
||||
and XOR operators are not available on the BS1.</p>
|
||||
<p class="PlainText">The NOT operator inverts the outcome of a condition, changing False to True,
|
||||
and True to False. The following <span class="keyword_in_text">IF...THEN</span>s are equivalent: </p><pre class="BScode" xml:space="preserve">
|
||||
IF (x <> 100) THEN Not_Equal ' Jump to Not_Equal if x is not 100
|
||||
IF NOT (x = 100) THEN Not_Equal ' Jump to Not_Equal if x is not 100
|
||||
</pre>
|
||||
<p>
|
||||
<img src="../../graphics/bs1_inline.gif" border="0">
|
||||
</img>
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
SYMBOL value1 = B2
|
||||
SYMBOL value2 = B3
|
||||
|
||||
Setup:
|
||||
value1 = 5
|
||||
value2 = 9
|
||||
|
||||
Main:
|
||||
IF value1 = 5 AND value2 = 10 THEN Is_True ' change AND to OR and see
|
||||
DEBUG "Statement was false." ' what happens
|
||||
END
|
||||
|
||||
Is_True:
|
||||
DEBUG "Statement was true."
|
||||
END
|
||||
</pre>
|
||||
<p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0">
|
||||
</img>
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
value1 VAR Byte
|
||||
value2 VAR Byte
|
||||
|
||||
Setup:
|
||||
value1 = 5
|
||||
value2 = 9
|
||||
|
||||
Main:
|
||||
' Change AND to OR and see what happens
|
||||
IF (value1 = 5) AND (value2 = 10) THEN Is_True
|
||||
DEBUG "Statement was false."
|
||||
END
|
||||
|
||||
Is_True:
|
||||
DEBUG "Statement was true."
|
||||
END
|
||||
</pre>
|
||||
<p class="PlainText">The condition "(value1 = 5) AND (value2 = 10)" is not true. Although value1 is
|
||||
5, value2 is not 10. The AND operator works just as it does in English; both
|
||||
conditions must be true for the statement to be true. The OR operator also works
|
||||
in a familiar way; if one or the other or both conditions are true, then the
|
||||
statement is true. The XOR operator (short for exclusive-OR) may not be familiar,
|
||||
but it does have an English counterpart: If one condition or the other (but not
|
||||
both) is true, then the statement is true. </p>
|
||||
<p class="PlainText">The table below summarizes the effects of the conditional logic operators. As
|
||||
with math, you can alter the order in which comparisons and logical operations
|
||||
are performed by using parentheses. Operations are normally evaluated left-to-right.
|
||||
Putting parentheses around an operation forces PBASIC 2.0 to evaluate it before
|
||||
operations not in parentheses. </p>
|
||||
<p class="PlainText">
|
||||
<img src="../../graphics/bs1note.gif" style="vertical-align: super;" /> Note: On the BS1, parentheses are not allowed within
|
||||
arguments.</p>
|
||||
<center>
|
||||
<table cellpadding="4" cellspacing="0" border="1">
|
||||
<tr>
|
||||
<td width="100" align="center" bgcolor="#CFCFCF">Condition A</td>
|
||||
<td width="100" align="center" bgcolor="#CFCFCF">NOT A</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">False</td>
|
||||
<td align="center">True</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">True</td>
|
||||
<td align="center">False</td>
|
||||
</tr>
|
||||
</table>
|
||||
<br>
|
||||
</br>
|
||||
<table cellpadding="4" cellspacing="0" border="1">
|
||||
<tr>
|
||||
<td width="100" align="center" bgcolor="#CFCFCF">Condition A</td>
|
||||
<td width="100" align="center" bgcolor="#CFCFCF">Condition B</td>
|
||||
<td width="100" align="center" bgcolor="#CFCFCF">A AND B</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">False</td>
|
||||
<td align="center">False</td>
|
||||
<td align="center">False</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">False</td>
|
||||
<td align="center">True</td>
|
||||
<td align="center">False</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">True</td>
|
||||
<td align="center">False</td>
|
||||
<td align="center">False</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">True</td>
|
||||
<td align="center">True</td>
|
||||
<td align="center">True</td>
|
||||
</tr>
|
||||
</table>
|
||||
<br>
|
||||
</br>
|
||||
<table cellpadding="4" cellspacing="0" border="1">
|
||||
<tr>
|
||||
<td width="100" align="center" bgcolor="#CFCFCF">Condition A</td>
|
||||
<td width="100" align="center" bgcolor="#CFCFCF">Condition B</td>
|
||||
<td width="100" align="center" bgcolor="#CFCFCF">A OR B</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">False</td>
|
||||
<td align="center">False</td>
|
||||
<td align="center">False</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">False</td>
|
||||
<td align="center">True</td>
|
||||
<td align="center">True</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">True</td>
|
||||
<td align="center">False</td>
|
||||
<td align="center">True</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">True</td>
|
||||
<td align="center">True</td>
|
||||
<td align="center">True</td>
|
||||
</tr>
|
||||
</table>
|
||||
<br>
|
||||
</br>
|
||||
<table cellpadding="4" cellspacing="0" border="1">
|
||||
<tr>
|
||||
<td width="100" align="center" bgcolor="#CFCFCF">Condition A</td>
|
||||
<td width="100" align="center" bgcolor="#CFCFCF">Condition B</td>
|
||||
<td width="100" align="center" bgcolor="#CFCFCF">A XOR B</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">False</td>
|
||||
<td align="center">False</td>
|
||||
<td align="center">False</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">False</td>
|
||||
<td align="center">True</td>
|
||||
<td align="center">True</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">True</td>
|
||||
<td align="center">False</td>
|
||||
<td align="center">True</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">True</td>
|
||||
<td align="center">True</td>
|
||||
<td align="center">False</td>
|
||||
</tr>
|
||||
</table>
|
||||
</center>
|
||||
<p> </p>
|
||||
<p class="PlainText">Unlike the <span class="keyword_in_text">IF...THEN</span> commands in other BASIC language variants, PBASIC 1.0/2.0's
|
||||
<span class="keyword_in_text">IF...THEN</span> can only go to a label as the result of a decision. It cannot
|
||||
conditionally perform some instruction, as in "IF x < 20 THEN y = y + 1" (This
|
||||
is possible using the $PBASIC 2.5 directive). To achieve this in PBASIC 1.0 and 2.0,
|
||||
you have to invert the logic using NOT and skip over the conditional instruction
|
||||
unless the condition is met: </p><pre class="BScode" xml:space="preserve">
|
||||
IF NOT (x < 20) THEN No_Inc ' Don't increment y unless x < 20.
|
||||
y = y + 1 ' Increment y if x < 20.
|
||||
|
||||
No_Inc: ' Program continues.
|
||||
</pre>
|
||||
<p class="PlainText">You can also code a conditional <span class="keyword_in_text">GOSUB</span>, as in "<span class="code_in_text">IF (x = 100) THEN GOSUB Centennial</span>."
|
||||
In PBASIC 2.0:</p><pre class="BScode" xml:space="preserve">
|
||||
IF NOT (x = 100) THEN No_Cent
|
||||
GOSUB Centennial ' IF x = 100 THEN GOSUB Centennial.
|
||||
|
||||
No_Cent: ' Program continues.
|
||||
</pre>
|
||||
<p class="PlainText">Internally, the BASIC Stamp defines "False" as 0 and "True" as any value other
|
||||
than 0. Consider the following instructions: </p><pre class="BScode" xml:space="preserve">
|
||||
flag VAR Bit
|
||||
|
||||
Setup:
|
||||
flag = 1
|
||||
|
||||
Test:
|
||||
IF flag THEN Is_True
|
||||
|
||||
Is_False:
|
||||
DEBUG "False", CR
|
||||
END
|
||||
|
||||
Is_True:
|
||||
DEBUG "True"
|
||||
END
|
||||
</pre>
|
||||
<p class="PlainText">Since flag is 1, <span class="keyword_in_text">IF...THEN</span> would evaluate it as true and print the message
|
||||
"True" on the screen. Suppose you changed the <span class="keyword_in_text">IF...THEN</span> command to read
|
||||
"<span class="code_in_text">IF NOT (flag) THEN IsTrue</span>." That would also evaluate as True. Whoa! Isn't NOT 1
|
||||
the same thing as 0? No, at least not in the 16-bit world of the BASIC Stamp.</p>
|
||||
<p class="PlainText">Internally, the BASIC Stamp sees a bit variable containing 1 as the 16-bit number
|
||||
%0000000000000001. So it sees the NOT of that as %1111111111111110. Since any
|
||||
non-zero number is regarded as True, NOT 1 is True. Strange but true. </p>
|
||||
<p class="PlainText">The easiest way to avoid the kinds of problems this might cause is to always
|
||||
use a conditional operator with <span class="keyword_in_text">IF...THEN</span>. Change the example above to read
|
||||
<span class="code_in_text">IF (flag = 1) THEN Is_True</span>. The result of the comparison will follow <span class="keyword_in_text">IF...THEN</span>rules. Also, the logical operators will work as they should; <span class="code_in_text">IF NOT (flag = 1)
|
||||
THEN Is_True</span> will correctly evaluate to False when flag contains 1.</p>
|
||||
<p class="PlainText">This also means that you should only use the "named" conditional logic operators
|
||||
NOT, AND, OR, and XOR with <span class="keyword_in_text">IF...THEN</span>. The conditional logic operators format
|
||||
their results correctly for <span class="keyword_in_text">IF...THEN</span> instructions. The other logical
|
||||
operators, represented by symbols ~ & | and ^ do not; they are binary logic operators.</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,181 @@
|
||||
<?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>IF…THEN…ELSE</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">IF…THEN…ELSE</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;"><a href="../ExampleTopics/IfThenElseEx.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">IF...THEN...ELSE Example</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: <br /><br />   <b>IF</b> <![CDATA[ ]]><i>Condition</i> <![CDATA[ ]]><span class="keyword_in_text">THEN</span><br />     <i>Statement(s)</i><br /> { <span class="keyword_in_text">ELSEIF</span> <![CDATA[ ]]><i>Condition(s)</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><br /><br />   <b>IF</b> <![CDATA[ ]]><i>Condition</i> <![CDATA[ ]]><span class="keyword_in_text">THEN</span> <![CDATA[ ]]><i>Statement(s)</i>{ <span class="keyword_in_text">ELSEIF</span> <![CDATA[ ]]><i>Statement(s)</i> } { <span class="keyword_in_text">ELSE</span> <![CDATA[ ]]><i>Statement(s)</i> }</p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Evaluate <i>Condition</i> and, if it is true, execute the statement(s) following
|
||||
<span class="keyword_in_text">THEN</span>, otherwise jump to and evaluate the <span class="keyword_in_text">ELSEIF</span> condition. If no
|
||||
<span class="keyword_in_text">ELSEIF</span> statement/block is provided, jump to and execute the statements that
|
||||
follow <span class="keyword_in_text">ELSE</span>. If no <span class="keyword_in_text">ELSE</span> block is provided, the program will continue
|
||||
at the line that follows <span class="keyword_in_text">ENDIF</span> (or the next line when single-line syntax
|
||||
is used).
|
||||
|
||||
</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Condition</i></b> is a statement, such as "x = 7" that can be evaluated
|
||||
as True or False. The <i>Condition</i> can be a very simple or very complex
|
||||
relationship, as described below.</li>
|
||||
<li value="2"><b><i>Statement</i></b> is any valid PBASIC statement. Multiple statements
|
||||
may be placed on the same line (though not recommended) by separating each
|
||||
statement with a colon ( : ).</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="80%" align="center" bgcolor="#CFCFCF">BS2 Family</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Comparison operators</td>
|
||||
<td align="center">=, <>, >, <, >=, <=</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Conditional Logic Operators</td>
|
||||
<td align="center">NOT, AND, OR, XOR</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Format of condition</td>
|
||||
<td align="center"><i>Value1 Comparison Value2</i>;<br />where <i>Value1</i> and <i>Value2</i> can
|
||||
be any of variable, constant or expression</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Parentheses</td>
|
||||
<td align="center">Allowed</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Nesting</td>
|
||||
<td align="center">Up to 16 levels</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
||||
<td align="center" colspan="1">
|
||||
<p colspan="1" align="center"><a href="IF_THEN.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">IF…THEN</a>, <a href="SELECT_CASE.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">SELECT...CASE</a></p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText"><span class="keyword_in_text">IF...THEN...ELSE</span> is a primary PBASIC decision maker that allows one block of
|
||||
code or [optionally] another to run based on the value (True or False) of a condition.
|
||||
The condition that <span class="keyword_in_text">IF...THEN...ELSE</span> tests is written as a mixture of
|
||||
comparison and logic operators. The available comparison operators are:</p>
|
||||
<center>
|
||||
<table cellpadding="4" cellspacing="0" border="1">
|
||||
<tr>
|
||||
<td width="130" align="center" bgcolor="#CFCFCF">Comparison Operator Symbol</td>
|
||||
<td width="170" align="center" bgcolor="#CFCFCF">Definition</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">=</td>
|
||||
<td align="center">Equal</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><></td>
|
||||
<td align="center">Not Equal</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">></td>
|
||||
<td align="center">Greater Than</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><</td>
|
||||
<td align="center">Less Than</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">>=</td>
|
||||
<td align="center">Greater Than or Equal To</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><=</td>
|
||||
<td align="center">Less Than or Equal To</td>
|
||||
</tr>
|
||||
</table>
|
||||
</center>
|
||||
<p> </p>
|
||||
<p class="PlainText">Comparisons are always written in the form: <i>Value1 Comparison Value2</i>. The values
|
||||
to be compared can be any combination of variables (any size), constants, or
|
||||
expressions.</p><pre class="BScode" xml:space="preserve">
|
||||
value VAR Word
|
||||
|
||||
Main:
|
||||
DO
|
||||
PULSIN 0, 1, value ' measure pulse input
|
||||
DEBUG DEC value, CR
|
||||
IF (value > 4000) THEN ' evaluate duration
|
||||
DEBUG "Value was greater than 4000"
|
||||
ELSEIF (value = 4000) THEN
|
||||
DEBUG "Value was equal to 4000"
|
||||
ELSE
|
||||
DEBUG "Value was less than 4000"
|
||||
ENDIF
|
||||
DEBUG CR, CR
|
||||
PAUSE 1000
|
||||
LOOP
|
||||
</pre>
|
||||
<p class="PlainText">Here, the BASIC Stamp will look for and measure a pulse on I/O pin 0, then
|
||||
compare the result, value, against 4000. Based on this comparison, a message
|
||||
regarding the pulse width value will be printed.</p>
|
||||
<p class="PlainText">In the following example, single-line syntax is used. Note that <span class="keyword_in_text">ENDIF</span>
|
||||
is not required when using single-line formatting of <span class="keyword_in_text">IF...THEN...ELSE</span>:
|
||||
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
DEBUG "Your grade is: "
|
||||
IF (score >= 90) THEN DEBUG "A", CR : ELSE DEBUG "B (or less)", CR
|
||||
</pre>
|
||||
<p class="PlainText">See <a href="IF_THEN.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">IF…THEN</a> for additional details on the use of
|
||||
comparison and conditional operators. </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>
|
123
help/BasicStampHelp/Content/LanguageTopics/Commands/INPUT.htm
Normal file
123
help/BasicStampHelp/Content/LanguageTopics/Commands/INPUT.htm
Normal file
@ -0,0 +1,123 @@
|
||||
<?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>INPUT</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">INPUT</h1>
|
||||
<div class="ImagePlusCaption">
|
||||
<div class="Col2">
|
||||
<p>
|
||||
<img src="../../graphics/pgm_icon1.gif" border="0" alt="BS1 icon" title="BS1 icon" />
|
||||
<img src="../../graphics/pgm_icon2.gif" border="0" alt="BS2 icon" title="BS2 icon" />
|
||||
<img src="../../graphics/pgm_icon2e.gif" border="0" alt="BS2e icon" title="BS2e icon" />
|
||||
<img src="../../graphics/pgm_icon2sx.gif" border="0" alt="BS2sx icon" title="BS2sx icon" />
|
||||
<img src="../../graphics/pgm_icon2p.gif" border="0" alt="BS2p icon" title="BS2p icon" />
|
||||
<img src="../../graphics/pgm_icon2pe.gif" border="0" alt="BS2pe icon" title="BS2pe icon" />
|
||||
<img src="../../graphics/pgm_icon2px.gif" border="0" alt="BS2px icon" title="BS2px icon" />
|
||||
</p>
|
||||
</div>
|
||||
<p style="text-align: right;"><a href="../ExampleTopics/InputOutputEx.htm" target="" title="" alt="" class="MCXref_0">INPUT / OUTPUT Examples</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: <span class="keyword_in_text">INPUT </span> <![CDATA[ ]]><i>Pin</i></p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Make the specified pin an input.
|
||||
|
||||
</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Pin</i></b> is a variable/constant/expression* (0 - 15) that specifies
|
||||
which I/O pin to set to input mode.</li>
|
||||
</ul>
|
||||
<p class="PlainText">*<img src="../../graphics/bs1note.gif" style="vertical-align: super;" /> Note: expressions are not allowed as arguments on the BS1. The range
|
||||
of the <i>Pin</i> argument on the BS1 is 0–7.</p>
|
||||
<h2>Quick Facts</h2>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr>
|
||||
<td align="center" width="150" bgcolor="#CFCFCF"> </td>
|
||||
<td align="center" width="40%" bgcolor="#CFCFCF">BS1</td>
|
||||
<td align="center" width="40%" bgcolor="#CFCFCF">All BS2 Models</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Input Pin Variables</td>
|
||||
<td align="center">PINS: PIN0 through PIN7</td>
|
||||
<td align="center">INS; IN0 through IN15</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
||||
<td align="center" colspan="2">
|
||||
<p colspan="2" align="center"><a href="OUTPUT.htm" target="" title="" alt="" class="MCXref_0">OUTPUT</a>, <a href="REVERSE.htm" target="" title="" alt="" class="MCXref_0">REVERSE</a></p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText">There are several ways to make a pin an input. When the BASIC Stamp is reset, all
|
||||
of the pins are inputs. Commands that rely on input pins, like <span class="keyword_in_text">PULSIN</span> and
|
||||
<span class="keyword_in_text">SERIN</span>, automatically change the specified pin to input. Writing 0s to
|
||||
particular bits of the variable DIRS makes the corresponding pins inputs. And
|
||||
then there’s the <span class="keyword_in_text">INPUT</span> command.</p>
|
||||
<p class="PlainText">When a pin is an input, your program can check its state by reading from
|
||||
the corresponding INS variable (PINS on the BS1). For example:</p>
|
||||
<p>
|
||||
<img src="../../graphics/bs1_inline.gif" width="9" height="16" border="0">
|
||||
</img>
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
Setup:
|
||||
INPUT 4
|
||||
|
||||
Hold:
|
||||
IF PIN4 = 0 THEN Hold ' Stay here until P4 is 1
|
||||
</pre>
|
||||
<p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0">
|
||||
</img>
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
Setup:
|
||||
INPUT 4
|
||||
|
||||
Hold:
|
||||
IF (IN4 = 0) THEN Hold ' Stay here until P4 is 1
|
||||
</pre>
|
||||
<p class="PlainText">What happens if your program writes to the OUTS bit (PINS bit on the
|
||||
BS1) of a pin that is set up as an input? The value is stored in OUTS (PINS
|
||||
on the BS1), but has no effect on the outside world. If the pin is changed to
|
||||
output, the last value written to the corresponding OUTS bit (or PINS bit
|
||||
on the BS1) will appear on the pin. The Example program shows how this works.</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>
|
115
help/BasicStampHelp/Content/LanguageTopics/Commands/IOTERM.htm
Normal file
115
help/BasicStampHelp/Content/LanguageTopics/Commands/IOTERM.htm
Normal file
@ -0,0 +1,115 @@
|
||||
<?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>IOTERM</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">IOTERM</h1>
|
||||
<div class="ImagePlusCaption">
|
||||
<div class="Col2">
|
||||
<p>
|
||||
<img src="../../graphics/pgm_icon2p.gif" border="0" alt="BS2p icon" title="BS2p icon" /> (BS2p40)</p>
|
||||
</div>
|
||||
<p style="text-align: right;"><a href="../ExampleTopics/AuMainIotermEx.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">AUXIO / MAINIO / IOTERM Example</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: <span class="keyword_in_text">IOTERM</span> <![CDATA[ ]]><i>Port</i></p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Switch program control to main I/O pins or auxiliary I/O pins (on the BS2p40 only)
|
||||
depending on the value of <i>Port</i>.
|
||||
</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Port</i></b> is a variable/constant/expression (0 - 1) that specifies
|
||||
which I/O port to use.</li>
|
||||
</ul>
|
||||
<h2>Quick Facts</h2>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF">
|
||||
<td width="15%" align="center"> </td>
|
||||
<td width="85%" align="center">BS2p, BS2pe, and BS2px</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Values for <i>Port</i></td>
|
||||
<td>0 = switch to main I/O group, 1 = switch to auxiliary I/O group.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">I/O Pin IDs</td>
|
||||
<td>0 - 15 (after IOTERM command, all references affect physical pins
|
||||
5 - 20 or 21 - 36 depending on state of <i>Port).</i></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Special Notes</td>
|
||||
<td>
|
||||
<p>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.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
||||
<td align="center" colspan="1">
|
||||
<p colspan="1" align="center"><a href="AUXIO.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">AUXIO</a>, <a href="MAINIO.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">MAINIO</a></p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText">The BS2p, BS2pe, and BS2px is available as a 24-pin module that is pin-compatible
|
||||
with the BS2, BS2e, and BS2sx. Also availabe is a 40-pin module called the BS2p40
|
||||
with an additional 16 I/O pins (for a total of 32). The BS2p40's I/O pins are
|
||||
organized into two groups, called main and auxiliary. The I/O pins in each group
|
||||
can be accessed in the same manner (by referencing I/O pins 0 - 15) but access is
|
||||
only possible within one group at a time. The <span class="keyword_in_text">IOTERM</span> command causes the
|
||||
BASIC Stamp to affect either the main or auxiliary I/O pins in all further code
|
||||
until the <span class="keyword_in_text">MAINIO</span>, <span class="keyword_in_text">AUXIO</span> or another <span class="keyword_in_text">IOTERM</span> command is reached,
|
||||
or the BASIC Stamp is reset or power-cycled. The value of <i>Port</i> determines
|
||||
which group of I/O pins will be referenced. Using 0 for <i>Port</i> will switch
|
||||
to the main I/O group and using 1 for Port will switch to the auxiliary group.</p>
|
||||
<p class="PlainText">The following example illustrates this:</p><pre class="BScode" xml:space="preserve">
|
||||
HIGH 0
|
||||
IOTERM 1
|
||||
LOW 0
|
||||
</pre>
|
||||
<p class="PlainText">The first line of the above example will set I/O pin 0 of the main I/O pins
|
||||
(physical pin 5) high. Afterward, the <span class="keyword_in_text">IOTERM</span> command tells the BASIC
|
||||
Stamp that all commands following it should affect the auxiliary I/O pins
|
||||
(Port = 1). The following <span class="keyword_in_text">LOW</span> command will set I/O pin 0 of the
|
||||
auxiliary I/O pins (physical pin 21) low.</p>
|
||||
<p class="PlainText">Note that the main I/O and auxiliary I/O pins are independent of each
|
||||
other; the states of the main I/O pins remain unchanged while the
|
||||
program affects the auxiliary I/O pins, and vice versa.</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>
|
570
help/BasicStampHelp/Content/LanguageTopics/Commands/LCDCMD.htm
Normal file
570
help/BasicStampHelp/Content/LanguageTopics/Commands/LCDCMD.htm
Normal file
@ -0,0 +1,570 @@
|
||||
<?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>LCDCMD</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">LCDCMD</h1>
|
||||
<div class="ImagePlusCaption">
|
||||
<div class="Col2">
|
||||
<p>
|
||||
<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/LcdcmdEx.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">LCDCMD Example</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: <span class="keyword_in_text">LCDCMD</span> <![CDATA[ ]]><i>Pin</i>,<i> Command</i></p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Send a command to an LCD display.
|
||||
|
||||
</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Pin</i></b> is a variable/constant/expression (0 - 1 or 8 - 9) that
|
||||
specifies which I/O pins to use. The LCD requires, at most, seven I/O pins
|
||||
to operate. The <i>Pin</i> argument serves a double purpose; specifying the
|
||||
first pin and, indirectly the group of other required pins. See explanation
|
||||
below. All I/O pins will be set to output mode.</li>
|
||||
<li value="2"><b><i>Command</i></b> is a variable/constant/expression (0 - 255) indicating
|
||||
the LCD command to send.</li>
|
||||
</ul>
|
||||
<h2>Quick Facts</h2>
|
||||
<table cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF">
|
||||
<td width="275" align="center"> </td>
|
||||
<td width="1200" align="center">BS2p, BS2pe, and BS2px</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Values for <i>Pin</i></td>
|
||||
<td align="center">0, 1, 8, or 9</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">I/O pin arrangement when <i>Pin</i>
|
||||
is 0 or 1</td>
|
||||
<td>0 or 1 (depending on <i>Pin</i>) : LCD Enable (E) pin<br></br> 2 : LCD Read/Write (R/W) pin<br></br> 3 : LCD Register Select (RS) pin<br></br> 4 - 7 : LCD Data Bus (DB4 - DB7, respectively) pins</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">I/O pin arrangement when <i>Pin</i> is
|
||||
8 or 9</td>
|
||||
<td>8 or 9 (depending on <i>Pin</i>) : LCD Enable (E) pin<br></br> 10 : LCD Read/Write (R/W) pin<br></br> 11 : LCD Register Select (RS) pin<br></br> 12 - 15 : LCD Data Bus (DB4 - DB7, respectively) pins</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Special Notes</td>
|
||||
<td align="center" colspan="1">LCDCMD is designed to use the LCD's 4-bit mode only.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
||||
<td align="center" colspan="1">
|
||||
<p colspan="1" align="center"><a href="LCDIN.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">LCDIN</a>, <a href="LCDOUT.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">LCDOUT</a></p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText">The three LCD commands (<span class="keyword_in_text">LCDCMD</span>, <span class="keyword_in_text">LCDIN</span> and <span class="keyword_in_text">LCDOUT</span>) allow the
|
||||
BS2p, BS2pe, or BS2px to interface directly to standard LCD displays that feature
|
||||
a Hitachi 44780 controller (part #HD44780A). This includes many 1 x 16, 2 x 16,
|
||||
and 4 x 20 character LCD displays. </p>
|
||||
<p class="PlainText">The Hitachi 44780 LCD controller supports a number of special instructions for
|
||||
initializing the display, moving the cursor, changing the default layout, etc.
|
||||
The <span class="keyword_in_text">LCDCMD</span> command is used to send one of these instructions to the LCD.
|
||||
It is most commonly used to initialize the display upon a power-up or reset
|
||||
condition. Note that <span class="keyword_in_text">LCDCMD</span>, <span class="keyword_in_text">LCDIN</span> and <span class="keyword_in_text">LCDOUT</span> use a 4-bit
|
||||
interface to the LCD which requires a specific initialization sequence before
|
||||
<span class="keyword_in_text">LCDIN</span> and <span class="keyword_in_text">LCDOUT</span> can be used. Specifics on the initialization
|
||||
sequence will follow.</p>
|
||||
<p class="PlainText">The following is an example of the <span class="keyword_in_text">LCDCMD</span> command:</p><pre class="BScode" xml:space="preserve">
|
||||
LCDCMD 1, 24
|
||||
</pre>
|
||||
<p class="PlainText">The preceding code will send the Scroll Left command (represented by the number
|
||||
24) to the LCD whose enable pin is connected to I/O pin 1. This will cause the LCD
|
||||
display to scroll, or shift, the entire display one character to the left.</p>
|
||||
<p class="PlainText">You may have noticed that the <i>Pin</i> argument in the example above was 1.
|
||||
The <span class="keyword_in_text">LCDCMD</span> command actually uses more than just this I/O pin, however.
|
||||
The <span class="keyword_in_text">LCDCMD</span> command requires seven I/O pins. This is because the standard
|
||||
LCD displays have a parallel interface, rather than a serial one. The <i>Pin</i>
|
||||
argument can be the numbers 0, 1, 8, or 9 and will result in the use of the I/O
|
||||
pins shown above. The figure below shows the required wiring for the above command
|
||||
to work.</p>
|
||||
<center>
|
||||
<img src="../../graphics/lcd_sch.gif" border="0">
|
||||
</img>
|
||||
</center>
|
||||
<p class="PlainText">Note that we could have used 0 for the Pin argument and moved the LCD's Enable
|
||||
pin (pin 6) to I/O pin 0. Similarly, using 9 for the Pin argument would have
|
||||
required us to wire the LCD's pins to I/O pins 9 through 15, rather than I/O pins
|
||||
1 through 7.</p>
|
||||
<p class="PlainText">When the LCD is first powered-up, it will be in an unknown state and must be
|
||||
properly configured before sending commands like the one shown above. This process
|
||||
is known as initializing the LCD and is the first thing your program should do
|
||||
upon starting up. The following code is a good example of LCD initialization.
|
||||
(<i>Refer to Hitachi documentation for details</i>).</p><pre class="BScode" xml:space="preserve">
|
||||
Init_LCD:
|
||||
PAUSE 1000 ' allow LCD to power-up
|
||||
LCDCMD 1, 48 ' Send wake-up sequence (3x)
|
||||
PAUSE 5
|
||||
LCDCMD 1, 48
|
||||
PAUSE 1
|
||||
LCDCMD 1, 48
|
||||
PAUSE 1
|
||||
LCDCMD 1, 32 ' Set data bus to 4-bit mode
|
||||
LCDCMD 1, 40 ' Set 2-line mode with 5x8 font
|
||||
LCDCMD 1, 8 ' Turn display off
|
||||
LCDCMD 1, 12 ' Turn display on without cursor
|
||||
LCDCMD 1, 6 ' Auto-increment cursor
|
||||
LCDCMD 1, 1 ' Clear the display
|
||||
</pre>
|
||||
<p class="PlainText">This initialization code is the most commonly used sequence for a 2 x 16 and
|
||||
4 x 20 LCD display (the 2-line mode instruction sets the 4 x 20 to 4-line mode).
|
||||
The <span class="code_in_text">PAUSE 1000</span> command is optional, but only if your program takes more
|
||||
than approximately 700 ms before it executes the Init_LCD code above. Without
|
||||
it, upon powering your circuit, the BASIC Stamp may talk to the LCD too early,
|
||||
the LCD will then miss some of the commands and the display will operate strangely,
|
||||
or not at all.</p>
|
||||
<p class="PlainText">Do not change the "wake-up" and "4-bit mode" sequence commands. However, the
|
||||
commands below the line that says, "Set data bus to 4-bit mode" may be modified
|
||||
to set other desired modes.</p>
|
||||
<p class="PlainText">The table below shows the most commonly used LCD commands. Here's an example:</p><pre class="BScode" xml:space="preserve">
|
||||
LCDCMD 1, 128 + 64
|
||||
</pre>
|
||||
<p class="PlainText">The preceding command will move the cursor to the first character position
|
||||
on the second line (on a 2 x 16 display). 128 is the Move To Display Address
|
||||
command and 64 is the location number. See the "Character Positioning" section
|
||||
below, for more information.</p>
|
||||
<h2>Common LCD Commands</h2>
|
||||
<table cellpadding="4" cellspacing="0" border="1" width="100%">
|
||||
<tr valign="top" bgcolor="#CFCFCF">
|
||||
<td width="200" align="center"> </td>
|
||||
<td width="125" align="center">Command<br></br>(Decimal)</td>
|
||||
<td align="center">Description</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td bgcolor="#CFCFCF">Do Nothing</td>
|
||||
<td align="center">0</td>
|
||||
<td>Don't perform any special function.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td bgcolor="#CFCFCF">Clear Display</td>
|
||||
<td align="center">1</td>
|
||||
<td>Move cursor and display to home position.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td bgcolor="#CFCFCF">Home Display</td>
|
||||
<td align="center">2</td>
|
||||
<td>Move cursor and display to home position.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td bgcolor="#CFCFCF">Inc Cursor</td>
|
||||
<td align="center">6</td>
|
||||
<td>Set cursor direction to right, without a display shift.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td bgcolor="#CFCFCF">Display Off</td>
|
||||
<td align="center">8</td>
|
||||
<td>Turn off display (display data is retained).</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td bgcolor="#CFCFCF">Display On</td>
|
||||
<td align="center">12</td>
|
||||
<td>Turn on display without cursor (display is restored).</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td bgcolor="#CFCFCF">Blinking Cursor</td>
|
||||
<td align="center">13</td>
|
||||
<td>Turn on display with blinking cursor.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td bgcolor="#CFCFCF">Underline Cursor</td>
|
||||
<td align="center">14</td>
|
||||
<td>Turn on display with underline cursor.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td bgcolor="#CFCFCF">Cursor Left</td>
|
||||
<td align="center">16</td>
|
||||
<td>Move cursor left one character.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td bgcolor="#CFCFCF">Cursor Right</td>
|
||||
<td align="center">20</td>
|
||||
<td>Move cursor right one character.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td bgcolor="#CFCFCF">Scroll Left</td>
|
||||
<td align="center">24</td>
|
||||
<td>Scroll display left one character.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td bgcolor="#CFCFCF">Scroll Right</td>
|
||||
<td align="center">28</td>
|
||||
<td>Scroll display right one character.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td bgcolor="#CFCFCF">Move To CGRAM Address</td>
|
||||
<td align="center">64 + address</td>
|
||||
<td>Move pointer to Character Generator RAM location</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td bgcolor="#CFCFCF">Move To DDRAM Address</td>
|
||||
<td align="center">128 + address</td>
|
||||
<td>Move cursor to Display Data RAM location</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p> </p>
|
||||
<p class="PlainText">While most users will only need the commands shown above, the table below
|
||||
details all of the instructions supported by the LCD (for advanced users). Many
|
||||
instructions are multipurpose, depending on the state of special bits. Clever
|
||||
manipulation of the instruction bits will allow for powerful control of the LCD.</p>
|
||||
<table cellpadding="4" cellspacing="0" border="1" width="100%">
|
||||
<tr valign="top" align="center" bgcolor="#CFCFCF">
|
||||
<td width="200" rowspan="2"> </td>
|
||||
<td width="200" colspan="8" align="center">Command Code (bits)</td>
|
||||
<td rowspan="2">Description</td>
|
||||
</tr>
|
||||
<tr valign="top" bgcolor="#CFCFCF">
|
||||
<td width="25" align="center">7</td>
|
||||
<td width="25" align="center">6</td>
|
||||
<td width="25" align="center">5</td>
|
||||
<td width="25" align="center">4</td>
|
||||
<td width="25" align="center">3</td>
|
||||
<td width="25" align="center">2</td>
|
||||
<td width="25" align="center">1</td>
|
||||
<td width="25" align="center">0</td>
|
||||
</tr>
|
||||
<tr align="center" valign="top">
|
||||
<td align="left" bgcolor="#CFCFCF">Clear Display</td>
|
||||
<td>0</td>
|
||||
<td>0</td>
|
||||
<td>0</td>
|
||||
<td>0</td>
|
||||
<td>0</td>
|
||||
<td>0</td>
|
||||
<td>0</td>
|
||||
<td>1</td>
|
||||
<td align="left">Clear entire display and move cursor home (address 0)</td>
|
||||
</tr>
|
||||
<tr align="center" valign="top">
|
||||
<td align="left" bgcolor="#CFCFCF">Home Display</td>
|
||||
<td>0</td>
|
||||
<td>0</td>
|
||||
<td>0</td>
|
||||
<td>0</td>
|
||||
<td>0</td>
|
||||
<td>0</td>
|
||||
<td>1</td>
|
||||
<td>0</td>
|
||||
<td align="left">Move cursor home and return display to home position.</td>
|
||||
</tr>
|
||||
<tr align="center" valign="top">
|
||||
<td align="left" bgcolor="#CFCFCF">Entry Mode</td>
|
||||
<td>0</td>
|
||||
<td>0</td>
|
||||
<td>0</td>
|
||||
<td>0</td>
|
||||
<td>0</td>
|
||||
<td>1</td>
|
||||
<td>M</td>
|
||||
<td>S</td>
|
||||
<td align="left">Sets cursor direction (M: 0=left, 1=right) and display scrolling
|
||||
(S: 0=no scroll, 1=scroll)</td>
|
||||
</tr>
|
||||
<tr align="center" valign="top">
|
||||
<td align="left" bgcolor="#CFCFCF">Display/Cursor</td>
|
||||
<td>0</td>
|
||||
<td>0</td>
|
||||
<td>0</td>
|
||||
<td>0</td>
|
||||
<td>1</td>
|
||||
<td>D</td>
|
||||
<td>U</td>
|
||||
<td>B</td>
|
||||
<td align="left">Sets display on/off (D), underline cursor (U) and blinking
|
||||
block cursor (B). (0=off, 1=on)</td>
|
||||
</tr>
|
||||
<tr align="center" valign="top">
|
||||
<td align="left" bgcolor="#CFCFCF">Scroll Display / Shift Cursor</td>
|
||||
<td>0</td>
|
||||
<td>0</td>
|
||||
<td>0</td>
|
||||
<td>1</td>
|
||||
<td>C</td>
|
||||
<td>M</td>
|
||||
<td>0</td>
|
||||
<td>0</td>
|
||||
<td align="left">Shifts display or cursor (C: 0=cursor, 1=display) left or
|
||||
right (M: 0=left, 1=right).</td>
|
||||
</tr>
|
||||
<tr align="center" valign="top">
|
||||
<td align="left" bgcolor="#CFCFCF">Function Set</td>
|
||||
<td>0</td>
|
||||
<td>0</td>
|
||||
<td>1</td>
|
||||
<td>B</td>
|
||||
<td>L</td>
|
||||
<td>F</td>
|
||||
<td>0</td>
|
||||
<td>0</td>
|
||||
<td align="left">Sets bus size (B: 0=4-bits, 1=8-bits), number of lines
|
||||
(L: 0=1?line, 1=2-lines) and font size (F: 0=5x8, 1=5x10)</td>
|
||||
</tr>
|
||||
<tr align="center" valign="top">
|
||||
<td align="left" bgcolor="#CFCFCF">Move To CGRAM Address</td>
|
||||
<td>O</td>
|
||||
<td>1</td>
|
||||
<td>A</td>
|
||||
<td>A</td>
|
||||
<td>A</td>
|
||||
<td>A</td>
|
||||
<td>A</td>
|
||||
<td>A</td>
|
||||
<td align="left">Move pointer to Character Generator RAM location specified
|
||||
by address (A)</td>
|
||||
</tr>
|
||||
<tr align="center" valign="top">
|
||||
<td align="left" bgcolor="#CFCFCF">Move To DDRAM Address</td>
|
||||
<td>1</td>
|
||||
<td>A</td>
|
||||
<td>A</td>
|
||||
<td>A</td>
|
||||
<td>A</td>
|
||||
<td>A</td>
|
||||
<td>A</td>
|
||||
<td>A</td>
|
||||
<td align="left">Move cursor to Display Data RAM location specified by
|
||||
address (A)</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p> </p>
|
||||
<p class="PlainText">The last command shown above (Move To DDRAM Address) is used to move the cursor
|
||||
to a specific position on the LCD. The LCD's DDRAM (Display Data RAM) is a fixed
|
||||
size with unique position number for each character cell. The viewable portion
|
||||
of the DDRAM depends on the LCD's logical view position (which can be altered with
|
||||
the Scroll Display command). The default view position is called the Home position;
|
||||
it means that the display's upper left character corresponds to DDRAM location 0.
|
||||
The diagrams below indicates the position numbers for characters on the LCD screen.</p>
|
||||
<p class="PlainText">Note that the diagram shows the most common DDRAM mapping, though some LCD's
|
||||
may have organized the DDRAM differently. A little experimentation with your LCD
|
||||
may reveal this.</p>
|
||||
<h3>2 x 16 Display</h3>
|
||||
<table border="0">
|
||||
<tr nowrap="" align="center" bgcolor="#CFCFCF">
|
||||
<td bgcolor="white"> </td>
|
||||
<td nowrap="" colspan="16">On-screen Positions*</td>
|
||||
<td colspan="3">Off-screen</td>
|
||||
</tr>
|
||||
<tr nowrap="" align="center" bgcolor="#99CC66">
|
||||
<td nowrap="" width="50" bgcolor="#CFCFCF">Line 1</td>
|
||||
<td width="25">0</td>
|
||||
<td width="25">1</td>
|
||||
<td width="25">2</td>
|
||||
<td width="25">3</td>
|
||||
<td width="25">4</td>
|
||||
<td width="25">5</td>
|
||||
<td width="25">6</td>
|
||||
<td width="25">7</td>
|
||||
<td width="25">8</td>
|
||||
<td width="25">9</td>
|
||||
<td width="25">10</td>
|
||||
<td width="25">11</td>
|
||||
<td width="25">12</td>
|
||||
<td width="25">13</td>
|
||||
<td width="25">14</td>
|
||||
<td width="25">15</td>
|
||||
<td width="25" bgcolor="#CFCFCF">16</td>
|
||||
<td width="25" bgcolor="#CFCFCF">...</td>
|
||||
<td width="25" bgcolor="#CFCFCF">39</td>
|
||||
</tr>
|
||||
<tr nowrap="" align="center" bgcolor="#99CC66">
|
||||
<td nowrap="" width="50" bgcolor="#CFCFCF">Line 2</td>
|
||||
<td width="25">64</td>
|
||||
<td width="25">65</td>
|
||||
<td width="25">66</td>
|
||||
<td width="25">67</td>
|
||||
<td width="25">68</td>
|
||||
<td width="25">69</td>
|
||||
<td width="25">79</td>
|
||||
<td width="25">71</td>
|
||||
<td width="25">72</td>
|
||||
<td width="25">73</td>
|
||||
<td width="25">74</td>
|
||||
<td width="25">75</td>
|
||||
<td width="25">76</td>
|
||||
<td width="25">77</td>
|
||||
<td width="25">78</td>
|
||||
<td width="25">79</td>
|
||||
<td width="25" bgcolor="#CFCFCF">80</td>
|
||||
<td width="25" bgcolor="#CFCFCF">...</td>
|
||||
<td width="25" bgcolor="#CFCFCF">103</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p class="PlainText">* Assuming the display is in the home position</p>
|
||||
<h3>4 x 20 Display</h3>
|
||||
<table border="0">
|
||||
<tr nowrap="" align="center" bgcolor="#99CC66">
|
||||
<td nowrap="" width="50" bgcolor="#CFCFCF">Line 1</td>
|
||||
<td width="25">0</td>
|
||||
<td width="25">1</td>
|
||||
<td width="25">2</td>
|
||||
<td width="25">3</td>
|
||||
<td width="25">4</td>
|
||||
<td width="25">5</td>
|
||||
<td width="25">6</td>
|
||||
<td width="25">7</td>
|
||||
<td width="25">8</td>
|
||||
<td width="25">9</td>
|
||||
<td width="25">10</td>
|
||||
<td width="25">11</td>
|
||||
<td width="25">12</td>
|
||||
<td width="25">13</td>
|
||||
<td width="25">14</td>
|
||||
<td width="25">15</td>
|
||||
<td width="25">16</td>
|
||||
<td width="25">17</td>
|
||||
<td width="25">18</td>
|
||||
<td width="25">19</td>
|
||||
</tr>
|
||||
<tr nowrap="" align="center" bgcolor="#99CC66">
|
||||
<td nowrap="" width="50" bgcolor="#CFCFCF">Line 2</td>
|
||||
<td width="25">64</td>
|
||||
<td width="25">65</td>
|
||||
<td width="25">66</td>
|
||||
<td width="25">67</td>
|
||||
<td width="25">68</td>
|
||||
<td width="25">69</td>
|
||||
<td width="25">79</td>
|
||||
<td width="25">71</td>
|
||||
<td width="25">72</td>
|
||||
<td width="25">73</td>
|
||||
<td width="25">74</td>
|
||||
<td width="25">75</td>
|
||||
<td width="25">76</td>
|
||||
<td width="25">77</td>
|
||||
<td width="25">78</td>
|
||||
<td width="25">79</td>
|
||||
<td width="25">80</td>
|
||||
<td width="25">81</td>
|
||||
<td width="25">82</td>
|
||||
<td width="25">83</td>
|
||||
</tr>
|
||||
<tr nowrap="" align="center" bgcolor="#99CC66">
|
||||
<td nowrap="" width="50" bgcolor="#CFCFCF">Line 3</td>
|
||||
<td width="25">20</td>
|
||||
<td width="25">21</td>
|
||||
<td width="25">22</td>
|
||||
<td width="25">23</td>
|
||||
<td width="25">24</td>
|
||||
<td width="25">25</td>
|
||||
<td width="25">26</td>
|
||||
<td width="25">27</td>
|
||||
<td width="25">28</td>
|
||||
<td width="25">29</td>
|
||||
<td width="25">30</td>
|
||||
<td width="25">31</td>
|
||||
<td width="25">32</td>
|
||||
<td width="25">33</td>
|
||||
<td width="25">34</td>
|
||||
<td width="25">35</td>
|
||||
<td width="25">36</td>
|
||||
<td width="25">37</td>
|
||||
<td width="25">38</td>
|
||||
<td width="25">39</td>
|
||||
</tr>
|
||||
<tr nowrap="" align="center" bgcolor="#99CC66">
|
||||
<td nowrap="" width="50" bgcolor="#CFCFCF">Line 4</td>
|
||||
<td width="25">84</td>
|
||||
<td width="25">85</td>
|
||||
<td width="25">86</td>
|
||||
<td width="25">87</td>
|
||||
<td width="25">88</td>
|
||||
<td width="25">89</td>
|
||||
<td width="25">90</td>
|
||||
<td width="25">91</td>
|
||||
<td width="25">92</td>
|
||||
<td width="25">93</td>
|
||||
<td width="25">94</td>
|
||||
<td width="25">95</td>
|
||||
<td width="25">96</td>
|
||||
<td width="25">97</td>
|
||||
<td width="25">98</td>
|
||||
<td width="25">99</td>
|
||||
<td width="25">100</td>
|
||||
<td width="25">101</td>
|
||||
<td width="25">102</td>
|
||||
<td width="25">103</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p> </p>
|
||||
<p class="PlainText">On a standard 2 x 16 character display, the following command would move the
|
||||
cursor to the third column of the second line:</p><pre class="BScode" xml:space="preserve">
|
||||
LCDCMD 1, 128 + 66
|
||||
</pre>
|
||||
<p class="PlainText">The number 128 tells the LCD we wish to move the cursor and 66 is the location
|
||||
number of the desired position. Similarly, sending just 128 (128 + 0) would move
|
||||
the cursor to the first character of the first line (the upper left character if
|
||||
the display is at the home position).</p>
|
||||
<p class="PlainText">You may have noticed that the 2 x 16 display has many locations that are not
|
||||
visible; they are to the right of the edge of the screen. These locations (16 -
|
||||
39 and 80 to 103) become important for scrolling operations. For example, it is
|
||||
possible to move the cursor to location 16, print some text there and then issue
|
||||
a number of Scroll Left instructions (<span class="keyword_in_text">LCDCMD</span> 1, 24) to slowly scroll the
|
||||
text onto the display from right to left. If you did so, the DDRAM positions that
|
||||
were on the left of the screen would now be past the left edge of the screen. For
|
||||
example:</p><pre class="BScode" xml:space="preserve">
|
||||
LCDCMD 1, 24
|
||||
LCDCMD 1, 24
|
||||
</pre>
|
||||
<p class="PlainText">...would cause the screen to scroll to the left by two characters. At this point,
|
||||
the upper-left character in the display would actually be DDRAM location 2 and the
|
||||
lower-left character would be DDRAM location 66. Locations 0, 1, 64 and 65 would
|
||||
be off the left edge of the LCD and would no longer be visible. Some interesting
|
||||
effects can be achieved by taking advantage of this feature.</p>
|
||||
<p class="PlainText">The 4 x 20 LCD has a strange DDRAM map. The upper-right character is location
|
||||
19 and the next location, 20, appears as the first character of the third line.
|
||||
This strange mapping is due to constraints in the LCD controller and the
|
||||
manufacturers design, and unfortunately makes the scrolling features virtually
|
||||
useless on the 4 x 20 displays.</p>
|
||||
<p class="PlainText">Even though the LCD requires many pins to talk to it, only the Enable pin needs
|
||||
to remain dedicated to the LCD and all the other pins can be multiplexed (shared)
|
||||
with certain other devices (if wired carefully). In addition, the I/O pin connected
|
||||
to the LCD's R/W pin is only necessary if the <span class="keyword_in_text">LCDIN</span> command will be used
|
||||
in the application. If the <span class="keyword_in_text">LCDIN</span> command will not be used, LCD pin 5 (R/W
|
||||
pin) can be connected to ground and I/O pin 2 (shown above) may be left disconnected.
|
||||
I/O pin 2 will still be set to output mode for each <span class="keyword_in_text">LCDCMD</span> and <span class="keyword_in_text">LCDOUT</span>command executed, however.</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>
|
293
help/BasicStampHelp/Content/LanguageTopics/Commands/LCDIN.htm
Normal file
293
help/BasicStampHelp/Content/LanguageTopics/Commands/LCDIN.htm
Normal file
@ -0,0 +1,293 @@
|
||||
<?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>LCDIN</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">LCDIN</h1>
|
||||
<div class="ImagePlusCaption">
|
||||
<div class="Col2">
|
||||
<p>
|
||||
<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/LcdinEx.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">LCDIN Example</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: <span class="keyword_in_text">LCDIN</span> <![CDATA[ ]]><i>Pin</i>,<i> Command</i>, [<i>InputData</i>]</p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Receive data from an LCD display.
|
||||
|
||||
</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Pin</i></b> is a variable/constant/expression (0 - 1 or 8 - 9) that
|
||||
specifies which I/O pins to use. The LCD requires, at most, seven I/O pins to
|
||||
operate. The <i>Pin</i> argument serves a double purpose; specifying the first
|
||||
pin and, indirectly, the group of other required pins. See explanation below.
|
||||
All I/O pins will be set to output mode initially and the upper I/O pins (4 -
|
||||
7 or 12 - 15) will be set to input mode by the end of the <span class="keyword_in_text">LCDIN</span> command.</li>
|
||||
<li value="2"><b><i>Command</i></b> is a variable/constant/expression (0 - 255) indicating
|
||||
the LCD command to send.</li>
|
||||
<li value="3"><b><i>InputData</i></b> is a list of variables and formatters that tells
|
||||
<span class="keyword_in_text">LCDIN</span> what to do with incoming data. <span class="keyword_in_text">LCDIN</span> can store data in a
|
||||
variable or array, interpret numeric text (decimal, binary, or hex) and store
|
||||
the corresponding value in a variable, wait for a fixed or variable sequence
|
||||
of bytes, or ignore a specified number of bytes. These actions can be combined
|
||||
in any order in the <i>InputData</i> list.</li>
|
||||
</ul>
|
||||
<h2>Quick Facts</h2>
|
||||
<table cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF">
|
||||
<td width="275" align="center"> </td>
|
||||
<td width="1200" align="center">BS2p, BS2pe, and BS2px</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Values for <i>Pin</i></td>
|
||||
<td align="center">0, 1, 8, or 9</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">I/O pin arrangement when<br></br><i>Pin</i> is
|
||||
0 or 1</td>
|
||||
<td>0 or 1 (depending on <i>Pin</i>) : LCD Enable (E) pin<br></br> 2 : LCD Read/Write (R/W) pin<br></br> 3 : LCD Register Select (RS) pin<br></br> 4 - 7 : LCD Data Bus (DB4 - DB7, respectively) pins</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">I/O pin arrangement when<br></br><i>Pin</i> is
|
||||
8 or 9</td>
|
||||
<td>8 or 9 (depending on <i>Pin</i>) : LCD Enable (E) pin<br></br> 10 : LCD Read/Write (R/W) pin<br></br> 11 : LCD Register Select (RS) pin<br></br> 12 - 15 : LCD Data Bus (DB4 - DB7, respectively) pins</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Special Notes</td>
|
||||
<td align="center" colspan="1"><span class="keyword_in_text">LCDIN </span>is designed to use the LCD's 4-bit mode only.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
||||
<td align="center" colspan="1">
|
||||
<p colspan="1" align="center"><a href="LCDCMD.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">LCDCMD</a>, <a href="LCDOUT.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">LCDOUT</a></p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText">The three LCD commands (<span class="keyword_in_text">LCDCMD</span>, <span class="keyword_in_text">LCDIN</span> and <span class="keyword_in_text">LCDOUT</span>) allow the
|
||||
BS2p, BS2pe, or BS2pe to interface directly to standard LCD displays that feature
|
||||
a Hitachi 44780 controller (part #HD44780A). This includes many 1 x 16, 2 x 16,
|
||||
and 4 x 20 character LCD displays. Note that <span class="keyword_in_text">LCDCMD</span>, <span class="keyword_in_text">LCDIN</span> and
|
||||
<span class="keyword_in_text">LCDOUT</span> use a 4-bit interface to the LCD which requires a specific
|
||||
initialization sequence before <span class="keyword_in_text">LCDIN</span> and <span class="keyword_in_text">LCDOUT</span> can be used
|
||||
(see <a href="LCDCMD.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">LCDCMD</a> for initialization details).</p>
|
||||
<p class="PlainText">The <span class="keyword_in_text">LCDIN</span> command is used to send one instruction and then receive at
|
||||
least one data byte from the LCD's Character Generator RAM (CGRAM) or Display Data
|
||||
RAM (DDRAM). The following is an example of the <span class="keyword_in_text">LCDIN</span> command:</p><pre class="BScode" xml:space="preserve">
|
||||
char VAR Byte
|
||||
|
||||
Main:
|
||||
LCDIN 1, 128, [char]
|
||||
STOP
|
||||
</pre>
|
||||
<p class="PlainText">The preceding example will read the character value at location 0 of the DDRAM.
|
||||
See the "Character Positioning" section, below, for more information.</p>
|
||||
<p class="PlainText">The <span class="keyword_in_text">LCDIN</span> command actually uses more than just the I/O pin specified by
|
||||
the <i>Pin</i> argument. The <span class="keyword_in_text">LCDIN</span> command requires seven I/O pins. This
|
||||
is because the standard LCD displays have a parallel interface, rather than a
|
||||
serial one. The <i>Pin</i> argument can be the numbers 0, 1, 8, or 9 and will
|
||||
result in the use of the I/O pins shown above. Please refer to the
|
||||
<a href="LCDCMD.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">LCDCMD</a> command description for information on properly
|
||||
wiring the LCD display.</p>
|
||||
<p class="PlainText">When the LCD is first powered-up, it will be in an unknown state and must be
|
||||
properly configured before sending commands like the one shown above. This process
|
||||
is known as initializing the LCD and is the first thing your program should do
|
||||
upon starting up. Please refer to the <a href="LCDCMD.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">LCDCMD</a> command
|
||||
description for information on properly initializing the LCD display. </p>
|
||||
<p class="PlainText">The <span class="keyword_in_text">LCDIN</span> command's <i>InputData</i> argument is similar to the <span class="keyword_in_text">SERIN</span> command's <i>InputData</i> argument. This means data can be received as ASCII
|
||||
character values, decimal, hexadecimal and binary translations and string data as
|
||||
in the examples below (assume the LCD display has "Value: 3A:101" starting at the
|
||||
first character of the first line on the screen).</p><pre class="BScode" xml:space="preserve">
|
||||
value VAR Byte(13)
|
||||
|
||||
Main:
|
||||
LCDIN 1, 128, [value] ' receive ASCII code for "V"
|
||||
LCDIN 1, 128, [DEC value] ' receive the number 3
|
||||
LCDIN 1, 128, [HEX value] ' receive the number $3A
|
||||
LCDIN 1, 128, [BIN value] ' receive the number %101
|
||||
LCDIN 1, 128, [STR value\13] ' receive the string "Value: 3A:101"
|
||||
</pre>
|
||||
<p class="PlainText">The tables below list all the available conversion formatters and special
|
||||
formatters available to the <span class="keyword_in_text">LCDIN</span> command. See the
|
||||
<a href="SERIN.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">SERIN</a> command for additional information and examples
|
||||
of their use.</p>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF" align="center" valign="top">
|
||||
<td width="15%">Conversion Formatter</td>
|
||||
<td width="45%">Type of Number</td>
|
||||
<td width="30%">Numeric Characters Accepted</td>
|
||||
<td width="10%">Notes</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>DEC{1..5}</td>
|
||||
<td>Decimal, optionally limited to 1 - 5 digits</td>
|
||||
<td>0 through 9</td>
|
||||
<td>1</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>SDEC{1..5}</td>
|
||||
<td>Signed decimal, optionally limited to 1 - 5 digits</td>
|
||||
<td>-, 0 through 9</td>
|
||||
<td>1,2</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>HEX{1..4}</td>
|
||||
<td>Hexadecimal, optionally limited to 1 - 4 digits</td>
|
||||
<td>0 through 9, A through F</td>
|
||||
<td>1,3</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>SHEX{1..4}</td>
|
||||
<td>Signed hexadecimal, optionally limited to 1 - 4 digits </td>
|
||||
<td>-, 0 through 9, A through F</td>
|
||||
<td>1,2,3</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>IHEX{1..4}</td>
|
||||
<td>Indicated hexadecimal, optionally limited to 1 - 4 digits</td>
|
||||
<td>$, 0 through 9, A through F</td>
|
||||
<td>1,3,4</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>ISHEX{1..4}</td>
|
||||
<td>Signed, indicated hexadecimal, optionally limited to 1 - 4 digits</td>
|
||||
<td>-, $, 0 through 9, A through F</td>
|
||||
<td>1,2,3,4</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>BIN{1..16}</td>
|
||||
<td>Binary, optionally limited to 1 - 16 digits</td>
|
||||
<td>0, 1</td>
|
||||
<td>1</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>SBIN{1..16}</td>
|
||||
<td>Signed binary, optionally limited to 1 - 16 digits</td>
|
||||
<td>-, 0, 1</td>
|
||||
<td>1,2</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>IBIN{1..16}</td>
|
||||
<td>Indicated binary, optionally limited to 1 - 16 digits</td>
|
||||
<td>%, 0, 1</td>
|
||||
<td>1,4</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>ISBIN{1..16}</td>
|
||||
<td>Signed, indicated binary, optionally limited to 1 - 16 digits</td>
|
||||
<td>-, %, 0, 1</td>
|
||||
<td>1,2,4</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>NUM</td>
|
||||
<td>Generic numeric input; hex or binary number must be indicated</td>
|
||||
<td>$, %, 0 through 9, A through F</td>
|
||||
<td>1,3,4</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>SNUM</td>
|
||||
<td>Similar to NUM with value treated as signed with range -32768 to +32767</td>
|
||||
<td>-, $, %, 0 through 9, A through F</td>
|
||||
<td>1,2,3,4</td>
|
||||
</tr>
|
||||
</table>
|
||||
<ol>
|
||||
<li value="1">All numeric conversions will continue to accept new data until receiving
|
||||
either the specified number of digits (ex: three digits for DEC3) or a
|
||||
non-numeric character.</li>
|
||||
<li value="2">To be recognized as part of a number, the minus sign (-) must immediately
|
||||
precede a numeric character. The minus sign character occurring in non-numeric
|
||||
text is ignored and any character (including a space) between a minus and a
|
||||
number causes the minus to be ignored.</li>
|
||||
<li value="3">The hexadecimal formatters are not case-sensitive; "a" through "f" means
|
||||
the same as "A" through "F".</li>
|
||||
<li value="4">Indicated hexadecimal and binary formatters ignore all characters, even
|
||||
valid numerics, until they receive the appropriate prefix ($ for hexadecimal,
|
||||
% for binary). The indicated formatters can differentiate between text and
|
||||
hexadecimal (ex: ABC would be interpreted by HEX as a number but IHEX would
|
||||
ignore it unless expressed as $ABC). Likewise, the binary version can
|
||||
distinguish the decimal number 10 from the binary number %10. A prefix
|
||||
occurring in non-numeric text is ignored, and any character (including a
|
||||
space) between a prefix and a number causes the prefix to be ignored. Indicated,
|
||||
signed formatters require that the minus sign come before the prefix, as
|
||||
in -$1B45.</li>
|
||||
</ol>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF" align="center" valign="top">
|
||||
<td width="20%">Special Formatter</td>
|
||||
<td width="80%">Action</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">STR ByteArray \L {\E}</td>
|
||||
<td>Input a character string of length L into an array. If specified, an end
|
||||
character E causes the string input to end before reaching length L.
|
||||
Remaining bytes are filled with 0s (zeros).</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">WAITSTR ByteArray {\L}</td>
|
||||
<td>Wait for a sequence of bytes matching a string stored in an array
|
||||
variable, optionally limited to L characters. If the optional L argument is
|
||||
left off, the end of the array-string must be marked by a byte containing a
|
||||
zero (0).</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">SKIP Length</td>
|
||||
<td>Ignore Length bytes of characters.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">SPSTR Length</td>
|
||||
<td>Buffer Length bytes (up to 126) of serial characters to Scratchpad RAM,
|
||||
starting at location 0. Use <a href="GET.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">GET</a> to retrieve the
|
||||
characters.</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p> </p>
|
||||
<p class="PlainText">Some possible uses of the <span class="keyword_in_text">LCDIN</span> command are 1) in combination with the
|
||||
<span class="keyword_in_text">LCDOUT</span> command to store and read data from the unused DDRAM or CGRAM
|
||||
locations (as extra variable space), 2) to verify that the data from a previous
|
||||
<span class="keyword_in_text">LCDOUT</span> command was received and processed properly by the LCD, and 3) to
|
||||
read character data from CGRAM for the purposes of modifying it and storing it
|
||||
as a custom character.</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>
|
309
help/BasicStampHelp/Content/LanguageTopics/Commands/LCDOUT.htm
Normal file
309
help/BasicStampHelp/Content/LanguageTopics/Commands/LCDOUT.htm
Normal file
@ -0,0 +1,309 @@
|
||||
<?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>LCDOUT</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">LCDOUT</h1>
|
||||
<div class="ImagePlusCaption">
|
||||
<div class="Col2">
|
||||
<p>
|
||||
<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/LcdoutEx.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">LCDOUT Example</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: <span class="keyword_in_text">LCDOUT</span> <![CDATA[ ]]><i>Pin</i>,<i> Command</i>, [<i>OutputData</i>]</p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Send data to an LCD display.
|
||||
|
||||
</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Pin</i></b> is a variable/constant/expression (0 - 1 or 8 - 9) that
|
||||
specifies which I/O pins to use. The LCD requires, at most, seven I/O pins
|
||||
to operate. The <i>Pin</i> argument serves a double purpose; specifying the
|
||||
first pin and, indirectly, the group of other required pins. See explanation
|
||||
below. All I/O pins will be set to output mode initially and the upper I/O
|
||||
pins (4 - 7 or 12 - 15) will be set to output mode by the end of the <span class="keyword_in_text">LCDOUT</span> command.</li>
|
||||
<li value="2"><b><i>Command</i></b> is a variable/constant/expression (0 - 255) indicating
|
||||
an LCD command to send.</li>
|
||||
<li value="3"><b><i>OutputData</i></b> is a list of variables, constants, expressions and
|
||||
formatters that tells <span class="keyword_in_text">LCDOUT</span> how to format outgoing data. <span class="keyword_in_text">LCDOUT</span>
|
||||
can transmit individual or repeating bytes, convert values into decimal, hex
|
||||
or binary text representations, or transmit strings of bytes from variable
|
||||
arrays. These actions can be combined in any order in the <i>OutputData</i>list.</li>
|
||||
</ul>
|
||||
<h2>Quick Facts</h2>
|
||||
<table cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF">
|
||||
<td width="275" align="center"> </td>
|
||||
<td width="1200" align="center">BS2p, BS2pe, and BS2px</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Values for <i>Pin</i></td>
|
||||
<td align="center">0, 1, 8, or 9</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">I/O pin arrangement when<br></br><i>Pin</i> is
|
||||
0 or 1</td>
|
||||
<td>0 or 1 (depending on <i>Pin</i>) : LCD Enable (E) pin<br></br> 2 : LCD Read/Write (R/W) pin<br></br> 3 : LCD Register Select (RS) pin<br></br> 4 - 7 : LCD Data Bus (DB4 - DB7, respectively) pins</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">I/O pin arrangement when<br></br><i>Pin</i> is
|
||||
8 or 9</td>
|
||||
<td>8 or 9 (depending on <i>Pin</i>) : LCD Enable (E) pin<br></br> 10 : LCD Read/Write (R/W) pin<br></br> 11 : LCD Register Select (RS) pin<br></br> 12 - 15 : LCD Data Bus (DB4 - DB7, respectively) pins</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
||||
<td align="center" colspan="1">
|
||||
<p colspan="1" align="center"><a href="LCDCMD.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">LCDCMD</a>, <a href="LCDIN.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">LCDIN</a></p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText">The three LCD commands (<span class="keyword_in_text">LCDCMD</span>, <span class="keyword_in_text">LCDIN</span> and <span class="keyword_in_text">LCDOUT</span>) allow the
|
||||
BS2p, BS2pe, or BS2pe to interface directly to standard LCD displays that feature
|
||||
a Hitachi 44780 controller (part #HD44780A). This includes many 1 x 16, 2 x 16,
|
||||
and 4 x 20 character LCD displays. Note that <span class="keyword_in_text">LCDCMD</span>, <span class="keyword_in_text">LCDIN</span> and
|
||||
<span class="keyword_in_text">LCDOUT</span> use a 4-bit interface to the LCD which requires a specific
|
||||
initialization sequence before <span class="keyword_in_text">LCDIN</span> and <span class="keyword_in_text">LCDOUT</span> can be used
|
||||
(see <a href="LCDCMD.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">LCDCMD</a> for initialization details).</p>
|
||||
<p class="PlainText">The <span class="keyword_in_text">LCDOUT</span> command is used to send one instruction followed by at least
|
||||
one data byte to the LCD. The data that is output is written to the LCD's
|
||||
Character Generator RAM (CGRAM) or Display Data RAM (DDRAM). The following is an
|
||||
example of the <span class="keyword_in_text">LCDOUT</span> command:</p><pre class="BScode" xml:space="preserve">
|
||||
LCDOUT 1, 1, ["Hello World!"]
|
||||
</pre>
|
||||
<p class="PlainText">The preceding example will clear the LCD screen and then send "Hello World!" to
|
||||
the screen. The first argument (1) is the starting I/O pin number and the second
|
||||
argument (also 1) is the LCD's instruction for Clear Screen.</p>
|
||||
<p class="PlainText">The <span class="keyword_in_text">LCDOUT</span> command actually uses more than just the I/O pin specified
|
||||
by the <i>Pin</i> argument. The LCDOUT command requires seven I/O pins. This is
|
||||
because the standard LCD displays have a parallel interface, rather than a serial
|
||||
one. The <i>Pin</i> argument can be the numbers 0, 1, 8, or 9 and will result in
|
||||
the use of the I/O pins shown above. Please refer to the
|
||||
<a href="LCDCMD.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">LCDCMD</a> command description for information on properly
|
||||
wiring the LCD display.</p>
|
||||
<p class="PlainText">When the LCD is first powered-up, it will be in an unknown state and must be
|
||||
properly configured before sending commands like the one shown above. This process
|
||||
is known as initializing the LCD and is the first thing your program should do
|
||||
upon starting up. Please refer to the <a href="LCDCMD.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">LCDCMD</a> command
|
||||
description for information on properly initializing the LCD display.</p>
|
||||
<p class="PlainText">The <span class="keyword_in_text">LCDOUT</span> command's <i>OutputData</i> argument is exactly like that
|
||||
of the <span class="keyword_in_text">DEBUG</span> and <span class="keyword_in_text">SEROUT</span> command's <i>OutputData</i> argument.
|
||||
This means data can be sent as literal text, ASCII character values, repetitive
|
||||
values, decimal, hexadecimal and binary translations and string data as in the
|
||||
examples below.</p><pre class="BScode" xml:space="preserve">
|
||||
value VAR Byte
|
||||
|
||||
Setup:
|
||||
value = 65
|
||||
|
||||
Main:
|
||||
LCDOUT 1, 0, [value] ' send ASCII character "A"
|
||||
LCDOUT 1, 0, [REP value\5] ' send "AAAAA"
|
||||
LCDOUT 1, 0, [DEC value] ' send "6" and "5"
|
||||
LCDOUT 1, 0, [HEX value] ' send "4" and "1"
|
||||
LCDOUT 1, 0, [BIN value] ' send "1000001"
|
||||
STOP
|
||||
</pre>
|
||||
<p class="PlainText">The tables below list all the available conversion formatters and special
|
||||
formatters available to the <span class="keyword_in_text">LCDOUT</span> command. See the
|
||||
<a href="DEBUG.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">DEBUG</a> and <a href="SEROUT.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">SEROUT</a> commands for
|
||||
additional information and examples of their use.</p>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF" align="center" valign="top">
|
||||
<td width="20%">Conversion Formatter</td>
|
||||
<td width="70%">Type of Number</td>
|
||||
<td width="10%">Notes</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>DEC{1..5}</td>
|
||||
<td align="left">Decimal, optionally fixed to 1 - 5 digits</td>
|
||||
<td>1</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>SDEC{1..5}</td>
|
||||
<td align="left">Signed decimal, optionally fixed to 1 - 5 digits</td>
|
||||
<td>1,2</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>HEX{1..4}</td>
|
||||
<td align="left">Hexadecimal, optionally fixed to 1 - 4 digits</td>
|
||||
<td>1</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>SHEX{1..4}</td>
|
||||
<td align="left">Signed hexadecimal, optionally fixed to 1 - 4 digits </td>
|
||||
<td>1,2</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>IHEX{1..4}</td>
|
||||
<td align="left">Indicated hexadecimal, optionally fixed to 1 - 4 digits</td>
|
||||
<td>1</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>ISHEX{1..4}</td>
|
||||
<td align="left">Signed, indicated hexadecimal, optionally fixed to 1 - 4
|
||||
digits ($ prefix)</td>
|
||||
<td>1,2</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>BIN{1..16}</td>
|
||||
<td align="left">Binary, optionally fixed to 1 - 16 digits</td>
|
||||
<td>1</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>SBIN{1..16}</td>
|
||||
<td align="left">Signed binary, optionally fixed to 1 - 16 digits</td>
|
||||
<td>1,2</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>IBIN{1..16}</td>
|
||||
<td align="left">Indicated binary, optionally fixed to 1 - 16 digits</td>
|
||||
<td>1</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>ISBIN{1..16}</td>
|
||||
<td align="left">Signed, indicated binary, optionally fixed to 1 - 16 digits</td>
|
||||
<td>1,2</td>
|
||||
</tr>
|
||||
</table>
|
||||
<ol>
|
||||
<li value="1">Fixed-digit formatters like DEC4 will pad the number with leading 0s if
|
||||
necessary; ex: DEC4 65 sends 0065. If a number is larger than the specified
|
||||
number of digits, the leading digits will be dropped; ex: DEC4 56422 sends
|
||||
6422.</li>
|
||||
<li value="2">Signed modifiers work under two's complement rules.</li>
|
||||
</ol>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF" align="center" valign="top">
|
||||
<td width="20%">Special Formatter</td>
|
||||
<td width="80%">Action</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">?</td>
|
||||
<td>Displays "symbol = x' + carriage return; where x is a number. Default
|
||||
format is decimal, but may be combined with conversion formatters (ex: BIN
|
||||
? x to display "x = binary_number").</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">ASC ?</td>
|
||||
<td>Displays "symbol = 'x'" + carriage return; where x is an ASCII character.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">STR ByteArray {\L}</td>
|
||||
<td>Send character string from an array. The optional \L argument can be used
|
||||
to limit the output to L characters, otherwise, characters will be sent up
|
||||
to the first byte equal to 0 or the end of RAM space is reached.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">REP Byte\L</td>
|
||||
<td>Send a string consisting of Byte repeated L times (ex: REP "X"\10 sends
|
||||
"XXXXXXXXXX").</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h3>Using the <i>Command</i> Argument</h3>
|
||||
<p class="PlainText">The <i>Command</i> argument is useful for proceeding a set of data with a
|
||||
special LCD instruction. For example, the code below will move the cursor to
|
||||
location 64 (the first character on the second line) and print "Hi":</p><pre class="BScode" xml:space="preserve">
|
||||
LCDOUT 1, 128 + 64, ["Hi"]
|
||||
</pre>
|
||||
<p class="PlainText">The next example, below, will turn on the blinking block cursor and print
|
||||
"Yo!":</p><pre class="BScode" xml:space="preserve">
|
||||
LCDOUT 1, 13, ["Yo!"]
|
||||
</pre>
|
||||
<p class="PlainText">Occasionally, you will want to send data without preceding it with a command.
|
||||
To do this, simply use 0 for the <i>Command</i> argument, as in:</p><pre class="BScode" xml:space="preserve">
|
||||
LCDOUT 1, 0, ["Hello there!"]
|
||||
</pre>
|
||||
<p class="PlainText">Another use for the <span class="keyword_in_text">LCDOUT</span> command is to access and create custom
|
||||
characters. The Hitachi 44780 controller has a built-in character set that is
|
||||
similar to the ASCII character set (at least for the first 128 characters).
|
||||
Most of these characters are stored in ROM and are not changeable, however, the
|
||||
first eight characters (ASCII 0 though 7) are programmable.</p>
|
||||
<p class="PlainText">Each of the programmable characters is five pixels wide and eight pixels tall.
|
||||
It takes eight bytes to describe each character; one byte per row (the left-most
|
||||
three bits are ignored). For example, the character at ASCII location 0 is defined
|
||||
by the bit patterns stored in bytes 0 through 7 of Character Generator RAM (CGRAM).
|
||||
The character at ASCII location 1 is defined by the bit patterns stored in bytes
|
||||
8 through 15 of CGRAM, and so on.</p>
|
||||
<p class="PlainText">To create a custom character, use some graph paper to plot out the bit pattern
|
||||
(on and off pixels) in a 5 x 8 pattern, as shown in below. Then calculate the
|
||||
corresponding binary value of the bit pattern for each of the eight rows of
|
||||
character data.</p>
|
||||
<center>
|
||||
<table border="0">
|
||||
<tr>
|
||||
<td align="center"><b>Character Cell Structure and Data</b>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<img src="../../graphics/lcd_char.gif" border="0">
|
||||
</img>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</center>
|
||||
<p class="PlainText">After the data is calculated for each character (8 byte values per character),
|
||||
use the <span class="keyword_in_text">LCDOUT</span> command with the "Move To CGRAM Address" instruction to
|
||||
insert the data into the character's CGRAM locations. For example, the code
|
||||
below will store the character shown in above into character 0's CGRAM data
|
||||
locations. Then it will place the cursor back on the display (DDRAM) and print
|
||||
the character on the screen.</p><pre class="BScode" xml:space="preserve">
|
||||
LCDOUT 1, 64+0, [00, 10, 10, 00, 17, 14, 06, 00]
|
||||
LCDOUT 1, 128+0, ["Custom Char: ", 0]
|
||||
</pre>
|
||||
<p class="PlainText">The number 64 in the <i>Command</i> argument is the LCD's "Move to CGRAM Address"
|
||||
instruction and the 0 that is added to it is the location of the first row of data
|
||||
for the character 0. The <span class="keyword_in_text">LCDOUT</span> command will write the first <i>OutputData</i>
|
||||
value (00) to this location, the second <i>OutputData</i> value (10) to location 1,
|
||||
etc. If we wanted this custom character to affect character 1, instead of 0, we'd
|
||||
have to adjust value of the "Move To..." command, i.e., 64+8. To affect character 2,
|
||||
we'd use 64+16.</p>
|
||||
<p class="PlainText">To try the example above, don't forget to execute the LCD initialization code
|
||||
(shown in the <a href="LCDCMD.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">LCDCMD</a> description) first and never forget
|
||||
to move the cursor back to the screen (as with the last command, above) when you're
|
||||
done writing the character data to CGRAM.</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>
|
86
help/BasicStampHelp/Content/LanguageTopics/Commands/LET.htm
Normal file
86
help/BasicStampHelp/Content/LanguageTopics/Commands/LET.htm
Normal file
@ -0,0 +1,86 @@
|
||||
<?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>LET</title>
|
||||
<link href="../../Resources/Stylesheets/BSE_Help.css" rel="stylesheet" />
|
||||
<script src="../../SkinSupport/MadCapAll.js" type="text/javascript">
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<h1 class="code">LET</h1>
|
||||
<div class="ImagePlusCaption">
|
||||
<div class="Col2">
|
||||
<p>
|
||||
<img src="../../graphics/pgm_icon1.gif" border="0" alt="BS1 icon" title="BS1 icon" />
|
||||
</p>
|
||||
</div>
|
||||
<p style="text-align: right;"> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: {<span class="keyword_in_text">LET</span>}<i>Variable </i>=<i> Value</i></p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Sets <i>Variable</i> equal to the value of <i>Value</i>.
|
||||
|
||||
</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Variable</i></b> is a variable/constant/expression (0-65535).</li>
|
||||
<li value="2"><b><i>Value</i></b> is a variable which will be set equal to <i>Value</i>. </li>
|
||||
</ul>
|
||||
<h2>Explanation<br /></h2>
|
||||
<p class="PlainText"><span class="keyword_in_text">LET</span> is an optional instruction for the BASIC Stamp 1 that can be used with variable assignment statements, such as A = 5 and B = A + 2, etc. This instruction is not required and only exits on the BASIC Stamp 1. <span class="keyword_in_text">LET</span> was a commonly used command in early forms of BASIC, and was originally included in the BS1 command set to accommodate programmers from that generation. Parallax recommends that all new BASIC Stamp 1 programs use assignment statements without the <span class="keyword_in_text">LET</span> command.</p>
|
||||
<p class="PlainText">The example below demonstrates the use of <span class="keyword_in_text">LET</span> in assignment statements. Note that the Lunchtime and Dinnertime routines do essentially the same type of thing, but the Dinnertime approach is recommended.</p><pre class="BScode" xml:space="preserve">' {$STAMP BS1}
|
||||
' {$PBASIC 1.0}
|
||||
' {$STAMP BS1}
|
||||
|
||||
SYMBOL salad = B1
|
||||
SYMBOL bread = B2
|
||||
SYMBOL soup = B3
|
||||
SYMBOL lunch = B4
|
||||
SYMBOL dinner = B5
|
||||
|
||||
Lunchtime:
|
||||
LET salad = 3
|
||||
LET bread = 1
|
||||
LET soup = 4
|
||||
lunch = salad + bread + soup
|
||||
DEBUG "Lunch = $", #lunch, "plus local tax.", CR
|
||||
|
||||
Dinnertime:
|
||||
salad = 4
|
||||
bread = 2
|
||||
soup = 5
|
||||
dinner = salad + bread + soup
|
||||
DEBUG "Dinner = $",#dinner, "plus local tax.", CR
|
||||
</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>
|
401
help/BasicStampHelp/Content/LanguageTopics/Commands/LOOKDOWN.htm
Normal file
401
help/BasicStampHelp/Content/LanguageTopics/Commands/LOOKDOWN.htm
Normal file
@ -0,0 +1,401 @@
|
||||
<?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>LOOKDOWN</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">LOOKDOWN</h1>
|
||||
<div class="ImagePlusCaption">
|
||||
<div class="Col2">
|
||||
<p>
|
||||
<img src="../../graphics/pgm_icon1.gif" border="0" alt="BS1 icon" title="BS1 icon" />
|
||||
<img src="../../graphics/pgm_icon2.gif" border="0" alt="BS2 icon" title="BS2 icon" />
|
||||
<img src="../../graphics/pgm_icon2e.gif" border="0" alt="BS2e icon" title="BS2e icon" />
|
||||
<img src="../../graphics/pgm_icon2sx.gif" border="0" alt="BS2sx icon" title="BS2sx icon" />
|
||||
<img src="../../graphics/pgm_icon2p.gif" border="0" alt="BS2p icon" title="BS2p icon" />
|
||||
<img src="../../graphics/pgm_icon2pe.gif" border="0" alt="BS2pe icon" title="BS2pe icon" />
|
||||
<img src="../../graphics/pgm_icon2px.gif" border="0" alt="BS2px icon" title="BS2px icon" />
|
||||
</p>
|
||||
</div>
|
||||
<p style="text-align: right;"><a href="../ExampleTopics/LookdownEx.htm" target="" title="" alt="" class="MCXref_0">LOOKDOWN Examples</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax <img align="absmiddle" src="../../graphics/mini_1.gif" /> :
|
||||
<span class="keyword_in_text">LOOKDOWN</span><i>Target</i>, (<i>Value0, Value1</i>, ...<i>ValueN </i>),<i> Variable</i><br />Syntax <img align="absmiddle" src="../../graphics/mini_2.gif" /> :
|
||||
<span class="keyword_in_text">LOOKDOWN</span> <![CDATA[ ]]><i>Target</i>, {<i>ComparisonOp</i>} [<i>Value0</i>,<i> Value1</i>,
|
||||
...<i>ValueN</i>],<i> Variable</i></p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Compare <i>Target</i> value to a list of values and store the index number of
|
||||
the first value that matches into <i>Variable</i>. If no value in the list matches,
|
||||
<i>Variable</i> is left unaffected. On the BS2, BS2e, BS2sx and BS2p, the optional
|
||||
<i>ComparisonOp</i> is used as criteria for the match; the default criteria is
|
||||
"equal to."
|
||||
|
||||
</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Target</i></b> is a variable/constant/expression* (0 - 65535) to be
|
||||
compared to the values in the list. </li>
|
||||
<li value="2"><b><i>ComparisonOp</i></b> is an optional comparison operator (as described
|
||||
below) to be used as the criteria when comparing values. When no
|
||||
<i>ComparisonOp</i> is specified, equal to (=) is assumed. This argument is
|
||||
not available on the BS1.</li>
|
||||
<li value="3"><b><i>Values</i></b> are variables/constants/expressions* (0 - 65535) to
|
||||
be compared to <i>Target</i>.</li>
|
||||
<li value="4"><b><i>Variable</i></b> is a variable (usually a byte) that will be set to
|
||||
the index (0 - 255) of the matching value in the <i>Values</i> list. If no
|
||||
matching value is found, <i>Variable</i> is left unaffected. </li>
|
||||
</ul>
|
||||
<p class="PlainText">*<img src="../../graphics/bs1note.gif" style="vertical-align: super;" /> Note: expressions are not allowed as arguments on the BS1.</p>
|
||||
<h2>Quick Facts</h2>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr>
|
||||
<td width="20%" align="center" bgcolor="#CFCFCF"> </td>
|
||||
<td width="80%" align="center" bgcolor="#CFCFCF">All BASIC Stamp Modules</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Limit of value entries</td>
|
||||
<td align="center">256</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Starting index number</td>
|
||||
<td align="center">0</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">If value list contains no match...</td>
|
||||
<td align="center"><i>Variable</i> is left unaffected</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Command</td>
|
||||
<td align="center" colspan="1">
|
||||
<p colspan="1" align="center"><a href="LOOKUP.htm" target="" title="" alt="" class="MCXref_0">LOOKUP</a>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText"><span class="keyword_in_text">LOOKDOWN</span> works like the index in a book. In an index, you search for a
|
||||
topic and get the page number. <span class="keyword_in_text">LOOKDOWN</span> searches for a target value in
|
||||
a list, and stores the index number of the first match in a variable. For
|
||||
example: </p>
|
||||
<p>
|
||||
<img src="../../graphics/bs1_inline.gif" border="0">
|
||||
</img>
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
SYMBOL value = B2
|
||||
SYMBOL result = B3
|
||||
|
||||
Setup:
|
||||
value = 17
|
||||
result = 15
|
||||
|
||||
Main:
|
||||
LOOKDOWN value, (26, 177, 13, 1, 0, 17, 99), result
|
||||
DEBUG "Value matches item ", #result, "in list"
|
||||
END
|
||||
</pre>
|
||||
<p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0">
|
||||
</img>
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
value VAR Byte
|
||||
result VAR Byte
|
||||
|
||||
Setup:
|
||||
value = 17
|
||||
result = 15
|
||||
|
||||
Main:
|
||||
LOOKDOWN value, [26, 177, 13, 1, 0, 17, 99], result
|
||||
DEBUG "Value matches item ", DEC result, " in list"
|
||||
END
|
||||
</pre>
|
||||
<p class="PlainText"><span class="keyword_in_text">DEBUG</span> prints, "Value matches item 5 in list" because the value (17)
|
||||
matches item 5 of [26, 177, 13, 1, 0, 17, 99]. Note that index numbers count up
|
||||
from 0, not 1; that is, in this list, 26 is item 0.</p>
|
||||
<p class="PlainText">What happens if the value doesn't match any of the items in the list? Try
|
||||
changing "<span class="code_in_text">value = 17</span>" to "<span class="code_in_text">value = 2.</span>" Since 2 is not on the list, <span class="keyword_in_text">LOOKDOWN</span>
|
||||
leaves <span class="code_in_text">result </span>unaffected. Since <span class="code_in_text">result </span>contained 15 before <span class="keyword_in_text">LOOKDOWN</span>
|
||||
executed, <span class="keyword_in_text">DEBUG</span> prints "Value matches item 15 in list." By strategically
|
||||
setting the initial value of <span class="code_in_text">result</span>, as we have here, your program can be written
|
||||
to detect when an item was not found in the list. </p>
|
||||
<p class="PlainText">Don't forget that text phrases are just lists of byte values, so they too are
|
||||
eligible for <span class="keyword_in_text">LOOKDOWN</span> searches, as in this example:</p>
|
||||
<p>
|
||||
<img src="../../graphics/bs1_inline.gif" border="0">
|
||||
</img>
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
SYMBOL value = B2
|
||||
SYMBOL result = B3
|
||||
|
||||
Setup:
|
||||
value = "f"
|
||||
result = 255
|
||||
|
||||
Main:
|
||||
LOOKDOWN value, ("The quick brown fox"), result
|
||||
DEBUG "Value matches item ", #result, "in list"
|
||||
END
|
||||
</pre>
|
||||
<p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0">
|
||||
</img>
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
value VAR Byte
|
||||
result VAR Byte
|
||||
|
||||
Setup:
|
||||
value = "f"
|
||||
result = 255
|
||||
|
||||
Main:
|
||||
LOOKDOWN value, ["The quick brown fox"], result
|
||||
DEBUG "Value matches item ", DEC result, " in list"
|
||||
END
|
||||
</pre>
|
||||
<p><span class="keyword_in_text">DEBUG</span> prints, "Value matches item 16 in list" because the character at
|
||||
index item 16 is "f" in the phrase, "The quick brown fox".</p>
|
||||
<p class="PlainText">The examples above show <span class="keyword_in_text">LOOKDOWN</span> working with lists of constants, but
|
||||
it also works with variables and expressions also. Note, however, that expressions
|
||||
are not allowed as argument on the BS1.</p>
|
||||
<p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0">
|
||||
</img>
|
||||
</p>
|
||||
<p class="PlainText">On the BS2, BS2e, BS2sx, BS2p and BS2pe, the <span class="keyword_in_text">LOOKDOWN</span> command can also
|
||||
use another criteria (other than "equal to") for its list. All of the examples
|
||||
above use <span class="keyword_in_text">LOOKDOWN</span>'s default comparison operator, =, that searches for an
|
||||
exact match. The entire list of <i>ComaprisonOps</i> is shown below. The
|
||||
"greater than" comparison operator (>) is used in the following example: </p><pre class="BScode" xml:space="preserve">
|
||||
value VAR Byte
|
||||
result VAR Byte
|
||||
|
||||
Setup:
|
||||
value = 17
|
||||
result = 15
|
||||
|
||||
Main:
|
||||
LOOKDOWN value, >[26, 177, 13, 1, 0, 17, 99], result
|
||||
DEBUG "Value greater than item ", DEC result, " in list"
|
||||
END
|
||||
</pre>
|
||||
<p class="PlainText"><span class="keyword_in_text">DEBUG</span> prints, "Value greater than item 2 in list" because the first
|
||||
item the value 17 is greater than is 13 (which is item 2 in the list). Value is
|
||||
also greater than items 3 and 4, but these are ignored, because <span class="keyword_in_text">LOOKDOWN</span>
|
||||
only cares about the first item that matches the criteria. This can require a
|
||||
certain amount of planning in devising the order of the list. To see a complete program, see the
|
||||
<a href="../ExampleTopics/LookdownEx.htm" target="" title="" alt="" class="MCXref_0">LOOKDOWN Examples</a>.</p>
|
||||
<p class="PlainText"><span class="keyword_in_text">LOOKDOWN</span> comparison operators use unsigned 16-bit math. They will not
|
||||
work correctly with signed numbers, which are represented internally as two's
|
||||
complement (large 16-bit integers). For example, the two's complement
|
||||
representation of -99 is 65437. So although -99 is certainly less than 0, it
|
||||
would appear to be larger than zero to the <span class="keyword_in_text">LOOKDOWN</span> comparison operators.
|
||||
The bottom line is: Don't used signed numbers with <span class="keyword_in_text">LOOKDOWN</span> comparisons.</p>
|
||||
<center>
|
||||
<table width="80%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr>
|
||||
<td width="25%" align="center" bgcolor="#CFCFCF">ComparisonOp Symbol</td>
|
||||
<td width="55%" align="center" bgcolor="#CFCFCF">Description</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">=</td>
|
||||
<td align="center">Find the first value Target is equal to</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><></td>
|
||||
<td align="center">Find the first value Target is not equal to</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">></td>
|
||||
<td align="center">Find the first value Target is greater than</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><</td>
|
||||
<td align="center">Find the first value Target is less than</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">>=</td>
|
||||
<td align="center">Find the first value Target is greater than or equal to</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><=</td>
|
||||
<td align="center">Find the first value Target is less than or equal to</td>
|
||||
</tr>
|
||||
</table>
|
||||
</center>
|
||||
<p> </p>
|
||||
<p class="PlainText">A common application for <span class="keyword_in_text">LOOKDOWN</span> is to use it in conjunction with the
|
||||
<span class="keyword_in_text">BRANCH</span> command to create selective jumps based on a simple variable input: </p>
|
||||
<p>
|
||||
<img src="../../graphics/bs1_inline.gif" border="0">
|
||||
</img>
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
SYMBOL cmd = B2
|
||||
|
||||
Setup:
|
||||
cmd = "M"
|
||||
|
||||
Main:
|
||||
LOOKDOWN cmd, ("SLMH"), cmd
|
||||
BRANCH cmd, (_Stop, _Low, _Medium, _High)
|
||||
DEBUG "Command not in list"
|
||||
END
|
||||
|
||||
_Stop:
|
||||
DEBUG "Stop"
|
||||
END
|
||||
|
||||
_Low:
|
||||
DEBUG "Low"
|
||||
END
|
||||
|
||||
_Medium:
|
||||
DEBUG "Medium"
|
||||
END
|
||||
|
||||
_High:
|
||||
DEBUG "High"
|
||||
END
|
||||
</pre>
|
||||
<p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0">
|
||||
</img>
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
cmd VAR Byte
|
||||
|
||||
Setup:
|
||||
cmd = "M"
|
||||
|
||||
Main:
|
||||
LOOKDOWN cmd, ["SLMH"], cmd
|
||||
BRANCH cmd, [_Stop, _Low, _Medium, _High]
|
||||
DEBUG "Command not in list"
|
||||
END
|
||||
|
||||
_Stop:
|
||||
DEBUG "Stop"
|
||||
END
|
||||
|
||||
_Low:
|
||||
DEBUG "Low"
|
||||
END
|
||||
|
||||
_Medium:
|
||||
DEBUG "Medium"
|
||||
END
|
||||
|
||||
_High:
|
||||
DEBUG "High"
|
||||
END
|
||||
</pre>
|
||||
<p class="PlainText">In this example, <span class="code_in_text">cmd </span>contains "M" (ASCII 77). <span class="keyword_in_text">LOOKDOWN</span> finds that this
|
||||
is item 2 of a list of one-character commands and stores 2 into <span class="code_in_text">cmd</span>. <span class="keyword_in_text">BRANCH</span>then goes to item 2 of its list, which is the program label "<span class="code_in_text">_Medium</span>" at which
|
||||
point <span class="keyword_in_text">DEBUG</span> prints "Medium" on the PC screen. This is a powerful method
|
||||
for interpreting user input, and a lot neater than the alternative <span class="keyword_in_text">IF...THEN</span>instructions. </p>
|
||||
<p class="PlainText">Another great use of <span class="keyword_in_text">LOOKDOWN</span> is in combination with <span class="keyword_in_text">LOOKUP</span> to
|
||||
"map" non-contiguous sets of numbers together. For example, you may have an
|
||||
application where certain numbers are received by the BASIC Stamp and, in response,
|
||||
the BASIC Stamp needs to send a specific set of numbers. This may be easy to code
|
||||
if the numbers are contiguous, or follow some known algebraic equation... but what
|
||||
if they don't? The table below shows some sample, non-contiguous inputs and the
|
||||
corresponding outputs the BASIC Stamp needs to respond with:</p>
|
||||
<center>
|
||||
<table width="60%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr>
|
||||
<td width="10%" align="center" bgcolor="#CFCFCF">Index</td>
|
||||
<td width="25%" align="center" bgcolor="#CFCFCF">Each of these values
|
||||
received (inputs):</td>
|
||||
<td width="25%" align="center" bgcolor="#CFCFCF">Needs to result in each of
|
||||
these values sent (outputs):</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">0</td>
|
||||
<td align="center">5</td>
|
||||
<td align="center">16</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">1</td>
|
||||
<td align="center">14</td>
|
||||
<td align="center">17</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">2</td>
|
||||
<td align="center">1</td>
|
||||
<td align="center">18</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">3</td>
|
||||
<td align="center">43</td>
|
||||
<td align="center">24</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">4</td>
|
||||
<td align="center">26</td>
|
||||
<td align="center">10</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">5</td>
|
||||
<td align="center">22</td>
|
||||
<td align="center">12</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">6</td>
|
||||
<td align="center">30</td>
|
||||
<td align="center">11</td>
|
||||
</tr>
|
||||
</table>
|
||||
</center>
|
||||
<p> </p>
|
||||
<p class="PlainText">So, if we receive the number 5, we need to output 16. If we received 43, we
|
||||
need to output 24, and so on. These numbers are not contiguous and they don't
|
||||
appear to be derived from any simple algorithm. We can solve this problem with
|
||||
two lines of code, as follows:</p><pre class="BScode" xml:space="preserve">
|
||||
LOOKDOWN value, [5, 14, 1, 43, 26, 22, 30], value
|
||||
LOOKUP value, [16, 17, 18, 24, 10, 12, 11], value
|
||||
</pre>
|
||||
<p class="PlainText">Assuming our received number is in value, the first line (<span class="keyword_in_text">LOOKDOWN</span>)
|
||||
will find the value in the list and store the index of the location that matches
|
||||
back into <span class="code_in_text">value</span>. (This step "maps" the non-contiguous numbers: 5, 14, 1, etc,
|
||||
to a contiguous set of numbers: 0, 1, 2, etc). The second line (<span class="keyword_in_text">LOOKUP</span>)
|
||||
takes our new value, finds the number at that location and stores it back into
|
||||
<span class="code_in_text">value</span>. If the received value was 14, <span class="keyword_in_text">LOOKDOWN</span> stores 1 into value and
|
||||
<span class="keyword_in_text">LOOKUP</span> looks at the value at location 1 and stores 17 in <span class="code_in_text">value</span>. The
|
||||
number 43 gets mapped to 3, 3 gets mapped to 24, and so on. This is a quick and
|
||||
easy fix for a potentially messy problem!</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>
|
255
help/BasicStampHelp/Content/LanguageTopics/Commands/LOOKUP.htm
Normal file
255
help/BasicStampHelp/Content/LanguageTopics/Commands/LOOKUP.htm
Normal file
@ -0,0 +1,255 @@
|
||||
<?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>LOOKUP</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">LOOKUP</h1>
|
||||
<div class="ImagePlusCaption">
|
||||
<div class="Col2">
|
||||
<p>
|
||||
<img src="../../graphics/pgm_icon1.gif" border="0" alt="BS1 icon" title="BS1 icon" />
|
||||
<img src="../../graphics/pgm_icon2.gif" border="0" alt="BS2 icon" title="BS2 icon" />
|
||||
<img src="../../graphics/pgm_icon2e.gif" border="0" alt="BS2e icon" title="BS2e icon" />
|
||||
<img src="../../graphics/pgm_icon2sx.gif" border="0" alt="BS2sx icon" title="BS2sx icon" />
|
||||
<img src="../../graphics/pgm_icon2p.gif" border="0" alt="BS2p icon" title="BS2p icon" />
|
||||
<img src="../../graphics/pgm_icon2pe.gif" border="0" alt="BS2pe icon" title="BS2pe icon" />
|
||||
<img src="../../graphics/pgm_icon2px.gif" border="0" alt="BS2px icon" title="BS2px icon" />
|
||||
</p>
|
||||
</div>
|
||||
<p style="text-align: right;"><a href="../ExampleTopics/LookupEx.htm" target="" title="" alt="" class="MCXref_0">LOOKUP Examples</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax <img align="absmiddle" src="../../graphics/mini_1.gif" /> :
|
||||
<span class="keyword_in_text">LOOKUP</span> <![CDATA[ ]]><i>Index</i>, (<i>Value0</i>,<i> Value1</i>, ...<i>ValueN</i>),<i>
|
||||
Variable</i><br />Syntax <img align="absmiddle" src="../../graphics/mini_2.gif" /> :
|
||||
<span class="keyword_in_text">LOOKUP</span> <![CDATA[ ]]><i>Index</i>, [<i>Value0</i>,<i> Value1</i>, ...<i>ValueN</i>],<i>
|
||||
Variable</i></p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Find the value at location <i>Index</i> and store it in <i>Variable</i>.
|
||||
If <i>Index</i> exceeds the highest index value of the items in the list,
|
||||
<i>Variable</i> is left unaffected.
|
||||
|
||||
</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Index</i></b> is a variable/constant/expression* (0 - 255) indicating
|
||||
the list item to retrieve. </li>
|
||||
<li value="2"><b><i>Values</i></b> are variables/constants/expressions* (0 - 65535).</li>
|
||||
<li value="3"><b><i>Variables</i></b> is a variable that will be set to the value at the
|
||||
<i>Index</i> location. If <i>Index</i> exceeds the highest location number, <i>Variable</i> is left unaffected.</li>
|
||||
</ul>
|
||||
<p class="PlainText">*<img src="../../graphics/bs1note.gif" style="vertical-align: super;" /> Note: expressions are not allowed as arguments on the BS1.</p>
|
||||
<h2>Quick Facts</h2>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr>
|
||||
<td width="20%" align="center" bgcolor="#CFCFCF"> </td>
|
||||
<td width="80%" align="center" bgcolor="#CFCFCF">All BASIC Stamp Modules</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Limit of value entries</td>
|
||||
<td align="center">256</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Starting index number</td>
|
||||
<td align="center">0</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">If index exceeds the highest location...</td>
|
||||
<td align="center"><i>Variable</i> is left unaffected</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Command</td>
|
||||
<td align="center" colspan="1">
|
||||
<p colspan="1" align="center"><a href="LOOKDOWN.htm" target="" title="" alt="" class="MCXref_0">LOOKDOWN</a>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText"><span class="keyword_in_text">LOOKUP</span> retrieves an item from a list based on the item's position, Index,
|
||||
in the list. For example: </p>
|
||||
<p>
|
||||
<img src="../../graphics/bs1_inline.gif" border="0">
|
||||
</img>
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
SYMBOL idx = B2
|
||||
SYMBOL result = B3
|
||||
|
||||
Setup:
|
||||
idx = 3
|
||||
result = 255
|
||||
|
||||
Main:
|
||||
LOOKUP idx, (26, 177, 13, 1, 0, 17, 99), result
|
||||
DEBUG "Item ", #idx, "is: ", #result
|
||||
END
|
||||
</pre>
|
||||
<p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0">
|
||||
</img>
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
idx VAR Nib
|
||||
result VAR Byte
|
||||
|
||||
Setup:
|
||||
idx = 3
|
||||
result = 255
|
||||
|
||||
Main:
|
||||
LOOKUP idx, [26, 177, 13, 1, 0, 17, 99], result
|
||||
DEBUG "Item ", DEC idx, " is: ", DEC result
|
||||
END
|
||||
</pre>
|
||||
<p class="PlainText">In this example, <span class="keyword_in_text">DEBUG</span> prints "Item 3 is: 1." Note that the first
|
||||
location number is 0. In the list above, item 0 is 26, item 1 is 177, etc.</p>
|
||||
<p class="PlainText">If <i>Index</i> is beyond the end of the list, the result variable is unchanged.
|
||||
In the example above, if index were greater than 6, the message would have reported
|
||||
the result to be 255, because that's what result contained before <span class="keyword_in_text">LOOKUP</span>
|
||||
executed. </p>
|
||||
<p class="PlainText">Don't forget that text phrases are just lists of byte values, so they too are
|
||||
eligible for <span class="keyword_in_text">LOOKUP</span> searches, as in this example:</p>
|
||||
<p>
|
||||
<img src="../../graphics/bs1_inline.gif" border="0">
|
||||
</img>
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
SYMBOL idx = B2
|
||||
SYMBOL result = B3
|
||||
|
||||
Setup:
|
||||
idx = 16
|
||||
result = "*"
|
||||
|
||||
Main:
|
||||
LOOKUP idx, ("The quick brown fox"), result
|
||||
DEBUG @result
|
||||
END
|
||||
</pre>
|
||||
<p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0">
|
||||
</img>
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
iidx VAR Byte
|
||||
result VAR Byte
|
||||
|
||||
Setup:
|
||||
idx = 16
|
||||
result = "*"
|
||||
|
||||
Main:
|
||||
LOOKUP idx, ["The quick brown fox"], result
|
||||
DEBUG ASC? result
|
||||
END
|
||||
</pre>
|
||||
<p class="PlainText"><span class="keyword_in_text">DEBUG</span> prints, "Result = 'f'" because the character at index item 16 is
|
||||
"f" in the phrase, "The quick brown fox".</p>
|
||||
<p class="PlainText">The examples above show <span class="keyword_in_text">LOOKUP</span> working with lists of constants, but it
|
||||
also works with variables and expressions also. Note, however, that expressions
|
||||
are not allowed as argument on the BS1. </p>
|
||||
<p class="PlainText">A great use of <span class="keyword_in_text">LOOKUP</span> is in combination with <span class="keyword_in_text">LOOKDOWN</span> to "map"
|
||||
non-contiguous sets of numbers together. For example, you may have an application
|
||||
where certain numbers are received by the BASIC Stamp and, in response, the BASIC
|
||||
Stamp needs to send a specific set of numbers. This may be easy to code if the
|
||||
numbers are contiguous, or follow some know algebraic equations… but what if they
|
||||
don't? The table below shows some sample, non-contiguous inputs and the
|
||||
corresponding outputs the BASIC Stamp needs to respond with:</p>
|
||||
<center>
|
||||
<table width="60%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr>
|
||||
<td width="10%" align="center" bgcolor="#CFCFCF">Index</td>
|
||||
<td width="25%" align="center" bgcolor="#CFCFCF">Each of these values
|
||||
received (inputs):</td>
|
||||
<td width="25%" align="center" bgcolor="#CFCFCF">Needs to result in each of
|
||||
these values sent (outputs):</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">0</td>
|
||||
<td align="center">5</td>
|
||||
<td align="center">16</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">1</td>
|
||||
<td align="center">14</td>
|
||||
<td align="center">17</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">2</td>
|
||||
<td align="center">1</td>
|
||||
<td align="center">18</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">3</td>
|
||||
<td align="center">43</td>
|
||||
<td align="center">24</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">4</td>
|
||||
<td align="center">26</td>
|
||||
<td align="center">10</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">5</td>
|
||||
<td align="center">22</td>
|
||||
<td align="center">12</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">6</td>
|
||||
<td align="center">30</td>
|
||||
<td align="center">11</td>
|
||||
</tr>
|
||||
</table>
|
||||
</center>
|
||||
<p> </p>
|
||||
<p class="PlainText">So, if we receive the number 5, we need to output 16. If we received 43, we
|
||||
need to output 24, and so on. These numbers are not contiguous and they don't
|
||||
appear to be derived from any simple algorithm. We can solve this problem with
|
||||
two lines of code, as follows:</p><pre class="BScode" xml:space="preserve">
|
||||
LOOKDOWN value, [5, 14, 1, 43, 26, 22, 30], value
|
||||
LOOKUP value, [16, 17, 18, 24, 10, 12, 11], value
|
||||
</pre>
|
||||
<p class="PlainText">Assuming our received number is in <span class="code_in_text">value</span>, the first line (<span class="keyword_in_text">LOOKDOWN</span>)
|
||||
will find the value in the list and store the index of the location that matches
|
||||
back into <span class="code_in_text">value</span>. (This step "maps" the non-contiguous numbers: 5, 14, 1, etc,
|
||||
to a contiguous set of numbers: 0, 1, 2, etc). The second line (<span class="keyword_in_text">LOOKUP</span>)
|
||||
takes our new value, finds the number at that location and stores it back into
|
||||
<span class="code_in_text">value</span>. If the received value was 14, <span class="keyword_in_text">LOOKDOWN</span> stores 1 into <span class="code_in_text">value </span>and
|
||||
<span class="keyword_in_text">LOOKUP</span> looks at the value at location 1 and stores 17 in <span class="code_in_text">value</span>. The
|
||||
number 43 gets mapped to 3, 3 gets mapped to 24, and so on. This is a quick and
|
||||
easy fix for a potentially messy problem!</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>
|
108
help/BasicStampHelp/Content/LanguageTopics/Commands/LOW.htm
Normal file
108
help/BasicStampHelp/Content/LanguageTopics/Commands/LOW.htm
Normal file
@ -0,0 +1,108 @@
|
||||
<?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>LOW</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">LOW</h1>
|
||||
<div class="ImagePlusCaption">
|
||||
<div class="Col2">
|
||||
<p>
|
||||
<img src="../../graphics/pgm_icon1.gif" border="0" alt="BS1 icon" title="BS1 icon" />
|
||||
<img src="../../graphics/pgm_icon2.gif" border="0" alt="BS2 icon" title="BS2 icon" />
|
||||
<img src="../../graphics/pgm_icon2e.gif" border="0" alt="BS2e icon" title="BS2e icon" />
|
||||
<img src="../../graphics/pgm_icon2sx.gif" border="0" alt="BS2sx icon" title="BS2sx icon" />
|
||||
<img src="../../graphics/pgm_icon2p.gif" border="0" alt="BS2p icon" title="BS2p icon" />
|
||||
<img src="../../graphics/pgm_icon2pe.gif" border="0" alt="BS2pe icon" title="BS2pe icon" />
|
||||
<img src="../../graphics/pgm_icon2px.gif" border="0" alt="BS2px icon" title="BS2px icon" />
|
||||
</p>
|
||||
</div>
|
||||
<p style="text-align: right;"><a href="../ExampleTopics/HighLowEx.htm" target="" title="" alt="" class="MCXref_0">HIGH / LOW Example</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: <span class="keyword_in_text">LOW</span> <![CDATA[ ]]><i>Pin</i></p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Make the specified pin output low.
|
||||
|
||||
</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Pin</i></b> is a variable/constant/expression (0 - 15) that specifies
|
||||
which I/O pin to set low. This pin will be placed into output mode.</li>
|
||||
</ul>
|
||||
<p class="PlainText">*<img src="../../graphics/bs1note.gif" style="vertical-align: super;" /> Note: expressions are not allowed as arguments on the BS1. The range
|
||||
of the <i>Pin</i> argument on the BS1 is 0–7.</p>
|
||||
<h2>Quick Facts</h2>
|
||||
<table cellpadding="4" cellspacing="0" border="1" style="caption-side: top;width: 100%;">
|
||||
<col />
|
||||
<col />
|
||||
<tr bgcolor="#CFCFCF">
|
||||
<td width="15%" align="center"> </td>
|
||||
<td width="85%" align="center">BS1 and all BS2 models</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
||||
<td>
|
||||
<p align="center"><a href="HIGH.htm" target="" title="" alt="" class="MCXref_0">HIGH</a>, <a href="TOGGLE.htm" target="" title="" alt="" class="MCXref_0">TOGGLE</a></p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText">The <span class="keyword_in_text">LOW</span> command sets the specified pin to 0 (a 0 volt level) and then
|
||||
sets its mode to output. For example,
|
||||
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
 LOW 6
|
||||
</pre>
|
||||
<p class="PlainText">...does exactly the same thing as:</p>
|
||||
<p>
|
||||
<img src="../../graphics/bs1_inline.gif" border="0" />
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
 PIN6 = 0
|
||||
 DIR6 = 1
|
||||
</pre>
|
||||
<p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0">
|
||||
</img>
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
 OUT6 = 0
|
||||
 DIR6 = 1
|
||||
</pre>
|
||||
<p class="PlainText">Using the <span class="keyword_in_text">LOW</span> command is faster in this case.</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,90 @@
|
||||
<?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>MAINIO</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">MAINIO</h1>
|
||||
<div class="ImagePlusCaption">
|
||||
<div class="Col2">
|
||||
<p>
|
||||
<img src="../../graphics/pgm_icon2p.gif" border="0" alt="BS2p icon" title="BS2p icon" /> (BS2p40)</p>
|
||||
</div>
|
||||
<p style="text-align: right;"><a href="../ExampleTopics/AuMainIotermEx.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">AUXIO / MAINIO / IOTERM Example</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: <span class="keyword_in_text">MAINIO</span></p>
|
||||
<h2>Function</h2>
|
||||
<p>Switch from control of auxiliary I/O pins to main I/O pins (on the BS2p40 only).</p>
|
||||
<h2>Quick Facts</h2>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF">
|
||||
<td width="15%" align="center"> </td>
|
||||
<td width="85%" align="center">BS2p / BS2pe / BS2px</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">I/O Pin IDs</td>
|
||||
<td>0 - 15 (just like auxiliary I/O, but after <span class="keyword_in_text">MAINIO</span> command, all
|
||||
references affect physical pins 5 - 20).</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Special Notes</td>
|
||||
<td>
|
||||
<p>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.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
||||
<td align="center" colspan="1">
|
||||
<p colspan="1" align="center"><a href="AUXIO.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">AUXIO</a>, <a href="IOTERM.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">IOTERM</a></p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText">The BS2p, BS2pe, and BS2px is available as a 24-pin module that is pin-compatible with the BS2, BS2e, and BS2sx. Also availabe is a 40-pin module called the BS2p40 with an additional 16 I/O pins (for a total of 32). The BS2p40's extra, or auxiliary, I/O pins can be accessed in the same manner as the main I/O pins (by using the IDs 0 to 15) but only after issuing an <span class="keyword_in_text">AUXIO</span> or <span class="keyword_in_text">IOTERM 1</span> command. The <span class="keyword_in_text">MAINIO</span> command causes the BASIC Stamp to affect the main I/O pins (the default) instead of the auxiliary I/O pins in all further code until the <span class="keyword_in_text">AUXIO</span> or <span class="keyword_in_text">IOTERM 1</span> command is reached, or the BASIC Stamp is reset or power-cycled.</p>
|
||||
<p class="PlainText">The following example illustrates this:<br></br></p><pre class="BScode" xml:space="preserve">
|
||||
AUXIO
|
||||
HIGH 0
|
||||
MAINIO
|
||||
LOW 0
|
||||
</pre>
|
||||
<p class="PlainText">The first line of the above example will tell the BASIC Stamp to affect the auxiliary I/O pins in the commands following it. Line 2 sets I/O pin 0 of the auxiliary I/O pins (physical pin 21) high. Afterward, the <span class="keyword_in_text">MAINIO </span>command tells the BASIC Stamp that all commands following it should affect the main I/O pins. The last command, <span class="keyword_in_text">LOW</span>, will set I/O pin 0 of the main I/O pins (physical pin 5) low.</p>
|
||||
<p class="PlainText">Note that the main I/O and auxiliary I/O pins are independent of each other; the states of the main I/O pins remain unchanged while the program affects the auxiliary I/O pins, and vice versa.</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>
|
194
help/BasicStampHelp/Content/LanguageTopics/Commands/NAP.htm
Normal file
194
help/BasicStampHelp/Content/LanguageTopics/Commands/NAP.htm
Normal file
@ -0,0 +1,194 @@
|
||||
<?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>NAP</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">NAP</h1>
|
||||
<div class="ImagePlusCaption">
|
||||
<div class="Col2">
|
||||
<p>
|
||||
<img src="../../graphics/pgm_icon1.gif" border="0" alt="BS1 icon" title="BS1 icon" />
|
||||
<img src="../../graphics/pgm_icon2.gif" border="0" alt="BS2 icon" title="BS2 icon" />
|
||||
<img src="../../graphics/pgm_icon2e.gif" border="0" alt="BS2e icon" title="BS2e icon" />
|
||||
<img src="../../graphics/pgm_icon2sx.gif" border="0" alt="BS2sx icon" title="BS2sx icon" />
|
||||
<img src="../../graphics/pgm_icon2p.gif" border="0" alt="BS2p icon" title="BS2p icon" />
|
||||
<img src="../../graphics/pgm_icon2pe.gif" border="0" alt="BS2pe icon" title="BS2pe icon" />
|
||||
<img src="../../graphics/pgm_icon2px.gif" border="0" alt="BS2px icon" title="BS2px icon" />
|
||||
</p>
|
||||
</div>
|
||||
<p style="text-align: right;"><a href="../ExampleTopics/NapEx.htm" target="" title="" alt="" class="MCXref_0">NAP Example</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: <span class="keyword_in_text">NAP</span> <![CDATA[ ]]><i>Duration</i></p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Enter sleep mode for a short time. Power consumption is reduced as indicated in
|
||||
the table below assuming no loads are being driven.
|
||||
|
||||
</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Duration</i></b> is a variable/constant/expression* (0 - 7) that
|
||||
specifies the duration of the reduced-power "nap." The low-power duration is
|
||||
2<sup style="font-style: italic;">Duration</sup> x 18 milliseconds.</li>
|
||||
</ul>
|
||||
<p class="PlainText">*<img src="../../graphics/bs1note.gif" style="vertical-align: super;" /> Note: expressions are not allowed as arguments on the BS1.</p>
|
||||
<h2>Quick Facts</h2>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr align="center" bgcolor="#CFCFCF">
|
||||
<td width="23%"> </td>
|
||||
<td width="11%">BS1</td>
|
||||
<td width="11%">BS2</td>
|
||||
<td width="11%">BS2e</td>
|
||||
<td width="11%">BS2sx</td>
|
||||
<td width="11%">BS2p</td>
|
||||
<td width="11%">BS2pe</td>
|
||||
<td width="11%">BS2px</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td bgcolor="#CFCFCF">Current Draw during Run</td>
|
||||
<td>1 mA</td>
|
||||
<td>3 mA</td>
|
||||
<td>25 mA</td>
|
||||
<td>60 mA</td>
|
||||
<td>40 mA</td>
|
||||
<td>15 mA</td>
|
||||
<td>55 mA</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td bgcolor="#CFCFCF">Current Draw during <span class="keyword_in_text">NAP</span></td>
|
||||
<td>25 µA</td>
|
||||
<td>50 µA</td>
|
||||
<td>200 µA</td>
|
||||
<td>500 µA</td>
|
||||
<td>350 µA</td>
|
||||
<td>36 µA</td>
|
||||
<td>450 µA</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
||||
<td align="center" colspan="4">
|
||||
<p colspan="4" align="center"><a href="END.htm" target="" title="" alt="" class="MCXref_0">END</a>, <a href="SLEEP.htm" target="" title="" alt="" class="MCXref_0">SLEEP</a></p>
|
||||
</td>
|
||||
<td align="center" colspan="3">
|
||||
<p colspan="3" align="center"><a href="END.htm" target="" title="" alt="" class="MCXref_0">END</a>, <a href="SLEEP.htm" target="" title="" alt="" class="MCXref_0">SLEEP</a>, <a href="POLLWAIT.htm" target="" title="" alt="" class="MCXref_0">POLLWAIT</a></p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td bgcolor="#CFCFCF">Accuracy of <span class="keyword_in_text">NAP</span></td>
|
||||
<td colspan="7">-50 to 100% (±10% @ 75°F with stable power supply)</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText"><span class="keyword_in_text">NAP</span> uses the same shutdown/startup mechanism as <span class="keyword_in_text">SLEEP</span>, with one big
|
||||
difference. During <span class="keyword_in_text">SLEEP</span>, the BASIC Stamp automatically compensates for
|
||||
variations in the speed of the watchdog timer oscillator that serves as its alarm
|
||||
clock. As a result, longer <span class="keyword_in_text">SLEEP</span> intervals are accurate to approximately
|
||||
±1 percent.</p>
|
||||
<center>
|
||||
<table cellpadding="4" cellspacing="0" border="1">
|
||||
<col style="width: 63px;" />
|
||||
<col />
|
||||
<tr align="center" bgcolor="#CFCFCF">
|
||||
<td><i>Duration</i>
|
||||
</td>
|
||||
<td width="165">Length of <span class="keyword_in_text">NAP</span></td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>0</td>
|
||||
<td>18 ms</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>1</td>
|
||||
<td>36 ms</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>2</td>
|
||||
<td>72 ms</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>3</td>
|
||||
<td>144 ms</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>4</td>
|
||||
<td>288 ms</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>5</td>
|
||||
<td>576 ms</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>6</td>
|
||||
<td>1152 ms (1.152 seconds)</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>7</td>
|
||||
<td>2304 ms (2.304 seconds)</td>
|
||||
</tr>
|
||||
</table>
|
||||
</center>
|
||||
<p> </p>
|
||||
<p class="PlainText"><span class="keyword_in_text">NAP</span> intervals are directly controlled by the watchdog timer without
|
||||
compensation. Variations in temperature, supply voltage, and manufacturing
|
||||
tolerance of the BASIC Stamp's interpreter chip can cause the actual timing to
|
||||
vary by as much as -50, +100 percent (i.e., a <i>Duration</i> of 0, <span class="keyword_in_text">NAP</span> can range
|
||||
from 9 to 36 ms). At room temperature with a fresh battery or other stable power
|
||||
supply, variations in the length of a <span class="keyword_in_text">NAP</span> will be less than ±10 percent. </p>
|
||||
<p class="PlainText">One great use for <span class="keyword_in_text">NAP</span> is in a battery-powered application where at least
|
||||
some small amount of time is spent doing nothing. For example, you may have a
|
||||
program that loops endlessly, performing some task, and pausing for approximately
|
||||
100 ms each time through the loop. You could replace your <span class="code_in_text">PAUSE 100</span> with
|
||||
<span class="code_in_text">NAP 3</span>, as long as the timing of the 100 ms pause was not critical. The
|
||||
<span class="code_in_text">NAP 3</span> would effectively pause your program for about 144 milliseconds and,
|
||||
at the same time, would place the BASIC Stamp in low-power mode, which would extend
|
||||
your battery life.</p>
|
||||
<p class="PlainText">During execution of power conserving commands (<span class="keyword_in_text">END</span>, <span class="keyword_in_text">NAP</span>, <span class="keyword_in_text">POLLWAIT</span>, and <span class="keyword_in_text">SLEEP</span>), current will occasionally be interrupted
|
||||
on I/O pins for about 18 ms durations (60 µs on the BS2pe). The reason is that the
|
||||
watchdog-timer reset that awakens the BASIC Stamp during these commands also causes all of the pins to
|
||||
switch to input mode for approximately 18 ms (60 µs on the BS2pe). When the interpreter
|
||||
firmware regains control of the processor, it restores the I/O direction dictated
|
||||
by your program.</p>
|
||||
<p class="PlainText">If you plan to use <span class="keyword_in_text">END</span>, <span class="keyword_in_text">NAP</span>, <span class="keyword_in_text">POLLWAIT</span>, or <span class="keyword_in_text">SLEEP</span> in your programs,
|
||||
make sure that your loads can tolerate these power outages. The simplest solution
|
||||
is often to connect resistors high or low (to +5V or ground) as appropriate to
|
||||
ensure a continuing supply of current during the reset. </p>
|
||||
<p class="PlainText">The example program can be used to demonstrate the effects
|
||||
of the <span class="keyword_in_text">NAP</span> reset with an LED and resistor.</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>
|
107
help/BasicStampHelp/Content/LanguageTopics/Commands/ON_GOSUB.htm
Normal file
107
help/BasicStampHelp/Content/LanguageTopics/Commands/ON_GOSUB.htm
Normal file
@ -0,0 +1,107 @@
|
||||
<?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>ON...GOSUB</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">ON...GOSUB</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;"><a href="../ExampleTopics/OnGosubEx.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">ON...GOSUB Example</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: <span class="keyword_in_text">ON</span> <![CDATA[ ]]><i>Offset</i> <![CDATA[ ]]><span class="keyword_in_text">GOSUB</span> <![CDATA[ ]]><i>Address1</i>, <i>Address2</i>, ...<i>AddressN</i></p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Store the address of the next instruction after <span class="keyword_in_text">ON..GOSUB</span>, then go to the
|
||||
<i>Address</i> specified by offset (if in range) with the intention of returning
|
||||
to the stored address. If <i>Offset</i>-1 is greater than the number of elements in
|
||||
the address table, the program continues at the line following <span class="keyword_in_text">ON..GOSUB</span>.</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Offset</i></b> is a variable/constant/expression (0 - 255) that
|
||||
specifies the index of the address, in the list, to branch to (0 - N).</li>
|
||||
<li value="2"><b><i>Addresses</i></b> are labels that specify where to go for a given <i>Offset</i>. <span class="keyword_in_text">ON...GOSUB</span>
|
||||
will ignore any list entries beyond offset 255.</li>
|
||||
</ul>
|
||||
<h2>Quick Facts</h2>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr>
|
||||
<td align="center" width="25%" bgcolor="#CFCFCF"> </td>
|
||||
<td align="center" bgcolor="#CFCFCF">BS2 Family</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Limit of <i>Address</i> entries</td>
|
||||
<td align="center">256</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Maximum nested <span class="keyword_in_text">GOSUB</span>s </td>
|
||||
<td align="center">4</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Maximum <span class="keyword_in_text">GOSUB</span>s per Program</td>
|
||||
<td align="center">255 (each <span class="keyword_in_text">ON...GOSUB</span> counts as as a <span class="keyword_in_text">GOSUB </span>regardless of number of address list entries)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
||||
<td align="center" colspan="1">
|
||||
<p colspan="1" align="center"><a href="BRANCH.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">BRANCH</a>, <a href="GOSUB.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">GOSUB</a>, <a href="GOTO.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">GOTO</a>, <a href="ON_GOTO.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">ON...GOTO</a></p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText">The <span class="keyword_in_text">ON...GOSUB</span> instruction is useful when you want to write something like
|
||||
this:</p><pre class="BScode" xml:space="preserve">
|
||||
IF (value = 0) THEN GOSUB Case_0
|
||||
IF (value = 1) THEN GOSUB Case_1
|
||||
IF (value = 2) THEN GOSUB Case_2
|
||||
</pre>
|
||||
<p class="PlainText">You can use <span class="keyword_in_text">ON...GOSUB</span> to organize this into a single statement:</p><pre class="BScode" xml:space="preserve">
|
||||
ON value GOSUB Case_0, Case_1, Case_2
|
||||
</pre>
|
||||
<p class="PlainText">This works exactly the same as the previous <a href="IF_THEN.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">IF…THEN</a> example. If the value isn't in range (in this case if <span class="code_in_text">value</span> is greater than 2), <span class="keyword_in_text">ON...GOSUB</span> does nothing and the program continues with the next instruction after <span class="keyword_in_text">ON</span>.</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,98 @@
|
||||
<?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>ON...GOTO</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">ON...GOTO</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;"><a href="../ExampleTopics/OnGotoEx.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">ON...GOTO Example</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p>Syntax: <span class="keyword_in_text">ON</span> <![CDATA[ ]]><i>Offset</i> <![CDATA[ ]]><b>GOTO</b> <![CDATA[ ]]><i>Address1</i>,<i> Address2</i>,
|
||||
...<i>AddressN</i></p>
|
||||
<h2>Function</h2>
|
||||
<p>Go to the address specified by offset (if in range).
|
||||
|
||||
</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Offset</i></b> is a variable/constant/expression (0 - 255) that specifies
|
||||
the index of the address, in the list, to branch to (0 - N).</li>
|
||||
<li value="2"><b><i>Addresses</i></b> are labels that specify where to go. <span class="keyword_in_text">ON...GOTO</span>will ignore any list entries beyond offset 255.</li>
|
||||
</ul>
|
||||
<h2>Quick Facts</h2>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr>
|
||||
<td align="center" width="25%" bgcolor="#CFCFCF"> </td>
|
||||
<td align="center" bgcolor="#CFCFCF">BS2 Family</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Limit of <i>Address</i> entries</td>
|
||||
<td align="center">256</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
||||
<td align="center" colspan="1">
|
||||
<p colspan="1" align="center"><a href="BRANCH.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">BRANCH</a>, <a href="GOSUB.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">GOSUB</a>, <a href="ON_GOSUB.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">ON...GOSUB</a>, <a href="GOTO.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">GOTO</a></p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText">The <span class="keyword_in_text">ON...GOTO</span> instruction is useful when you want to write something like
|
||||
this:</p><pre class="BScode" xml:space="preserve">
|
||||
IF idx = 0 THEN Case_0 ' idx = 0: jump to label "Case_0"
|
||||
IF idx = 1 THEN Case_1 ' idx = 1: jump to label "Case_1"
|
||||
IF idx = 2 THEN Case_2 ' idx = 2: jump to label "Case_2"
|
||||
</pre>
|
||||
<p class="PlainText">You can use <span class="keyword_in_text">ON...GOTO</span> to organize this into a single statement:</p><pre class="BScode" xml:space="preserve">
|
||||
ON idx GOTO Case_0, Case_1, Case_2
|
||||
</pre>
|
||||
<p class="PlainText">This works exactly the same as the previous <a href="IF_THEN.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">IF…THEN</a> example. If the value isn't in range (in this case if <span class="code_in_text">value</span> is greater than 2), <span class="keyword_in_text">ON...GOSUB</span> does nothing and the program continues with the next instruction after <span class="keyword_in_text">ON</span>.</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>
|
111
help/BasicStampHelp/Content/LanguageTopics/Commands/OUTPUT.htm
Normal file
111
help/BasicStampHelp/Content/LanguageTopics/Commands/OUTPUT.htm
Normal file
@ -0,0 +1,111 @@
|
||||
<?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>OUTPUT</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">OUTPUT</h1>
|
||||
<div class="ImagePlusCaption">
|
||||
<div class="Col2">
|
||||
<p>
|
||||
<img src="../../graphics/pgm_icon1.gif" border="0" alt="BS1 icon" title="BS1 icon" />
|
||||
<img src="../../graphics/pgm_icon2.gif" border="0" alt="BS2 icon" title="BS2 icon" />
|
||||
<img src="../../graphics/pgm_icon2e.gif" border="0" alt="BS2e icon" title="BS2e icon" />
|
||||
<img src="../../graphics/pgm_icon2sx.gif" border="0" alt="BS2sx icon" title="BS2sx icon" />
|
||||
<img src="../../graphics/pgm_icon2p.gif" border="0" alt="BS2p icon" title="BS2p icon" />
|
||||
<img src="../../graphics/pgm_icon2pe.gif" border="0" alt="BS2pe icon" title="BS2pe icon" />
|
||||
<img src="../../graphics/pgm_icon2px.gif" border="0" alt="BS2px icon" title="BS2px icon" />
|
||||
</p>
|
||||
</div>
|
||||
<p style="text-align: right;"><a href="../ExampleTopics/InputOutputEx.htm" target="" title="" alt="" class="MCXref_0">INPUT / OUTPUT Examples</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: <span class="keyword_in_text">OUTPUT</span> <![CDATA[ ]]><i>Pin</i></p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Make the specified pin an output.
|
||||
|
||||
</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Pin</i></b> is a variable/constant/expression* (0 - 15) that specifies
|
||||
which I/O pin to set to output mode</li>
|
||||
</ul>
|
||||
<p class="PlainText">*<img src="../../graphics/bs1note.gif" style="vertical-align: super;" /> Note: expressions are not allowed as arguments on the BS1. The range
|
||||
of the <i>Pin</i> argument on the BS1 is 0–7.</p>
|
||||
<h2>Quick Facts</h2>
|
||||
<table cellpadding="4" cellspacing="0" border="1" style="caption-side: top;width: 100%;">
|
||||
<col />
|
||||
<col />
|
||||
<tr bgcolor="#CFCFCF">
|
||||
<td width="15%" align="center"> </td>
|
||||
<td width="85%" align="center">BS1 and all BS2 models</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
||||
<td>
|
||||
<p align="center"><a href="INPUT.htm" target="" title="" alt="" class="MCXref_0">INPUT</a>, <a href="REVERSE.htm" target="" title="" alt="" class="MCXref_0">REVERSE</a></p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText">There are several ways to make a pin an output. Commands that rely on
|
||||
output pins, like <span class="keyword_in_text">PULSOUT</span> and <span class="keyword_in_text">SEROUT</span>, automatically change the
|
||||
specified pin to output. Writing 1s to particular bits of the variable DIRS
|
||||
makes the corresponding pins outputs. And then there’s the <span class="keyword_in_text">OUTPUT</span>command.</p>
|
||||
<p class="PlainText">When a pin is an output, your program can change its state by writing to
|
||||
the corresponding bit in the OUTS variable (PINS on the BS1). For
|
||||
example:
|
||||
|
||||
</p>
|
||||
<p>
|
||||
<img src="../../graphics/bs1_inline.gif" border="0">
|
||||
</img>
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
OUTPUT 4
|
||||
PIN4 = 1
|
||||
</pre>
|
||||
<p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0">
|
||||
</img>
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
OUTPUT 4
|
||||
OUT4 = 1
|
||||
</pre>
|
||||
<p class="PlainText">When your program changes a pin from input to output, whatever state happens to be in the corresponding bit of OUTS (PINS on the BS1) sets the initial state of the pin. To simultaneously make a pin an output and set its state use the <span class="keyword_in_text">HIGH</span> and <span class="keyword_in_text">LOW</span> commands.</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>
|
432
help/BasicStampHelp/Content/LanguageTopics/Commands/OWIN.htm
Normal file
432
help/BasicStampHelp/Content/LanguageTopics/Commands/OWIN.htm
Normal file
@ -0,0 +1,432 @@
|
||||
<?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>OWIN</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">OWIN</h1>
|
||||
<div class="ImagePlusCaption">
|
||||
<div class="Col2">
|
||||
<p>
|
||||
<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/OwinOwoutEx.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">OWIN / OWOUT Example</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: <span class="keyword_in_text">OWIN</span> <![CDATA[ ]]><i>Pin</i>,<i> Mode</i>, [<i>InputData</i>]</p>
|
||||
<h2>Function</h2>
|
||||
<p>Receive data from a device using the Maxim/Dallas Semiconductor 1-Wire<sup>®</sup>protocol.</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Pin</i></b> is a variable/constant/expression (0 - 15) that specifies
|
||||
which I/O pin to use. 1-Wire devices require only one I/O pin
|
||||
(called DQ) to communicate. This I/O pin will be toggled between output
|
||||
and input mode during the <span class="keyword_in_text">OWIN</span> command and will be set to input mode
|
||||
by the end of the <span class="keyword_in_text">OWIN</span> command.</li>
|
||||
<li value="2"><b><i>Mode</i></b> is a variable/constant/expression (0 - 15) indicating
|
||||
the mode of data transfer. The <i>Mode</i> argument controls placement of
|
||||
reset pulses (and detection of presence pulses) as well as byte vs. bit input
|
||||
and normal vs. high speed. See explanation below.</li>
|
||||
<li value="3"><b><i>InputData</i></b> is a list of variables and modifiers that tells
|
||||
<span class="keyword_in_text">OWIN</span> what to do with incoming data. <span class="keyword_in_text">OWIN</span> can store data in a
|
||||
variable or array, interpret numeric text (decimal, binary, or hex) and store
|
||||
the corresponding value in a variable, wait for a fixed or variable sequence
|
||||
of bytes, or ignore a specified number of bytes. These actions can be combined
|
||||
in any order in the <i>InputData</i> list.</li>
|
||||
</ul>
|
||||
<h2>Quick Facts</h2>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF">
|
||||
<td width="20%" align="center"> </td>
|
||||
<td width="80%" align="center">BS2p, BS2pe, and BS2px</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Receive Rate</td>
|
||||
<td>Approximately 20 kBits/sec (low speed, not including reset pulse)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Special Notes</td>
|
||||
<td>The DQ pin (specified by <i>Pin</i>) must have a 4.7 kΩ pull-up
|
||||
resist0r.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
||||
<td align="center" colspan="1">
|
||||
<p colspan="1" align="center"><a href="OWOUT.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">OWOUT</a>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText">The 1-Wire protocol is a form of asynchronous serial communication developed by
|
||||
Maxim/Dallas Semiconductor. It only requires one I/O pin and that pin can
|
||||
be shared between multiple 1-Wire devices. The <span class="keyword_in_text">OWIN</span> command
|
||||
allows the BASIC Stamp to receive data from a 1-Wire device.</p>
|
||||
<p>The following is an example of the <span class="keyword_in_text">OWIN</span> command:</p><pre class="BScode" xml:space="preserve">
|
||||
result VAR Byte
|
||||
|
||||
Main:
|
||||
OWIN 0, 1, [result]
|
||||
STOP
|
||||
</pre>
|
||||
<p class="PlainText">This code will transmit a "reset" pulse to a 1-Wire device
|
||||
(connected to I/O pin 0) and then will detect the device's "presence" pulse and
|
||||
then receive one byte and store it in the variable result. </p>
|
||||
<p class="PlainText">The <i>Mode</i> argument is used to control placement of reset pulses (and
|
||||
detection of presence pulses) and to designate byte vs. bit input and normal vs.
|
||||
high speed<sup>†</sup>. The tables below show the meaning of each of the
|
||||
four bits of <i>Mode</i> and some of the 16 possible values and their effect. </p>
|
||||
<h3><i>Mode</i> Format bits</h3>
|
||||
<table width="35%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF">
|
||||
<td width="50" align="center">Bit</td>
|
||||
<td width="200" align="center">Function</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">0</td>
|
||||
<td>Front-End Reset<br></br>• 0 = No reset <br></br>• 1 = Generate reset before data</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">1</td>
|
||||
<td>Back-End Reset<br></br>• 0 = No reset <br></br>• 1 = Generate reset after data</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">2</td>
|
||||
<td>Bit / Byte Transfer<br></br>• 0 = Byte <br></br>• 1 = Bit</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">3</td>
|
||||
<td>Low / High Speed<sup>†</sup><br></br>• 0 = Low <br></br>• 1 = High</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p> </p>
|
||||
<table width="35%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF" align="center">
|
||||
<td width="50">Mode</td>
|
||||
<td>Effect</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">0</td>
|
||||
<td>No Reset, Byte mode, Low speed</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">1</td>
|
||||
<td>Reset before data, Byte mode, Low speed</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">2</td>
|
||||
<td>Reset after data, Byte mode, Low speed</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">3</td>
|
||||
<td>Reset before and after data, Byte mode, Low speed</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">4</td>
|
||||
<td>No Reset, Bit mode, Low speed</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">5</td>
|
||||
<td>Reset before data, Bit mode, Low speed</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">6</td>
|
||||
<td>Reset after data, Bit mode, Low speed</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">7</td>
|
||||
<td>Reset before and after data, Bit mode, Low speed</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">8</td>
|
||||
<td>No Reset, Byte mode, High speed<sup>†</sup></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">9</td>
|
||||
<td>Reset before data, Byte mode, High speed<sup>†</sup></td>
|
||||
</tr>
|
||||
</table>
|
||||
<p><sup>†</sup> The BS2pe is not capable of High-Speed transfers.</p>
|
||||
<p> </p>
|
||||
<p class="PlainText">The proper value for <i>Mode</i> depends on the 1-Wire device
|
||||
and the portion of the communication you're working on. Please consult the data
|
||||
sheet for the device in question to determine the correct value for Mode. In many
|
||||
cases, however, when using the <span class="keyword_in_text">OWIN</span> command, <i>Mode</i> should be set for
|
||||
either No Reset (to receive data from a transaction already started by a <span class="keyword_in_text">OWOUT</span>command) or a Back-End Reset (to terminate the session after data is received).
|
||||
This may vary due to device and application requirements, however.</p>
|
||||
<p>When using the Bit (rather than Byte) mode of data transfer, all variables in
|
||||
the <i>InputData</i> argument will only receive one bit. For example, the following
|
||||
code could be used to receive two bits using this mode:</p><pre class="BScode" xml:space="preserve">
|
||||
bitOne VAR Bit
|
||||
bitTwo VAR Bit
|
||||
|
||||
Main:
|
||||
OWIN 0, 6, [bitOne, bitTwo]
|
||||
STOP
|
||||
</pre>
|
||||
<p class="PlainText">In the code above, we chose the value "6" for <i>Mode</i>. This sets Bit transfer
|
||||
and Back-End Reset modes. Also, we could have chosen to make the bitOne and bitTwo
|
||||
variables each a byte in size, but they still would only have received one bit each
|
||||
in the <span class="keyword_in_text">OWIN</span> command (due to the <i>Mode</i> selected).</p>
|
||||
<p class="PlainText">The <span class="keyword_in_text">OWIN</span> command's <i>InputData</i> argument is similar to the <b>SERIN</b>command's <i>InputData</i> argument. This means data can be received as ASCII
|
||||
character values, decimal, hexadecimal and binary translations and string data as
|
||||
in the examples below. (Assume a 1-Wire device is used and that
|
||||
it transmits the string, "Value: 3A:101" every time it receives a Front-End Reset
|
||||
pulse).</p><pre class="BScode" xml:space="preserve">
|
||||
value VAR Byte(13)
|
||||
|
||||
Main:
|
||||
OWIN 0, 1, [value] ' receive ASCII code for "V"
|
||||
OWIN 0, 1, [DEC value] ' receive the number 3
|
||||
OWIN 0, 1, [HEX value] ' receive the number $3A
|
||||
OWIN 0, 1, [BIN value] ' receive the number %101
|
||||
OWIN 0, 1, [STR value\13] ' receive the string "Value: 3A:101"
|
||||
STOP
|
||||
</pre>
|
||||
<p class="PlainText">The tables below list all the available special formatters and conversion
|
||||
formatters available to the <span class="keyword_in_text">OWIN</span> command. See the <a href="SERIN.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">SERIN</a> command for additional information and examples of their use.</p>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF" align="center" valign="top">
|
||||
<td width="150">Special Formatter</td>
|
||||
<td>Action</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">STR ByteArray \L {\E}</td>
|
||||
<td>Input a character string of length L into an array. If specified, an end
|
||||
character E causes the string input to end before reaching length L.
|
||||
Remaining bytes are filled with 0s (zeros).</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">WAITSTR ByteArray {\L}</td>
|
||||
<td>Wait for a sequence of bytes matching a string stored in an array variable,
|
||||
optionally limited to L characters. If the optional L argument is left off,
|
||||
the end of the array-string must be marked by a byte containing a zero (0).</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">SKIP Length</td>
|
||||
<td>Ignore Length bytes of characters.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">SPSTR Length</td>
|
||||
<td>Buffer Length bytes (up to 126) of serial characters to Scratchpad RAM,
|
||||
starting at location 0. Use <a href="GET.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">GET</a> to retrieve the
|
||||
characters.</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p> </p>
|
||||
<p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0" />
|
||||
</p>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF" align="center" valign="top">
|
||||
<td width="15%">Conversion Formatter</td>
|
||||
<td width="45%">Type of Number</td>
|
||||
<td width="30%">Numeric Characters Accepted</td>
|
||||
<td width="10%">Notes</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>DEC{1..5}</td>
|
||||
<td>Decimal, optionally limited to 1 - 5 digits</td>
|
||||
<td>0 through 9</td>
|
||||
<td>1</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>SDEC{1..5}</td>
|
||||
<td>Signed decimal, optionally limited to 1 - 5 digits</td>
|
||||
<td>-, 0 through 9</td>
|
||||
<td>1,2</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>HEX{1..4}</td>
|
||||
<td>Hexadecimal, optionally limited to 1 - 4 digits</td>
|
||||
<td>0 through 9, A through F</td>
|
||||
<td>1,3</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>SHEX{1..4}</td>
|
||||
<td>Signed hexadecimal, optionally limited to 1 - 4 digits </td>
|
||||
<td>-, 0 through 9, A through F</td>
|
||||
<td>1,2,3</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>IHEX{1..4}</td>
|
||||
<td>Indicated hexadecimal, optionally limited to 1 - 4 digits</td>
|
||||
<td>$, 0 through 9, A through F</td>
|
||||
<td>1,3,4</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>ISHEX{1..4}</td>
|
||||
<td>Signed, indicated hexadecimal, optionally limited to 1 - 4 digits</td>
|
||||
<td>-, $, 0 through 9, A through F</td>
|
||||
<td>1,2,3,4</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>BIN{1..16}</td>
|
||||
<td>Binary, optionally limited to 1 - 16 digits</td>
|
||||
<td>0, 1</td>
|
||||
<td>1</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>SBIN{1..16}</td>
|
||||
<td>Signed binary, optionally limited to 1 - 16 digits</td>
|
||||
<td>-, 0, 1</td>
|
||||
<td>1,2</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>IBIN{1..16}</td>
|
||||
<td>Indicated binary, optionally limited to 1 - 16 digits</td>
|
||||
<td>%, 0, 1</td>
|
||||
<td>1,4</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>ISBIN{1..16}</td>
|
||||
<td>Signed, indicated binary, optionally limited to 1 - 16 digits</td>
|
||||
<td>-, %, 0, 1</td>
|
||||
<td>1,2,4</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>NUM</td>
|
||||
<td>Generic numeric input; hex or binary number must be indicated</td>
|
||||
<td>$, %, 0 through 9, A through F</td>
|
||||
<td>1,3,4</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>SNUM</td>
|
||||
<td>Similar to NUM with value treated as signed with range -32768 to +32767</td>
|
||||
<td>-, $, %, 0 through 9, A through F</td>
|
||||
<td>1,2,3,4</td>
|
||||
</tr>
|
||||
</table>
|
||||
<ol>
|
||||
<li value="1">All numeric conversions will continue to accept new data until receiving
|
||||
either the specified number of digits (ex: three digits for DEC3) or a
|
||||
non-numeric character.</li>
|
||||
<li value="2">To be recognized as part of a number, the minus sign (-) must immediately
|
||||
precede a numeric character. The minus sign character occurring in non-numeric
|
||||
text is ignored and any character (including a space) between a minus and a
|
||||
number causes the minus to be ignored.</li>
|
||||
<li value="3">The hexadecimal formatters are not case-sensitive; "a" through "f" means
|
||||
the same as "A" through "F".</li>
|
||||
<li value="4">Indicated hexadecimal and binary formatters ignore all characters, even
|
||||
valid numerics, until they receive the appropriate prefix ($ for hexadecimal,
|
||||
% for binary). The indicated formatters can differentiate between text and
|
||||
hexadecimal (ex: ABC would be interpreted by HEX as a number but IHEX would
|
||||
ignore it unless expressed as $ABC). Likewise, the binary version can
|
||||
distinguish the decimal number 10 from the binary number %10. A prefix
|
||||
occurring in non-numeric text is ignored, and any character (including a space)
|
||||
between a prefix and a number causes the prefix to be ignored. Indicated, signed
|
||||
formatters require that the minus sign come before the prefix, as in -$1B45.</li>
|
||||
</ol>
|
||||
<h3>The 1-Wire Protocol Format</h3>
|
||||
<p class="PlainText">The 1-Wire protocol has a well-defined standard for transaction
|
||||
sequences. Every transaction sequence consists of four parts: 1) Initialization, 2)
|
||||
ROM Function Command, 3) Memory Function Command, and 4) Transaction/Data.
|
||||
Additionally, the ROM Function Command and Memory Function Command are always 8
|
||||
bits wide (1 byte in size) and is sent least-significant-bit (LSB) first.</p>
|
||||
<p>The Initialization part consists of a reset pulse (generated by the master)
|
||||
and will be followed by a presence pulse (generated by all slave devices). The
|
||||
figure below details the reset pulse generated by the BASIC Stamp and a typical
|
||||
presence pulse generated by a 1-Wire slave, in response.</p>
|
||||
<center>
|
||||
<img src="../../graphics/ow_pulses.gif" border="0">
|
||||
</img>
|
||||
</center>
|
||||
<p> </p>
|
||||
<p class="PlainText">This reset pulse is controlled by the lowest two bits of the <i>Mode</i> argument
|
||||
in the <span class="keyword_in_text">OWIN</span> command. It can be made to appear before the ROM Function
|
||||
Command (ex: Mode = 1), after the Transaction/Data portion (ex: Mode = 2), before
|
||||
and after the entire transaction (ex: Mode = 3) or not at all (ex: Mode = 0).
|
||||
See the section on <i>Mode</i>, above, for more information.</p>
|
||||
<p class="PlainText">Following the Initialization part is the ROM Function Command. The ROM Function
|
||||
Command is used to address the desired 1-Wire device. The table
|
||||
below shows common ROM Function Commands. If only a single 1-Wire
|
||||
device is connected, the Skip ROM command can be used to address it. If more than
|
||||
one 1-Wire device is attached, the BASIC Stamp will ultimately have
|
||||
to address them individually using the Match ROM command.</p>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF" align="center" valign="top">
|
||||
<td width="100">Command</td>
|
||||
<td width="100">Value (HEX)</td>
|
||||
<td>Action</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">Read ROM</td>
|
||||
<td align="center">$33</td>
|
||||
<td>Reads the 64-bit ID of the 1-Wire device. This command
|
||||
can only be used if there is a single 1-Wire device on the
|
||||
line.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">Match ROM</td>
|
||||
<td align="center">$55</td>
|
||||
<td>This command, followed by a 64-bit ID, allows the BASIC Stamp to address
|
||||
a specific 1-Wire device.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">Skip ROM</td>
|
||||
<td align="center">$CC</td>
|
||||
<td>Address a 1-Wire device without its 64-bit ID. This
|
||||
command can only be used if there is a single 1-Wire device
|
||||
on the line.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">Search ROM</td>
|
||||
<td align="center">$F0</td>
|
||||
<td>Reads the 64-bit IDs of all the 1-Wire devices on the
|
||||
line. A process of elimination is used to distinguish each unique device.</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p> </p>
|
||||
<p class="PlainText">The third part, the Memory Function Command, allows the BASIC Stamp to address
|
||||
specific memory locations, or features, of the 1-Wire device.
|
||||
Refer to the 1-Wire device's data sheet for a list of the available
|
||||
Memory Function Commands.</p>
|
||||
<p class="PlainText">Finally, the Transaction/Data section is used to read or write data to the
|
||||
1-Wire device. The <span class="keyword_in_text">OWIN</span> command will read data at this
|
||||
point in the transaction. A read is accomplished by generating a brief low-pulse
|
||||
and sampling the line within 15 ms of the falling edge of the pulse. This is called
|
||||
a "Read Slot." The figure below shows typical Read Slots performed by the BASIC
|
||||
Stamp. See the <a href="OWOUT.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">OWOUT</a> command for information on Write Slots.</p>
|
||||
<center>
|
||||
<img src="../../graphics/ow_readslots.gif" border="0" />
|
||||
</center>
|
||||
<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>
|
401
help/BasicStampHelp/Content/LanguageTopics/Commands/OWOUT.htm
Normal file
401
help/BasicStampHelp/Content/LanguageTopics/Commands/OWOUT.htm
Normal file
@ -0,0 +1,401 @@
|
||||
<?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>OWOUT</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">OWOUT</h1>
|
||||
<div class="ImagePlusCaption">
|
||||
<div class="Col2">
|
||||
<p>
|
||||
<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/OwinOwoutEx.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">OWIN / OWOUT Example</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: <span class="keyword_in_text">OWOUT</span> <![CDATA[ ]]><i>Pin</i>,<i> Mode</i>, [<i>OutputData</i>]</p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Send data to a device using the Maxim/Dallas Semiconductor 1-Wire<sup>®</sup>protocol.</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Pin</i></b> is a variable/constant/expression (0 - 15) that specifies
|
||||
which I/O pin to use. 1-Wire devices require only one I/O
|
||||
pin (called DQ) to communicate. This I/O pin will be toggled between output
|
||||
and input mode during the <span class="keyword_in_text">OWOUT</span> command and will be set to input mode
|
||||
by the end of the <span class="keyword_in_text">OWOUT</span> command.</li>
|
||||
<li value="2"><b><i>Mode</i></b> is a variable/constant/expression (0 - 15) indicating
|
||||
the mode of data transfer. The <i>Mode</i> argument controls placement of
|
||||
reset pulses (and detection of presence pulses) as well as byte vs. bit input
|
||||
and normal vs. high<sup>†</sup> speed. See explanation below.</li>
|
||||
<li value="3"><b><i>OutputData</i></b> is a list of variables and modifiers that tells
|
||||
<span class="keyword_in_text">OWOUT</span> how to format outgoing data. <span class="keyword_in_text">OWOUT</span> can transmit individual
|
||||
or repeating bytes, convert values into decimal, hexadecimal or binary text
|
||||
representations, or transmit strings of bytes from variable arrays. These
|
||||
actions can be combined in any order in the <i>OutputData</i> list.</li>
|
||||
</ul>
|
||||
<h2>Quick Facts</h2>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF">
|
||||
<td width="20%" align="center"> </td>
|
||||
<td width="80%" align="center">BS2p, BS2pe, and BS2px</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Transmission Rate</td>
|
||||
<td>Approximately 20 kbits/sec (low speed, not including reset pulse)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Special Notes</td>
|
||||
<td>The DQ pin (specified by <i>Pin</i>) must have a 4.7 kΩ pull-up
|
||||
resister.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
||||
<td align="center" colspan="1">
|
||||
<p colspan="1" align="center"><a href="OWIN.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">OWIN</a>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText">The 1-Wire protocol is a form of asynchronous serial communication developed by
|
||||
Maxim/Dallas Semiconductor. It only requires one I/O pin and that pin can
|
||||
be shared between multiple 1-Wire devices. The <span class="keyword_in_text">OWOUT</span>
|
||||
command allows the BASIC Stamp to send data to a 1-Wire device.</p>
|
||||
<p class="PlainText">The following is an example of the <span class="keyword_in_text">OWOUT</span> command:</p><pre class="BScode" xml:space="preserve">
|
||||
OWOUT 0, 1, [$4E]
|
||||
</pre>
|
||||
<p class="PlainText">This code will transmit a "reset" pulse to a 1-Wire device
|
||||
(connected to I/O pin 0) and then will detect the device's "presence" pulse and
|
||||
then transmit one byte (the value $4E).</p>
|
||||
<p class="PlainText">The <i>Mode</i> argument is used to control placement of reset pulses (and
|
||||
detection of presence pulses) and to designate byte vs. bit input and normal vs.
|
||||
high speed<sup>†</sup>. The tables below show the meaning of each of the
|
||||
four bits of <i>Mode</i> and some of the 16 possible values and their effect. </p>
|
||||
<table align="center" width="35%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF">
|
||||
<td width="50" style="text-align: center;">Bit</td>
|
||||
<td width="200" style="text-align: center;">Function</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td bgcolor="#CFCFCF" style="text-align: center;">0</td>
|
||||
<td style="text-align: left;">Front-End Reset<br></br>• 0 = No reset <br></br>• 1 = Generate reset
|
||||
before data</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td bgcolor="#CFCFCF" style="text-align: center;">1</td>
|
||||
<td style="text-align: left;">Back-End Reset<br></br>• 0 = No reset <br></br>• 1 = Generate reset
|
||||
after data</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td bgcolor="#CFCFCF" style="text-align: center;">2</td>
|
||||
<td style="text-align: left;">Bit / Byte Transfer<br></br>• 0 = Byte <br></br>• 1 = Bit</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td bgcolor="#CFCFCF" style="text-align: center;">3</td>
|
||||
<td style="text-align: left;">Low / High Speed<sup>†</sup><br></br>• 0 = Low <br></br>• 1 = High</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p> </p>
|
||||
<table width="35%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF" align="center">
|
||||
<td width="50">Mode</td>
|
||||
<td>Effect</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">0</td>
|
||||
<td>No Reset, Byte mode, Low speed</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">1</td>
|
||||
<td>Reset before data, Byte mode, Low speed</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">2</td>
|
||||
<td>Reset after data, Byte mode, Low speed</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">3</td>
|
||||
<td>Reset before and after data, Byte mode, Low speed</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">4</td>
|
||||
<td>No Reset, Bit mode, Low speed</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">5</td>
|
||||
<td>Reset before data, Bit mode, Low speed</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">6</td>
|
||||
<td>Reset after data, Bit mode, Low speed</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">7</td>
|
||||
<td>Reset before and after data, Bit mode, Low speed</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">8</td>
|
||||
<td>No Reset, Byte mode, High speed<sup>†</sup></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">9</td>
|
||||
<td>Reset before data, Byte mode, High speed<sup>†</sup></td>
|
||||
</tr>
|
||||
</table>
|
||||
<p><sup>†</sup> The BS2pe is not capable of High Speed transfers.</p>
|
||||
<p> </p>
|
||||
<p class="PlainText">The proper value for <i>Mode</i> depends on the 1-Wire device
|
||||
and the portion of the communication you're working on. Please consult the data
|
||||
sheet for the device in question to determine the correct value for <i>Mode</i>.
|
||||
In many cases, however, when using the <span class="keyword_in_text">OWOUT</span> command, <i>Mode</i> should
|
||||
be set for a Front-End Reset (to initialize the transaction). This may vary due
|
||||
to device and application requirements, however.</p>
|
||||
<p class="PlainText">When using the Bit (rather than Byte) mode of data transfer, all variables in
|
||||
the <i>OutputData</i> argument will only transmit one bit. For example, the
|
||||
following code could be used to send two bits using this mode:</p><pre class="BScode" xml:space="preserve">
|
||||
bitOne VAR Bit
|
||||
bitTwo VAR Bit
|
||||
|
||||
Init:
|
||||
bitOne = 0
|
||||
bitTwo = 1
|
||||
|
||||
Main:
|
||||
OWOUT 0, 5, [bitOne, bitTwo]
|
||||
STOP
|
||||
</pre>
|
||||
<p class="PlainText">In the code above, we chose the value "5" for <i>Mode</i>. This sets Bit transfer
|
||||
and Front-End Reset modes. Also, we could have chosen to make the bitOne and
|
||||
bitTwo variables each a byte in size, but the BASIC Stamp would still only use the
|
||||
their lowest bit (Bit0) as the value to transmit in the <span class="keyword_in_text">OWOUT</span> command (due
|
||||
to the <i>Mode</i> we chose).</p>
|
||||
<p class="PlainText">The <span class="keyword_in_text">OWOUT</span> command's <i>OutputData</i> argument is similar to the <b>DEBUG</b>
|
||||
and <b>SEROUT</b> command's <i>OutputData</i> argument. This means data can be
|
||||
sent as literal text, ASCII character values, repetitive values, decimal, hexadecimal
|
||||
and binary translations and string data as in the examples below.</p><pre class="BScode" xml:space="preserve">
|
||||
value VAR Byte
|
||||
|
||||
Init:
|
||||
value = 65
|
||||
|
||||
Main:
|
||||
OWOUT 0, 1, [value] ' send ASCII character "A"
|
||||
OWOUT 0, 1, [REP value\5] ' send "A" 5x, ie: "AAAAA"
|
||||
OWOUT 0, 1, [DEC value] ' send "6" and "5"
|
||||
OWOUT 0, 1, [HEX value] ' send "4" and "1"
|
||||
OWOUT 0, 1, [BIN value] ' send "1000001"
|
||||
STOP
|
||||
</pre>
|
||||
<p class="PlainText">The tables below list all the available special formatters and conversion
|
||||
formatters available to the <span class="keyword_in_text">OWOUT</span> command. See the <a href="DEBUG.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">DEBUG</a>
|
||||
  and <a href="SEROUT.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">SEROUT</a> commands
|
||||
for additional information and examples of their use.</p>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF" align="center" valign="top">
|
||||
<td width="20%">Special Formatter</td>
|
||||
<td width="80%">Action</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">?</td>
|
||||
<td>Displays "symbol = x' + carriage return; where x is a number. Default
|
||||
format is decimal, but may be combined with conversion formatters (ex: BIN
|
||||
? x to display "x = binary_number").</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">ASC ?</td>
|
||||
<td>Displays "symbol = 'x'" + carriage return; where x is an ASCII
|
||||
character.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">STR ByteArray {\L}</td>
|
||||
<td>Send character string from an array. The optional \L argument can be
|
||||
used to limit the output to L characters, otherwise, characters will be
|
||||
sent up to the first byte equal to 0 r the end of RAM space is reached.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">REP Byte\L</td>
|
||||
<td>Send a string consisting of Byte repeated L times (ex: REP "X"\10 sends
|
||||
"XXXXXXXXXX").</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p> </p>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF" align="center" valign="top">
|
||||
<td width="20%">Conversion Formatter</td>
|
||||
<td width="70%">Type of Number</td>
|
||||
<td width="10%">Notes</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>DEC{1..5}</td>
|
||||
<td align="left">Decimal, optionally fixed to 1 - 5 digits</td>
|
||||
<td>1</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>SDEC{1..5}</td>
|
||||
<td align="left">Signed decimal, optionally fixed to 1 - 5 digits</td>
|
||||
<td>1,2</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>HEX{1..4}</td>
|
||||
<td align="left">Hexadecimal, optionally fixed to 1 - 4 digits</td>
|
||||
<td>1</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>SHEX{1..4}</td>
|
||||
<td align="left">Signed hexadecimal, optionally fixed to 1 - 4 digits </td>
|
||||
<td>1,2</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>IHEX{1..4}</td>
|
||||
<td align="left">Indicated hexadecimal, optionally fixed to 1 - 4 digits</td>
|
||||
<td>1</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>ISHEX{1..4}</td>
|
||||
<td align="left">Signed, indicated hexadecimal, optionally fixed to 1 - 4
|
||||
digits ($ prefix)</td>
|
||||
<td>1,2</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>BIN{1..16}</td>
|
||||
<td align="left">Binary, optionally fixed to 1 - 16 digits</td>
|
||||
<td>1</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>SBIN{1..16}</td>
|
||||
<td align="left">Signed binary, optionally fixed to 1 - 16 digits</td>
|
||||
<td>1,2</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>IBIN{1..16}</td>
|
||||
<td align="left">Indicated binary, optionally fixed to 1 - 16 digits</td>
|
||||
<td>1</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td>ISBIN{1..16}</td>
|
||||
<td align="left">Signed, indicated binary, optionally fixed to 1 - 16 digits</td>
|
||||
<td>1,2</td>
|
||||
</tr>
|
||||
</table>
|
||||
<ol>
|
||||
<li value="1">Fixed-digit formatters like DEC4 will pad the number with leading 0s if
|
||||
necessary; ex: DEC4 65 sends 0065. If a number is larger than the specified
|
||||
number of digits, the leading digits will be dropped; ex: DEC4 56422 sends
|
||||
6422.</li>
|
||||
<li value="2">Signed modifiers work under two's complement rules.</li>
|
||||
</ol>
|
||||
<h3>The 1-Wire Protocol Format</h3>
|
||||
<p class="PlainText">The 1-Wire protocol has a well-defined standard for transaction
|
||||
sequences. Every transaction sequence consists of four parts: 1) Initialization,
|
||||
2) ROM Function Command, 3) Memory Function Command, and 4) Transaction/Data.
|
||||
Additionally, the ROM Function Command and Memory Function Command are always 8
|
||||
bits wide (1 byte in size) and is sent least-significant-bit (LSB) first.
|
||||
</p>
|
||||
<p class="PlainText">The Initialization part consists of a reset pulse (generated by the master)
|
||||
and will be followed by a presence pulse (generated by all slave devices). The
|
||||
figure below details the reset pulse generated by the BASIC Stamp and a typical
|
||||
presence pulse generated by a 1-Wire slave, in response.</p>
|
||||
<center>
|
||||
<img src="../../graphics/ow_pulses.gif" width="389" height="223" border="0">
|
||||
</img>
|
||||
</center>
|
||||
<p> </p>
|
||||
<p class="PlainText">This reset pulse is controlled by the lowest two bits of the <i>Mode</i>
|
||||
argument in the <span class="keyword_in_text">OWIN</span> command. It can be made to appear before the ROM
|
||||
Function Command (ex: Mode = 1), after the Transaction/Data portion (ex: Mode
|
||||
= 2), before and after the entire transaction (ex: Mode = 3) or not at all (ex:
|
||||
Mode = 0). See the section on <i>Mode</i>, above, for more information.</p>
|
||||
<p class="PlainText">Following the Initialization part is the ROM Function Command. The ROM Function
|
||||
Command is used to address the desired 1-Wire device. The table
|
||||
below shows common ROM Function Commands. If only a single 1-Wire
|
||||
device is connected, the Match ROM command can be used to address it. If more than
|
||||
one 1-Wire device is attached, the BASIC Stamp will ultimately
|
||||
have to address them individually using the Match ROM command.</p>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF" align="center" valign="top">
|
||||
<td width="100">Command</td>
|
||||
<td width="100">Value (HEX)</td>
|
||||
<td>Action</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">Read ROM</td>
|
||||
<td align="center">$33</td>
|
||||
<td>Reads the 64-bit ID of the 1-Wire device. This command
|
||||
can only be used if there is a single 1-Wire device on the
|
||||
line.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">Match ROM</td>
|
||||
<td align="center">$55</td>
|
||||
<td>This command, followed by a 64-bit ID, allows the BASIC Stamp to address
|
||||
a specific 1-Wire device.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">Skip ROM</td>
|
||||
<td align="center">$CC</td>
|
||||
<td>Address a 1-Wire device without its 64-bit ID. This
|
||||
command can only be used if there is a single 1-Wire device
|
||||
on the line.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">Search ROM</td>
|
||||
<td align="center">$F0</td>
|
||||
<td>Reads the 64-bit IDs of all the 1-Wire devices on the
|
||||
line. A process of elimination is used to distinguish each unique device.</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p> </p>
|
||||
<p class="PlainText">The third part, the Memory Function Command, allows the BASIC Stamp to address
|
||||
specific memory locations, or features, of the 1-Wire device.
|
||||
Refer to the 1-Wire device's data sheet for a list of the available
|
||||
Memory Function Commands.</p>
|
||||
<p class="PlainText">Finally, the Transaction/Data section is used to read or write data to the
|
||||
1-Wire device. The <span class="keyword_in_text">OWOUT</span> command will write data at this
|
||||
point in the transaction. A write is accomplished by generating a low-pulse of
|
||||
a varying width to indicate a 0 or a 1. This is called a "Write Slot" and must be
|
||||
at least 60 us wide. The figure below shows typical Write Slots performed by the
|
||||
BASIC Stamp. See the <a href="OWIN.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">OWIN</a> command for information on Read
|
||||
Slots.</p>
|
||||
<center>
|
||||
<img src="../../graphics/ow_writeslots.gif" border="0" />
|
||||
</center>
|
||||
<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,87 @@
|
||||
<?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>PAUSE</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">PAUSE</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" /><span class="code_in_text"> {PBASIC 2.5}</span>
|
||||
</p>
|
||||
</div>
|
||||
<p style="text-align: right;"><a href="../ExampleTopics/PauseEx.htm" target="" title="" alt="" class="MCXref_0">PAUSE Example</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: <span class="keyword_in_text">PAUSE</span> <![CDATA[ ]]><i>Duration</i></p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Pause the program (do nothing) for the specified <i>Duration</i>.
|
||||
|
||||
</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Duration</i></b> is a variable/constant/expression* (0 - 65535) that
|
||||
specifies the duration of the pause. The unit of time for <i>Duration</i> is
|
||||
one millisecond. </li>
|
||||
</ul>
|
||||
<p class="PlainText">*<img src="../../graphics/bs1note.gif" style="vertical-align: super;" /> Note: expressions are not allowed as arguments on the BS1.</p>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText"><span class="keyword_in_text">PAUSE</span> delays the execution of the next program instruction for the specified
|
||||
number of milliseconds. For example: </p><pre class="BScode" xml:space="preserve">
|
||||
Flash:
|
||||
  LOW 0
|
||||
 PAUSE 100
|
||||
  HIGH 0
|
||||
 PAUSE 100
|
||||
 GOTO Flash
|
||||
</pre>
|
||||
<p class="PlainText">This code causes pin 0 to go low for 100 ms, then high for 100 ms. The delays
|
||||
produced by <span class="keyword_in_text">PAUSE</span> are as accurate as the ceramic-resonator time base (on
|
||||
the BASIC Stamp modules), ±1 percent. When you use <span class="keyword_in_text">PAUSE</span> in timing-critical
|
||||
applications, keep in mind the relatively low speed of the PBASIC interpreter.
|
||||
This is the time required for the BASIC Stamp to read and interpret an instruction
|
||||
stored in the EEPROM. </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>
|
245
help/BasicStampHelp/Content/LanguageTopics/Commands/POLLIN.htm
Normal file
245
help/BasicStampHelp/Content/LanguageTopics/Commands/POLLIN.htm
Normal file
@ -0,0 +1,245 @@
|
||||
<?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>POLLIN</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">POLLIN</h1>
|
||||
<div class="ImagePlusCaption">
|
||||
<div class="Col2">
|
||||
<p>
|
||||
<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/PollinOutEx.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">POLLIN / POLLOUT / POLLMODE Example</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: <span class="keyword_in_text">POLLIN</span> <![CDATA[ ]]><i>Pin, State</i></p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Specify a polled-input pin and active state.
|
||||
|
||||
</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Pin</i></b> is a variable/constant/expression (0 - 15) that specifies
|
||||
the I/O pin to use. This I/O pin will be set to input mode.</li>
|
||||
<li value="2"><b><i>State</i></b> is a variable/constant/expression (0 - 1) that specifies
|
||||
whether to poll the I/O pin for a low (0) or a high (1) level.</li>
|
||||
</ul>
|
||||
<h2>Quick Facts</h2>
|
||||
<table cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF">
|
||||
<td width="150" align="center"> </td>
|
||||
<td width="1000" align="center">BS2p, BS2pe, and BS2px</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Available actions in response to reaching
|
||||
the desired <i>State</i></td>
|
||||
<td align="left">
|
||||
<ol>
|
||||
<li value="1">Nothing,</li>
|
||||
<li value="2">Set polled-output pins to a specified state,</li>
|
||||
<li value="3">Run another program (in a specified program-slot),</li>
|
||||
<li value="4">Wait (pause program execution) until desired State is reached,</li>
|
||||
<li value="5">Any combination of 2, 3 and 4, above.</li>
|
||||
</ol>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Special Notes</td>
|
||||
<td align="left">
|
||||
<ul>
|
||||
<li value="1">The polled-input pins are monitored (polled) in-between each command
|
||||
within the PBASIC code.</li>
|
||||
<li value="2">On the BS2p40 polled-input pins can be defined on both main and
|
||||
auxiliary I/O pins. These are all active regardless of which group
|
||||
the program happens to be using at the time of a polling event.</li>
|
||||
<li value="3">Polled input pins are stored in special Scratchpad RAM locations. Use
|
||||
<a href="GET.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">GET</a> to retrieve.<br /><ul type="square"><li value="1">Location 128 : MAINIO Pins 0 - 7</li><li value="2">Location 129 : MAINIO Pins 8 - 15</li><li value="3">Location 130 : AUXIO Pins 0 - 7</li><li value="4">Location 131 : AUXIO Pins 8 - 15</li></ul></li>
|
||||
</ul>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
||||
<td align="center" colspan="1">
|
||||
<p colspan="1" align="center"><a href="POLLMODE.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">POLLMODE</a>, <a href="POLLOUT.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">POLLOUT</a>, <a href="POLLRUN.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">POLLRUN</a>, <a href="POLLWAIT.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">POLLWAIT</a></p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText">The <span class="keyword_in_text">POLLIN</span> command is one of a family of unique "polling" commands on the
|
||||
BS2p, BS2pe, and BS2px modules. The other commands in this family include <span class="keyword_in_text">POLLMODE</span>,
|
||||
<span class="keyword_in_text">POLLOUT</span>, <span class="keyword_in_text">POLLRUN</span> and <span class="keyword_in_text">POLLWAIT</span>. The <span class="keyword_in_text">POLLIN</span> command
|
||||
is used to specify an input pin to monitor, or "poll", in-between instructions
|
||||
during the rest of the PBASIC program. The BASIC Stamp will then perform some
|
||||
activity (in between instructions) when the specified State is detected. The
|
||||
activity performed depends on the <span class="keyword_in_text">POLLMODE</span>, <span class="keyword_in_text">POLLOUT</span> and <span class="keyword_in_text">POLLRUN</span>commands.</p>
|
||||
<p class="PlainText">The "polling" commands allow the BASIC Stamp to respond to certain I/O pin
|
||||
events at a faster rate than what is normally possible through manual PBASIC
|
||||
programming. The term "poll" comes from the fact that the BASIC Stamp's interpreter
|
||||
periodically checks the state of the designated polled-input pins. It "polls"
|
||||
these pins after the end of each PBASIC instruction and before it reads the next
|
||||
PBASIC instruction from the user program; giving the appearance that it is polling
|
||||
"in the background". </p>
|
||||
<p class="PlainText">This feature should not be confused with the concept of interrupts, as
|
||||
<i><b>the BASIC Stamp does not support true interrupts.</b></i></p>
|
||||
<p class="PlainText">The following is an example of the <span class="keyword_in_text">POLLIN</span> command:</p><pre class="BScode" xml:space="preserve">
|
||||
POLLIN 0, 0
|
||||
POLLMODE 2
|
||||
</pre>
|
||||
<p class="PlainText">The <span class="keyword_in_text">POLLIN</span> command in the above code will cause the BASIC Stamp to set
|
||||
I/O pin 0 to an input mode and get ready to poll it for a low (0) state. The
|
||||
BASIC Stamp will not actually start polling until it is set to the appropriate
|
||||
mode, however. The second line, <span class="keyword_in_text">POLLMODE</span>, initiates the polling process
|
||||
(see the <a href="POLLMODE.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">POLLMODE</a> description for more information).
|
||||
From then on, as the BASIC Stamp executes the rest of the program, it will check
|
||||
for a low level (logic 0) on I/O pin 0, in-between instructions. </p>
|
||||
<p class="PlainText">In the code above, no obvious action will be noticed since we didn't tell the
|
||||
BASIC Stamp what to do when it detects a change on the I/O pin. One possible
|
||||
action the BASIC Stamp can be instructed to take is to change the state of an
|
||||
output, called a polled-output. Take a look at the next example:</p><pre class="BScode" xml:space="preserve">
|
||||
Setup:
|
||||
POLLIN 0, 0
|
||||
POLLOUT 1, 1
|
||||
POLLMODE 2
|
||||
|
||||
Main
|
||||
DEBUG "Looping...", CR
|
||||
GOTO Main
|
||||
</pre>
|
||||
<p class="PlainText">In this example, in addition to an endless loop, we've added another polling
|
||||
command called <span class="keyword_in_text">POLLOUT</span> (see the <a href="POLLOUT.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">POLLOUT</a> description
|
||||
for more information). Our <span class="keyword_in_text">POLLOUT</span> command tells the BASIC Stamp to set
|
||||
I/O pin 1 to an output mode and set it high (1) when it detects the desired poll
|
||||
state. The poll state is the low (0) level on I/O pin 0 that <span class="keyword_in_text">POLLIN</span> told
|
||||
it to look for. If the polled-input pin is high, it will set polled-output
|
||||
pin 1 to low (0), instead.</p>
|
||||
<p class="PlainText">Once the program reaches the endless loop, starting at Main, it will continuously
|
||||
print "Looping..." on the PC screen. In between reading the <span class="keyword_in_text">DEBUG</span> command
|
||||
and the <span class="keyword_in_text">GOTO</span> command (and vice versa) it will check polled-input pin 0 and
|
||||
set polled-output pin 1 accordingly. In this case, when I/O pin 0 is set low,
|
||||
the BASIC Stamp will set I/O pin 1 high. When I/O pin 0 is set high, the BASIC
|
||||
Stamp will set I/O pin 1 low. It will continue to perform this operation,
|
||||
in-between each command in the loop, endlessly.</p>
|
||||
<p>It's important to note that, in this example, only the <span class="keyword_in_text">DEBUG</span> and <span class="keyword_in_text">GOTO</span>commands are being executed over and over again. The first three lines of code
|
||||
are only run once, yet their effects are "remembered" by the BASIC Stamp throughout
|
||||
the rest of the program.</p>
|
||||
<p>If the polling commands were not used, the program would have to look like the
|
||||
one below in order to achieve the same effect.</p><pre class="BScode" xml:space="preserve">
|
||||
Setup:
|
||||
INPUT 0
|
||||
OUTPUT 1
|
||||
|
||||
Main:
|
||||
OUT1 = ~IN0
|
||||
DEBUG "Looping...", CR
|
||||
OUT1 = ~IN0
|
||||
GOTO Main
|
||||
</pre>
|
||||
<p class="PlainText">In this example, we create the inverse relationship of input pin 0 and output
|
||||
pin 1 manually, in-between the <span class="keyword_in_text">DEBUG</span> and <span class="keyword_in_text">GOTO</span> lines. Though the
|
||||
effects are the same as when using the polling commands, this program actually
|
||||
takes a little longer to run and consumes 7 additional bytes of program (EEPROM)
|
||||
space. Clearly, using the polling commands is more efficient.</p>
|
||||
<p class="PlainText">You can have as many polled-input and polled-output pins as you have available.
|
||||
If multiple polled-input pins are defined, any one of them can trigger changes on
|
||||
the polled-output pins that are also defined. For example:</p><pre class="BScode" xml:space="preserve">
|
||||
Setup:
|
||||
POLLIN 0, 1
|
||||
POLLIN 1, 1
|
||||
POLLOUT 2, 1
|
||||
POLLMODE 2
|
||||
|
||||
Main:
|
||||
DEBUG "Looping...", CR
|
||||
GOTO Main
|
||||
</pre>
|
||||
<p class="PlainText">This code sets I/O pins 0 and 1 to polled-input pins (looking for a high (1)
|
||||
state) and sets I/O pin 2 to be a polled-output pin (with a high-active state).
|
||||
If either I/O pin 0 or 1 goes high, the BASIC Stamp will set I/O pin 2 high.
|
||||
This works similar to a logical OR operation. The truth table below shows all the
|
||||
possible states of these two polled-input pins and the corresponding states the
|
||||
BASIC Stamp will set the polled-output pin to.</p>
|
||||
<center>
|
||||
<table width="200" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF">
|
||||
<td colspan="2" align="center">Polled-Inputs</td>
|
||||
<td colspan="1" align="center">Polled-Output</td>
|
||||
</tr>
|
||||
<tr bgcolor="#CFCFCF">
|
||||
<td width="50" align="center">0</td>
|
||||
<td width="50" align="center">1</td>
|
||||
<td width="100" align="center">2</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">0</td>
|
||||
<td align="center">0</td>
|
||||
<td align="center">0</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">0</td>
|
||||
<td align="center">1</td>
|
||||
<td align="center">1</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">1</td>
|
||||
<td align="center">0</td>
|
||||
<td align="center">1</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">1</td>
|
||||
<td align="center">1</td>
|
||||
<td align="center">1</td>
|
||||
</tr>
|
||||
</table>
|
||||
</center>
|
||||
<p> </p>
|
||||
<p class="PlainText">Normally, any polled-output pins reflect the state changes continuously, as
|
||||
described above. The <span class="keyword_in_text">POLLMODE</span> command supports another feature, however,
|
||||
where the polled-output pins will latch the active state; they will change only
|
||||
once (when the poll state is reached) and stay in the new state until the PBASIC
|
||||
program tells it to change again. See the
|
||||
<a href="POLLMODE.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">POLLMODE</a> description for more information.</p>
|
||||
<p class="PlainText">Other possible actions in response to polled-input states are: 1) Running
|
||||
another program (in a specified program slot), 2) Waiting (pausing program
|
||||
execution with or without low-power mode) until the poll state is reached, or 3)
|
||||
Any combination of the above-mentioned actions</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>
|
270
help/BasicStampHelp/Content/LanguageTopics/Commands/POLLMODE.htm
Normal file
270
help/BasicStampHelp/Content/LanguageTopics/Commands/POLLMODE.htm
Normal file
@ -0,0 +1,270 @@
|
||||
<?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>POLLMODE</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">POLLMODE</h1>
|
||||
<div class="ImagePlusCaption">
|
||||
<div class="Col2">
|
||||
<p>
|
||||
<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/PollinOutEx.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">POLLIN / POLLOUT / POLLMODE Example</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: <span class="keyword_in_text">POLLMODE</span> <![CDATA[ ]]><i>Mode</i></p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Specify a polled command mode.</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Mode</i></b> is a variable/constant/expression (0 - 15) that indicates
|
||||
the mode in which to process the polled command configuration.</li>
|
||||
</ul>
|
||||
<h2>Quick Facts</h2>
|
||||
<table cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF">
|
||||
<td width="150" align="center"> </td>
|
||||
<td width="1000" align="center">BS2p, BS2pe, and BS2px</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Special Notes</td>
|
||||
<td align="left">
|
||||
<ul>
|
||||
<li value="1">Polled-output pins will either change states continuously, just once
|
||||
or not at all, depending on the <span class="keyword_in_text">POLLMODE</span> command</li>
|
||||
<li value="2">A poll mode of 2 or 4 is required for a <span class="keyword_in_text">POLLWAIT</span> command
|
||||
to work</li>
|
||||
<li value="3">If both polled-outputs and polled-run are active, the polled-output
|
||||
event will occur before the polled-run event.</li>
|
||||
</ul>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
||||
<td align="center" colspan="1">
|
||||
<p colspan="1" align="center"><a href="POLLIN.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">POLLIN</a>, <a href="POLLOUT.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">POLLOUT</a>, <a href="POLLRUN.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">POLLRUN</a>, <a href="POLLWAIT.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">POLLWAIT</a></p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText">The <span class="keyword_in_text">POLLMODE</span> command is one of a family of unique "polling" commands on the
|
||||
BS2p, BS2pe, and BS2px modules. The other commands in this family include <span class="keyword_in_text">POLLIN</span>,
|
||||
<span class="keyword_in_text">POLLOUT</span>, <span class="keyword_in_text">POLLRUN</span> and <span class="keyword_in_text">POLLWAIT</span>. The <span class="keyword_in_text">POLLMODE</span> command
|
||||
is used to specify the mode in which polling events and activities are processed.
|
||||
This activity will occur in between instructions during the rest of the PBASIC
|
||||
program.</p>
|
||||
<p class="PlainText">The "polling" commands allow the BASIC Stamp to respond to certain I/O pin events
|
||||
at a faster rate than what is normally possible through manual PBASIC programming.
|
||||
The term "poll" comes from the fact that the BASIC Stamp's interpreter periodically
|
||||
checks the state of the designated polled-input pins. It "polls" these pins after
|
||||
the end of each PBASIC instruction and before it reads the next PBASIC instruction
|
||||
from the user program; giving the appearance that it is polling "in the
|
||||
background".</p>
|
||||
<p class="PlainText">This feature should not be confused with the concept of interrupts, as <i><b>the
|
||||
BASIC Stamp does not support true interrupts.</b></i></p>
|
||||
<p class="PlainText">The <span class="keyword_in_text">POLLMODE</span> command sets one of 15 possible modes for the polling
|
||||
commands. It is used mainly before and/or after any <span class="keyword_in_text">POLLIN</span>, <span class="keyword_in_text">POLLOUT</span>
|
||||
and <span class="keyword_in_text">POLLRUN</span> commands to disable and enable the polling features as desired.
|
||||
The table below shows the mode values and their effect.</p>
|
||||
<table cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF">
|
||||
<td width="150" align="center">Mode</td>
|
||||
<td width="1000" align="center">Effect</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">0</td>
|
||||
<td align="left">Deactivate polling, clear polled-input and output configuration.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">1</td>
|
||||
<td align="left">Deactivate polling, save polled-input and output configuration.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">2</td>
|
||||
<td align="left">Activate polling with polled-output action (and polled-wait) only.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">3<sup>1</sup></td>
|
||||
<td align="left">Activate polling with polled-run action only.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">4<sup>2</sup></td>
|
||||
<td align="left">Activate polling with polled-output/polled-wait and polled-run actions.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">5<sup>3</sup></td>
|
||||
<td align="left">Clear polled-input configuration.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">6<sup>3</sup></td>
|
||||
<td align="left">Clear polled-output configuration.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">7<sup>3</sup></td>
|
||||
<td align="left">Clear polled-input and output configuration.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">8 - 15</td>
|
||||
<td align="left">Same at 0 - 7 except polled-output states are latched.</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p> </p>
|
||||
<table width="100%" cellpadding="0" cellspacing="0" border="0">
|
||||
<tr>
|
||||
<td width="10"><sup>1</sup>
|
||||
</td>
|
||||
<td>After the polled-run action occurs, the mode switches to 1 (deactivated,
|
||||
saved)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="10"><sup>2</sup>
|
||||
</td>
|
||||
<td>After the polled-run action occurs, the mode switches to 2 (activated,
|
||||
outputs)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="10"><sup>3</sup>
|
||||
</td>
|
||||
<td>These modes do not override the previous mode. Also, the output state of
|
||||
polled-outputs does not change as a result of these modes.</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p> </p>
|
||||
<p class="PlainText">The polled-run modes, 3 and 4, are unique. As soon as the polled-run action
|
||||
occurs, the mode switches to 1 (deactivated, saved) or 2 (activated, outputs),
|
||||
respectively. This is so that the BASIC Stamp doesn't continuously go to the
|
||||
start of the designated program slot while the polled-inputs are in the desired
|
||||
poll state. Without this "one shot" feature, your program would appear to lock-up
|
||||
as long as the polled-inputs are in the designated state.</p>
|
||||
<p class="PlainText">The clear configuration modes, 5, 6 and 7, are also unique. These modes do not
|
||||
override the previous mode. For example, if polled-inputs, polled-outputs and a
|
||||
polled-run configuration was set and the mode was set to 4 (activated, outputs and
|
||||
run) and later the program issued a <span class="keyword_in_text">POLLMODE</span> 6 command, the polled-output
|
||||
configuration would be cleared but the mode would switch back to 4... still allowing
|
||||
the run action. This also means if, later still, the program issues a <span class="keyword_in_text">POLLOUT</span>
|
||||
command, this polled-output would take effect immediately (since the mode is still
|
||||
4). Also note that these modes do not change the output state of previously defined
|
||||
polled-output pins.</p>
|
||||
<p class="PlainText">The <span class="keyword_in_text">POLLMODE</span> command determines what action, if any, will occur in
|
||||
response to a polled-input event. This command works in conjunction with the
|
||||
<span class="keyword_in_text">POLLIN</span>, <span class="keyword_in_text">POLLOUT</span> and <span class="keyword_in_text">POLLRUN</span> commands. The following is an
|
||||
example of the <span class="keyword_in_text">POLLMODE</span> command:</p><pre class="BScode" xml:space="preserve">
|
||||
Setup:
|
||||
POLLIN 0, 0
|
||||
POLLOUT 1, 1
|
||||
POLLMODE 2
|
||||
Main:
|
||||
DEBUG "Looping...", CR
|
||||
GOTO Main
|
||||
</pre>
|
||||
<p>In this example, the first two lines configure I/O pin 0 as a polled-input
|
||||
(looking for a low state) and I/O pin 1 as a polled-output (going high if I/O pin
|
||||
0 goes low, and vice versa). The third line, <span class="keyword_in_text">POLLMODE</span>, initiates the
|
||||
polling process and configures polled-outputs to be active. From then on, as the
|
||||
BASIC Stamp executes the rest of the program, it will check for a low level
|
||||
(logic 0) on I/O pin 0 in between instructions and will set I/O pin 1 accordingly.</p>
|
||||
<p class="PlainText">If, in the above example, the poll mode was set to 1 (which means deactivate
|
||||
polling but save configuration) I/O pins 0 and 1 would still be defined the same
|
||||
way, and I/O pin 1 would still be set to output mode, but no polling would take
|
||||
place during the rest of the program.</p>
|
||||
<p class="PlainText">Here's another example that demonstrates mode 1 (deactivate but save
|
||||
configuration).</p><pre class="BScode" xml:space="preserve">
|
||||
Setup:
|
||||
POLLIN 0, 0
|
||||
POLLOUT 1, 1
|
||||
POLLMODE 2
|
||||
DEBUG "Polling configured", CR
|
||||
Main:
|
||||
POLLMODE 1
|
||||
DEBUG "No polling allowed here...", CR
|
||||
PAUSE 1000
|
||||
POLLMODE 2
|
||||
Poll_Now:
|
||||
DEBUG "Polling now...", CR
|
||||
GOTO Poll_Now
|
||||
</pre>
|
||||
<p class="PlainText">In this case, polling is configured and activated before "Polling configured"
|
||||
is printed on the screen. Once we reach the Main routine, however, polling is
|
||||
disabled (via the <span class="keyword_in_text">POLLMODE</span> 1 command) and no polling occurs during the
|
||||
printing of "No polling allowed here..." or during the 1 second pause afterward.
|
||||
Finally, polling is activated again, and since the configuration was saved (because
|
||||
of mode 1, before) the polling activity acts just like it did initially for the
|
||||
remainder of the program. The ability to temporarily disable polling, without
|
||||
changing the configuration, can be a powerful feature for certain "critical" parts
|
||||
of a program.</p>
|
||||
<p class="PlainText">The following example contains two programs. The first should be downloaded
|
||||
into program slot 0 and the second into program slot 1. We'll assume they are
|
||||
called POLL0.BSP and POLL1.BSP, respectively (as defined in the $STAMP directive
|
||||
lines). </p><pre class="BScode" xml:space="preserve">
|
||||
' ----- Program #1 (Slot 0) -----
|
||||
' {$STAMP BS2p, POLL1.BSP}
|
||||
Setup:
|
||||
POLLIN 0, 0
|
||||
POLLOUT 1, 1
|
||||
POLLRUN 1
|
||||
POLLMODE 4
|
||||
Main:
|
||||
DEBUG "Program 1", CR
|
||||
GOTO Main
|
||||
</pre><pre class="BScode" xml:space="preserve">
|
||||
' ----- Program #2 (Slot 1) -----
|
||||
' {$STAMP BS2p}
|
||||
DEBUG "Switching...", CR
|
||||
Again:
|
||||
DEBUG "Program 2", CR
|
||||
GOTO Again
|
||||
</pre>
|
||||
<p class="PlainText">In this example (containing two programs; one is slot 0 and the other in slot 1)
|
||||
program 1 (slot 0) will configure polled-input pin 0 to detect a low state and
|
||||
polled-output 1 to go high in response. Program 1 also configures a polled-run
|
||||
activity (see the <span class="keyword_in_text">POLLRUN</span> description for more information) to run the
|
||||
program in slot 1. The <span class="keyword_in_text">POLLMODE</span> setting activates the polled-output and
|
||||
the polled-run. Then, program 1 continuously prints "Program 1" on the PC screen.</p>
|
||||
<p class="PlainText">Once I/O pin 0 goes low, however, the BASIC Stamp will set I/O pin 1 high,
|
||||
then execution will be switched to the program in slot 1 (program 2). Program 2
|
||||
will first print "Switching..." on the PC screen and then will continuously print
|
||||
"Program 2". From this point forward, I/O pin 1 will continue to be set low and
|
||||
high in response to changes occurring on I/O pin 0, but the polled-run activity
|
||||
is disabled and the BASIC Stamp endlessly runs the code in program 2's Again
|
||||
routine.</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>
|
264
help/BasicStampHelp/Content/LanguageTopics/Commands/POLLOUT.htm
Normal file
264
help/BasicStampHelp/Content/LanguageTopics/Commands/POLLOUT.htm
Normal file
@ -0,0 +1,264 @@
|
||||
<?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>POLLOUT</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">POLLOUT</h1>
|
||||
<div class="ImagePlusCaption">
|
||||
<div class="Col2">
|
||||
<p>
|
||||
<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/PollinOutEx.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">POLLIN / POLLOUT / POLLMODE Example</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: <span class="keyword_in_text">POLLOUT</span> <![CDATA[ ]]><i>Pin</i>,<i> State</i></p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Specify a polled-output pin and active state.
|
||||
|
||||
</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Pin</i></b> is a variable/constant/expression (0 - 15) that specifies
|
||||
the I/O pin to use. This I/O pin will be set to output mode.</li>
|
||||
<li value="2"><b><i>State</i></b> is a variable/constant/expression (0 - 1) that specifies
|
||||
whether to set the I/O pin low (0) or high (1) when a polled-input pin changes
|
||||
to its poll state.</li>
|
||||
</ul>
|
||||
<h2>Quick Facts</h2>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF">
|
||||
<td width="25%" align="center"> </td>
|
||||
<td width="75%" align="center">BS2p, BS2pe, and BS2px</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Special Notes</td>
|
||||
<td align="left">
|
||||
<ul>
|
||||
<li value="1">The <span class="keyword_in_text">POLLOUT</span> command will immediately change the I/O pin to an
|
||||
output mode and set its level opposite to that of <i>State</i>,
|
||||
regardless of the polled-input states or the polled mode.</li>
|
||||
<li value="2">Polled-output pins will either change states continuously, just once
|
||||
or not at all, depending on the <span class="keyword_in_text">POLLMODE</span> command.</li>
|
||||
<li value="3">On the BS2p40 polled-output pins can be defined on both main and
|
||||
and auxiliary I/O pins. These are all active regardless of which group
|
||||
the program happens to be using at the time of a polling event.</li>
|
||||
<li value="4">If both polled-outputs and polled-run are active, the polled-output event
|
||||
will occur before the polled-run event.</li>
|
||||
</ul>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
||||
<td align="center" colspan="1">
|
||||
<p colspan="1" align="center"><a href="POLLIN.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">POLLIN</a>, <a href="POLLMODE.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">POLLMODE</a>, <a href="POLLRUN.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">POLLRUN</a>, <a href="POLLWAIT.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">POLLWAIT</a></p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText">The <span class="keyword_in_text">POLLOUT</span> command is one of a family of unique "polling" commands on the
|
||||
BS2p, BS2pe, and BS2px modules. The other commands in this family include <span class="keyword_in_text">POLLIN</span>,
|
||||
<span class="keyword_in_text">POLLMODE</span>, <span class="keyword_in_text">POLLRUN</span> and <span class="keyword_in_text">POLLWAIT</span>. The <span class="keyword_in_text">POLLOUT</span> command
|
||||
is used to specify an output pin that changes states in response to changes on
|
||||
any of the defined polled-input pins. This activity will occur in between
|
||||
instructions during the rest of the PBASIC program.</p>
|
||||
<p class="PlainText">The "polling" commands allow the BASIC Stamp to respond to certain I/O pin
|
||||
events at a faster rate than what is normally possible through manual PBASIC
|
||||
programming. The term "poll" comes from the fact that the BASIC Stamp's interpreter
|
||||
periodically checks the state of the designated polled-input pins. It "polls"
|
||||
these pins after the end of each PBASIC instruction and before it reads the next
|
||||
PBASIC instruction from the user program; giving the appearance that it is polling
|
||||
"in the background". </p>
|
||||
<p class="PlainText">This feature should not be confused with the concept of interrupts, as
|
||||
<i><b>the BASIC Stamp does not support true interrupts.</b></i></p>
|
||||
<p>The <span class="keyword_in_text">POLLOUT</span> command achieves one of three possible actions in response
|
||||
to a polled-input event. This command works in conjunction with the <span class="keyword_in_text">POLLIN</span>
|
||||
and <span class="keyword_in_text">POLLMODE</span> commands. The following is an example of the <span class="keyword_in_text">POLLOUT</span>
|
||||
command:</p><pre class="BScode" xml:space="preserve">
|
||||
Setup:
|
||||
POLLIN 0, 0
|
||||
POLLOUT 1, 1
|
||||
POLLMODE 2
|
||||
|
||||
Main:
|
||||
DEBUG "Looping...", CR
|
||||
GOTO Main
|
||||
</pre>
|
||||
<p class="PlainText">In this example, the <span class="keyword_in_text">POLLOUT</span> command tells the BASIC Stamp to set I/O
|
||||
pin 1 to an output mode and set it high (1) when it detects the desired poll state.
|
||||
The poll state is the low (0) level on I/O pin 0 that <span class="keyword_in_text">POLLIN</span> told it to
|
||||
look for. If the polled-input pin is high, the BASIC Stamp will set
|
||||
polled-output pin 1 to low (0), instead. The BASIC Stamp will not actually start
|
||||
polling until it is set to the appropriate mode, however. The third line,
|
||||
<span class="keyword_in_text">POLLMODE</span>, initiates the polling process (see the
|
||||
<a href="POLLMODE.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">POLLMODE</a> description for more information). From then
|
||||
on, as the BASIC Stamp executes the rest of the program, it will check for a low
|
||||
level (logic 0) on I/O pin 0 in between instructions. </p>
|
||||
<p class="PlainText">Once the program reaches the endless loop, at Main, it will continuously
|
||||
print "Looping...." on the PC screen. In between reading the <span class="keyword_in_text">DEBUG</span> command
|
||||
and the <span class="keyword_in_text">GOTO</span> command (and vice versa) it will check polled-input pin 0 and
|
||||
set polled-output pin 1 accordingly. In this case, when I/O pin 0 is set low,
|
||||
the BASIC Stamp will set I/O pin 1 high. When I/O pin 0 is set high, the BASIC
|
||||
Stamp will set I/O pin 1 low. It will continue to perform this operation,
|
||||
in between each command in the loop, endlessly.</p>
|
||||
<p class="PlainText">It's important to note that in this example only the <span class="keyword_in_text">DEBUG</span> and
|
||||
<span class="keyword_in_text">GOTO</span> commands are being executed over and over again. The first three
|
||||
lines of code are only run once, yet their effects are "remembered" by the BASIC
|
||||
Stamp throughout the rest of the program.</p>
|
||||
<p class="PlainText">If the polling commands were not used, the program would have to look like
|
||||
the one below in order to achieve the same effect.</p><pre class="BScode" xml:space="preserve">
|
||||
Setup:
|
||||
INPUT 0
|
||||
OUTPUT 1
|
||||
|
||||
Main:
|
||||
OUT1 = ~IN0
|
||||
DEBUG "Looping...", CR
|
||||
OUT1 = ~IN0
|
||||
GOTO Main
|
||||
</pre>
|
||||
<p class="PlainText">In this example, we create the inverse relationship of input pin 0 and output
|
||||
pin 1 manually, in-between the <span class="keyword_in_text">DEBUG</span> and <span class="keyword_in_text">GOTO</span> lines. Though the
|
||||
effects are the same as when using the polling commands, this program actually
|
||||
takes a little longer to run and consumes 7 additional bytes of program (EEPROM)
|
||||
space. Clearly, using the polling commands is more efficient.</p>
|
||||
<p class="PlainText">You can have as many polled-input and polled-output pins as you have available.
|
||||
If multiple polled-input pins are defined, any one of them can trigger changes on
|
||||
the polled-output pins that are also defined. For example:</p><pre class="BScode" xml:space="preserve">
|
||||
Setup:
|
||||
POLLIN 0, 1
|
||||
POLLIN 1, 1
|
||||
POLLOUT 2, 1
|
||||
POLLMODE 2
|
||||
|
||||
Main:
|
||||
DEBUG "Looping...", CR
|
||||
GOTO Main
|
||||
</pre>
|
||||
<p class="PlainText">This code sets I/O pins 0 and 1 to polled-input pins (looking for a high (1)
|
||||
state) and sets I/O pin 2 to be a polled-output pin (with a high-active state).
|
||||
If either I/O pin 0 or 1 goes high, the BASIC Stamp will set I/O pin 2 high.
|
||||
This works similar to a logical OR operation. The truth table below shows all the
|
||||
possible states of these two polled-input pins and the corresponding states the
|
||||
BASIC Stamp will set the polled-output pin to.</p>
|
||||
<center>
|
||||
<table width="200" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF">
|
||||
<td colspan="2" align="center">Polled-Inputs</td>
|
||||
<td colspan="1" align="center">Polled-Output</td>
|
||||
</tr>
|
||||
<tr bgcolor="#CFCFCF">
|
||||
<td width="50" align="center">0</td>
|
||||
<td width="50" align="center">1</td>
|
||||
<td width="100" align="center">2</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">0</td>
|
||||
<td align="center">0</td>
|
||||
<td align="center">0</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">0</td>
|
||||
<td align="center">1</td>
|
||||
<td align="center">1</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">1</td>
|
||||
<td align="center">0</td>
|
||||
<td align="center">1</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">1</td>
|
||||
<td align="center">1</td>
|
||||
<td align="center">1</td>
|
||||
</tr>
|
||||
</table>
|
||||
</center>
|
||||
<p> </p>
|
||||
<p class="PlainText">Normally, any polled-output pins reflect the state changes continuously, as
|
||||
described above. The <span class="keyword_in_text">POLLMODE</span> command supports another feature, however,
|
||||
where the polled-output pins will latch the active state; they will change only
|
||||
once (when the poll state is reached) and stay in the new state until the PBASIC
|
||||
program tells it to change again. See the <a href="POLLMODE.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">POLLMODE</a>
|
||||
description for more information.</p>
|
||||
<p class="PlainText">A clever use of the "latched" feature is to set a polled-output to be the same
|
||||
as the polled-input. For example, suppose an application needed to respond in some
|
||||
way if a polled-input pin goes high, but it doesn't need to respond immediately,
|
||||
and the other tasks should not be interrupted. In essence, we need a way to know
|
||||
if the pin has gone high since the last time we checked it. Look at this
|
||||
example:</p><pre class="BScode" xml:space="preserve">
|
||||
idx VAR Byte
|
||||
|
||||
Setup:
|
||||
POLLOUT 0, 1 ' pin 0 is polled-output, high
|
||||
POLLIN 0, 1 ' pin 0 back to polled-input, high
|
||||
POLLMODE 10 ' Set mode to latch the polled-output
|
||||
|
||||
Work: ' kill time waiting for polled
|
||||
FOR idx = 1 TO 20 ' event
|
||||
DEBUG "Working....", CR
|
||||
NEXT
|
||||
IF (OUT0 = 0) THEN Work
|
||||
|
||||
Respond: ' Response message
|
||||
DEBUG CR,
|
||||
"You set my pin high!", CR
|
||||
POLLMODE 10 ' Reset polled-output's latch function
|
||||
GOTO Work
|
||||
</pre>
|
||||
<p class="PlainText">Here, we set I/O pin 0 to a polled-output, then immediately set it to a
|
||||
polled-input. Then we set the polled-mode to latch the polled-outputs. Since
|
||||
the <span class="keyword_in_text">POLLIN</span> command occurred after the <span class="keyword_in_text">POLLOUT</span>, I/O pin 0 will be
|
||||
an input, but the polling feature will still affect the OUT0 bit (output latch
|
||||
for I/O pin 0). Then, the program performs some work, and once in a while, checks
|
||||
the state of OUT0. If OUT0 is 0, I/O pin 0 was never seen to go high. If,
|
||||
however, OUT0 is 1, I/O pin 0 must have gone high while the program was doing
|
||||
other work, and now it can respond in the proper manner. This even works if the
|
||||
pin had gone high and then low again before we check it (as long as it was high
|
||||
at some point in between the instructions in our Work routine.</p>
|
||||
<p class="PlainText">It is important to note that during the time between the <span class="keyword_in_text">POLLOUT</span> and
|
||||
<span class="keyword_in_text">POLLIN</span> commands, I/O pin 0 will be set to an output direction. This can
|
||||
cause a temporary short with the circuitry connected to I/O pin 0, so it is
|
||||
vital that a large enough series resister (perhaps 220 ohms or greater) be
|
||||
inserted on that pin to protect the external device and the BASIC Stamp.</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>
|
144
help/BasicStampHelp/Content/LanguageTopics/Commands/POLLRUN.htm
Normal file
144
help/BasicStampHelp/Content/LanguageTopics/Commands/POLLRUN.htm
Normal file
@ -0,0 +1,144 @@
|
||||
<?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>POLLRUN</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">POLLRUN</h1>
|
||||
<div class="ImagePlusCaption">
|
||||
<div class="Col2">
|
||||
<p>
|
||||
<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/PollrunEx.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">POLLRUN Example</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: <span class="keyword_in_text">POLLRUN</span> <![CDATA[ ]]><i>ProgramSlot</i></p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Specify a program to run upon a polled-input event.
|
||||
|
||||
</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>ProgramSlot</i></b> is a variable/constant/expression (0 - 7) that
|
||||
specifies the program slot to run when a polled-input event occurs.</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="80%" align="center" bgcolor="#CFCFCF">BS2p, BS2pe, and BS2px</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Default Slot</td>
|
||||
<td align="left">The default polled-run slot is 0. If no <span class="keyword_in_text">POLLRUN</span>
|
||||
command is given and a poll mode of 3 or 4 is set, the program in slot 0
|
||||
will run in response to a polled-input event.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Special Notes</td>
|
||||
<td align="left">
|
||||
<ul>
|
||||
<li value="1">If both polled-outputs and polled-run are active, the polled-output
|
||||
event will occur before the polled-run event.
|
||||
</li>
|
||||
</ul>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
||||
<td align="center" colspan="1">
|
||||
<p colspan="1" align="center"><a href="POLLIN.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">POLLIN</a>, <a href="POLLMODE.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">POLLMODE</a>, <a href="POLLOUT.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">POLLOUT</a>, <a href="POLLWAIT.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">POLLWAIT</a>, <a href="RUN.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">RUN</a></p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText">The <span class="keyword_in_text">POLLRUN</span> command is one of a family of unique "polling" commands on the
|
||||
BS2p, BS2pe, and BS2px modules. The other commands in this family include <span class="keyword_in_text">POLLIN</span>,
|
||||
<span class="keyword_in_text">POLLMODE</span>, <span class="keyword_in_text">POLLOUT</span> and <span class="keyword_in_text">POLLWAIT</span>. The <span class="keyword_in_text">POLLRUN</span> command
|
||||
is used to specify a program slot to run in response to a polled event. This
|
||||
activity can occur in between any two instructions within the rest of the PBASIC
|
||||
program.</p>
|
||||
<p class="PlainText">The "polling" commands allow the BASIC Stamp to respond to certain I/O pin
|
||||
events at a faster rate than what is normally possible through manual PBASIC
|
||||
programming. The term "poll" comes from the fact that the BASIC Stamp's interpreter
|
||||
periodically checks the state of the designated polled-input pins. It "polls"
|
||||
these pins after the end of each PBASIC instruction and before it reads the next
|
||||
PBASIC instruction from the user program; giving the appearance that it is polling
|
||||
"in the background". This feature should not be confused with the concept of
|
||||
interrupts, as the BASIC Stamp does not support true interrupts.</p>
|
||||
<p class="PlainText">The following is a simple example of the <span class="keyword_in_text">POLLRUN</span> command:</p><pre class="BScode" xml:space="preserve">
|
||||
Setup:
|
||||
POLLIN 0, 0
|
||||
POLLRUN 1
|
||||
POLLMODE 3
|
||||
|
||||
Main:
|
||||
DEBUG "Waiting in Program Slot 0...", CR
|
||||
GOTO Main
|
||||
</pre>
|
||||
<p class="PlainText">The first line of the above code will set up I/O pin 0 as a polled-input pin
|
||||
looking for a low (0) state. The second line, <span class="keyword_in_text">POLLRUN</span>, tells the BASIC
|
||||
Stamp that when I/O pin 0 goes low, it should switch execution over to the
|
||||
program residing in program slot 1. The third line, <span class="keyword_in_text">POLLMODE</span>, activates
|
||||
the polled-run configuration.</p>
|
||||
<p class="PlainText">Once the BASIC Stamp reaches the Main routine, it will continuously print
|
||||
"Waiting in Program Slot 0..." on the PC screen. In between reading the
|
||||
<span class="keyword_in_text">DEBUG</span> and <span class="keyword_in_text">GOTO</span> commands, however, the BASIC Stamp will poll I/O
|
||||
pin 0 and check for a high or low state. If the state of pin 0 is high,
|
||||
it will do nothing and continue as normal. If the state of pin 1 is low, it
|
||||
will switch execution over to the program in slot 1 (the second program is not
|
||||
shown in this example). The switch to another program slot works exactly like
|
||||
with the <span class="keyword_in_text">RUN</span> command; the designated program is run and the BASIC Stamp
|
||||
does not "return" to the previous program (similar to a <span class="keyword_in_text">GOTO</span> command).</p>
|
||||
<p class="PlainText">Note that in order for the polled-run activity to occur, the poll mode must
|
||||
be set to either 3 or 4 (the two modes that activate polled-run). Also note,
|
||||
that the polled-run modes, 3 and 4, are unique. As soon as the polled-run action
|
||||
occurs, the mode switches to 1 (deactivated, saved) or 2 (activated, outputs),
|
||||
respectively. This is so that the BASIC Stamp doesn't continuously go to the
|
||||
start of the designated program slot while the polled-inputs are in the desired
|
||||
poll state. Without this "one shot" feature, your program would appear to lock-up
|
||||
as long as the polled-inputs are in the designated state.</p>
|
||||
<p class="PlainText">After the program switch takes place, the <i>ProgramSlot</i> value is maintained.
|
||||
Any future change to poll mode 3 or 4, without another <span class="keyword_in_text">POLLRUN</span> command, will
|
||||
result in the previously defined program slot being used.</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>
|
218
help/BasicStampHelp/Content/LanguageTopics/Commands/POLLWAIT.htm
Normal file
218
help/BasicStampHelp/Content/LanguageTopics/Commands/POLLWAIT.htm
Normal file
@ -0,0 +1,218 @@
|
||||
<?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>POLLWAIT</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">POLLWAIT</h1>
|
||||
<div class="ImagePlusCaption">
|
||||
<div class="Col2">
|
||||
<p>
|
||||
<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/PollwaitEx.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">POLLWAIT Example</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: <span class="keyword_in_text">POLLWAIT</span> <![CDATA[ ]]><i>Duration</i></p>
|
||||
<h2>Function</h2>
|
||||
<p>Pause program execution, in a low-power mode, in units of <i>Duration</i> until any
|
||||
polled-input pin reaches the desired poll state.
|
||||
|
||||
</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Duration</i></b> is a variable/constant/expression (0 - 8) that
|
||||
specifies the duration of the low-power state. The low-power duration is
|
||||
2<sup style="font-style: italic;">Duration</sup> x 18 milliseconds. The table below indicates the low-power
|
||||
duration for any given <i>Duration</i>. Using 8 as the <i>Duration</i> is a special
|
||||
case; the BS2p, BS2pe, and BS2px will not go into low-power mode and will
|
||||
respond quicker to polled inputs.</li>
|
||||
</ul>
|
||||
<h2>Quick Facts</h2>
|
||||
<table width="100%" cellpadding="2" cellspacing="0" border="1">
|
||||
<tr>
|
||||
<td width="25%" align="center" bgcolor="#CFCFCF"> </td>
|
||||
<td width="25%" align="center" bgcolor="#CFCFCF">BS2p</td>
|
||||
<td width="25%" align="center" bgcolor="#CFCFCF">BS2pe</td>
|
||||
<td width="25%" align="center" bgcolor="#CFCFCF">BS2px</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Current draw during <span class="keyword_in_text">POLLWAIT</span></td>
|
||||
<td align="center">350 µA</td>
|
||||
<td align="center">36 µA</td>
|
||||
<td align="center">450 µA</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Response time with <i>Duration</i><br />set
|
||||
to 8</td>
|
||||
<td align="center">Less than 160 µs</td>
|
||||
<td align="center">Less than 250 µs</td>
|
||||
<td align="center">Less than 100 µs</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Special Notes</td>
|
||||
<td align="left" colspan="3">
|
||||
<ul>
|
||||
<li value="1">Poll mode must be 2 or 4 and at least one polled-input must be set
|
||||
to activate <span class="keyword_in_text">POLLWAIT</span><br></br>(<span class="keyword_in_text">POLLWAIT</span> will be ignored
|
||||
otherwise).</li>
|
||||
<li value="2">If both polled-wait and polled-run are active, the polled-run event
|
||||
will occur immediately after the polled-wait detects an event.</li>
|
||||
</ul>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
||||
<td align="center" colspan="3">
|
||||
<p colspan="3" align="center"><a href="POLLIN.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">POLLIN</a>, <a href="POLLMODE.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">POLLMODE</a>, <a href="POLLOUT.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">POLLOUT</a>, <a href="POLLRUN.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">POLLRUN</a>, <a href="END.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">END</a>, <a href="NAP.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">NAP</a>, <a href="SLEEP.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">SLEEP</a></p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText">The <span class="keyword_in_text">POLLWAIT</span> command is one of a family of unique "polling" commands on
|
||||
the BS2p and BS2pe modules. The other commands in this family include <span class="keyword_in_text">POLLIN</span>,
|
||||
<span class="keyword_in_text">POLLMODE</span>, <span class="keyword_in_text">POLLOUT</span> and <span class="keyword_in_text">POLLRUN</span>. The <span class="keyword_in_text">POLLWAIT</span> command
|
||||
is used to pause program execution and go into a low-power state until any
|
||||
polled-input pin reaches the desired poll state.</p>
|
||||
<p class="PlainText">The "polling" commands allow the BASIC Stamp to respond to certain I/O pin
|
||||
events at a faster rate than what is normally possible through manual PBASIC
|
||||
programming. The term "poll" comes from the fact that the BASIC Stamp's interpreter
|
||||
periodically checks the state of the designated polled-input pins. It "polls"
|
||||
these pins after the end of each PBASIC instruction and before it reads the next
|
||||
PBASIC instruction from the user program; giving the appearance that it is polling
|
||||
"in the background". This feature should not be confused with the concept of
|
||||
interrupts, as the BASIC Stamp does not support true interrupts.</p>
|
||||
<p class="PlainText">The <span class="keyword_in_text">POLLWAIT</span> command is unique among the polling commands in that it
|
||||
actually causes execution to halt, until a polled-input pin event occurs.
|
||||
The <i>Duration</i> argument is similar to that of the <span class="keyword_in_text">NAP</span> command; using
|
||||
the values 0 to 7 specifies the duration of the low-power period. After the
|
||||
low-power period is over, the BASIC Stamp polls the polled-input pins and determines
|
||||
if any meet the desired poll state. If no polled-input is in the desired state
|
||||
(as set by <span class="keyword_in_text">POLLIN</span> command) the BASIC Stamp goes back into low-power mode,
|
||||
again, for the same duration as before. If any polled-input is in the desired
|
||||
state, however, the BASIC Stamp will continue execution with the next line of
|
||||
code.</p>
|
||||
<p class="PlainText">A <i>Duration</i> of 8 makes the BASIC Stamp pause execution in normal running
|
||||
mode (not low-power mode) until a polled-input event occurs. The response time
|
||||
is indicated in the table below. Since the response time is so fast, this feature
|
||||
can be used to synchronize a portion of PBASIC code to an incoming pulse</p>
|
||||
<center>
|
||||
<table cellpadding="4" cellspacing="0" border="1">
|
||||
<tr>
|
||||
<td align="center" width="45" bgcolor="#CFCFCF"><i>Duration</i>
|
||||
</td>
|
||||
<td align="center" width="165" bgcolor="#CFCFCF">Length of Low-Power Mode</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">0</td>
|
||||
<td align="center">18 ms</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">1</td>
|
||||
<td align="center">36 ms</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">2</td>
|
||||
<td align="center">72 ms</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">3</td>
|
||||
<td align="center">144 ms</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">4</td>
|
||||
<td align="center">288 ms</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">5</td>
|
||||
<td align="center">576 ms</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">6</td>
|
||||
<td align="center">1152 ms (1.152 seconds)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">7</td>
|
||||
<td align="center">2304 ms (2.304 seconds)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">8</td>
|
||||
<td align="center">No power-down</td>
|
||||
</tr>
|
||||
</table>
|
||||
</center>
|
||||
<p> </p>
|
||||
<p class="PlainText">The following is a simple example of the <span class="keyword_in_text">POLLWAIT</span> command.</p><pre class="BScode" xml:space="preserve">
|
||||
Setup:
|
||||
POLLIN 0, 0
|
||||
POLLMODE 2
|
||||
|
||||
Main:
|
||||
POLLWAIT 0
|
||||
TOGGLE 1
|
||||
GOTO Main
|
||||
</pre>
|
||||
<p class="PlainText">In this example, the <span class="keyword_in_text">POLLIN</span> command sets I/O pin 0 to be a polled-input
|
||||
pin looking for a low (0) state. The Main routine immediately runs a <span class="keyword_in_text">POLLWAIT</span>command and specifies a <i>Duration</i> of 0 (with results in a low-power state of
|
||||
18 ms). This means that every 18 milliseconds, the BASIC Stamp wakes-up and checks
|
||||
I/O pin 0 for a low. If I/O pin 0 is high, it goes back to sleep for another 18
|
||||
milliseconds. If I/O pin 0 is low, it runs the next line of code, which toggles
|
||||
the state of I/O pin 1. Then the loop starts all over again. </p>
|
||||
<p class="PlainText">If low-power mode is not required, change the <span class="keyword_in_text">POLLWAIT</span> command in the
|
||||
example above to "<span class="code_in_text">POLLWAIT 8</span>" instead. This will have the effect of keeping
|
||||
the BASIC Stamp in normal running mode (i.e., no low-power glitches) and will also
|
||||
cause the <span class="keyword_in_text">TOGGLE</span> command to execute in a much shorter amount of time after
|
||||
a polled-input event occurs.</p>
|
||||
<p class="PlainText">Note: Due to the
|
||||
nature of low-power mode, I/O pin 1 may occasionally toggle between high and low even if I/O pin 0 stays low. This is an
|
||||
artifact of power conserving commands, described below.</p>
|
||||
<p class="PlainText">During execution of power conserving commands (<span class="keyword_in_text">END</span>, <span class="keyword_in_text">NAP</span>, <span class="keyword_in_text">POLLWAIT</span>, and <span class="keyword_in_text">SLEEP</span>), current will occasionally be interrupted
|
||||
on I/O pins for about 18 ms durations (60 µs on the BS2pe). The reason is that the
|
||||
watchdog-timer reset that awakens the BASIC Stamp during these commands also causes all of the pins to
|
||||
switch to input mode for approximately 18 ms (60 µs on the BS2pe). When the interpreter
|
||||
firmware regains control of the processor, it restores the I/O direction dictated
|
||||
by your program.</p>
|
||||
<p class="PlainText">If you plan to use <span class="keyword_in_text">END</span>, <span class="keyword_in_text">NAP</span>, <span class="keyword_in_text">POLLWAIT</span>, or <span class="keyword_in_text">SLEEP</span> in your programs,
|
||||
make sure that your loads can tolerate these power outages. The simplest solution
|
||||
is often to connect resistors high or low (to +5V or ground) as appropriate to
|
||||
ensure a continuing supply of current during the reset. </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>
|
122
help/BasicStampHelp/Content/LanguageTopics/Commands/POT.htm
Normal file
122
help/BasicStampHelp/Content/LanguageTopics/Commands/POT.htm
Normal file
@ -0,0 +1,122 @@
|
||||
<?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>POT</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">POT</h1>
|
||||
<div class="ImagePlusCaption">
|
||||
<div class="Col2">
|
||||
<p>
|
||||
<img src="../../graphics/pgm_icon1.gif" border="0" alt="BS1 icon" title="BS1 icon" /><span class="code_in_text"> {PBASIC 1.0}</span>
|
||||
</p>
|
||||
</div>
|
||||
<p style="text-align: right;"><a href="../ExampleTopics/PotEx.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">POT Example</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: <span class="keyword_in_text">POT</span> <![CDATA[ ]]><i>Pin</i>,<i> Scale</i>,<i> Variable</i></p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Read a 5 kΩ to 50 kΩ potentiometer, thermistor, photocell, or other
|
||||
variable resistance.</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Pin</i></b> is a variable/constant (0 - 7) that specifies the I/O pin
|
||||
to use. This pin will be set to output mode initially, then to input mode. </li>
|
||||
<li value="2"><b><i>Scale</i></b> is a variable/constant (0 - 255) used to scale the
|
||||
command's internal 16-bit result. See Explanation below for steps to finding
|
||||
the scale value to use for your circuit.</li>
|
||||
<li value="3"><b><i>Variable</i></b> is a variable (usually a byte) where the final result
|
||||
of the reading will be stored. Internally, the <span class="keyword_in_text">POT</span> command calculates
|
||||
a 16-bit value, which is scaled down to an 8-bit value. </li>
|
||||
</ul>
|
||||
<p>Note: See <a href="RCTIME.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">RCTIME</a> for all BS2 models.</p>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText"><span class="keyword_in_text">POT</span> reads a variable resistance and returns a value (0 - 255) representing
|
||||
the amount of time it took to discharge the capacitor through the resistance. Pin
|
||||
must be connected to one side of the variable resistance, whose other side is
|
||||
connected through a capacitor to ground, as shown below. </p>
|
||||
<center>
|
||||
<img src="../../graphics/pot_sch.gif" border="0">
|
||||
</img>
|
||||
</center>
|
||||
<p> </p>
|
||||
<p class="PlainText"><span class="keyword_in_text">POT</span> works by first setting the specified I/O pin to an output and setting
|
||||
its state high. This step places +5 volts on one side of the capacitor and ground
|
||||
(0 volts) on the other side, which charges the capacitor. <span class="keyword_in_text">POT</span> will hold the
|
||||
pin high for 10 milliseconds to charge the capacitor. It is important to select
|
||||
component values that will allow the capacitor to charge in this period. If, for
|
||||
example, a 50 kΩ potentiometer is used with a 0.1 µF cap, the maximum
|
||||
charge time would be:</p>
|
||||
<p class="PlainText">Charge time: 5 x (50 x 10<sup>3</sup>) x (0.1 x 10<sup>-6</sup>)
|
||||
= 25 x 10<sup>-3</sup></p>
|
||||
<p class="PlainText">The full charge time (5 TC) is 25 x 10<sup>-3</sup> or 25 milliseconds.
|
||||
Obviously, the capacitor would never fully charge when the potentiometer is
|
||||
at its maximum position. In this case, changing the capacitor to 0.01 µF
|
||||
reduces the charge time to 2.5 milliseconds; well within the range of the
|
||||
<span class="keyword_in_text">POT</span> function.</p>
|
||||
<p class="PlainText">After the capacitor is charged the I/O pin to an input mode and <span class="keyword_in_text">POT</span>starts its timer. Initially the I/O pin will see a high (1) that will eventually
|
||||
drop to a low (0) when the capacitor discharges past the 1.4-volt threshold.
|
||||
The timer stops once the low is seen. The value of the variable resistor affects
|
||||
the time it takes to discharge the capacitor from 5 volts to approximately 1.4
|
||||
volts.</p>
|
||||
<p class="PlainText">The 16-bit reading is multiplied by (<i>Scale</i> ÷ 256), so a scale
|
||||
value of 128 would reduce the range by approximately 50%, a scale of 64 would
|
||||
reduce to 25%, and so on. The amount by which the internal value must be scaled
|
||||
varies with the size of the resistor being used.</p>
|
||||
<h3>Finding the best <i>Scale</i> value: </h3>
|
||||
<ol type="1">
|
||||
<li value="1">Build the circuit shown above and plug the BS1 into the PC. </li>
|
||||
<li value="2">Select Run | POT Scaling.<br></br> A special calibration window appears, allowing you to find the best value.</li>
|
||||
<li value="3">The window asks for the number of the I/O pin to which the variable resistor
|
||||
is connected. Select the appropriate pin (0 - 7).</li>
|
||||
<li value="4">The editor downloads a short program to the BS1 (this overwrites any program
|
||||
already stored in the BS1).</li>
|
||||
<li value="5">Two numbers will be displayed: scale and value. Adjust the resistor until
|
||||
the smallest number is shown for scale (assuming you can adjust the resistor,
|
||||
as with a potentiometer).</li>
|
||||
<li value="6">Once you've found the smallest number for scale, you're done. This number
|
||||
should be used for the <i>Scale</i> in the <span class="keyword_in_text">POT</span> command.</li>
|
||||
<li value="7">Optionally, you can verify the scale number found above by selecting the
|
||||
POT Value checkbox. This locks the scale and causes the BS1 to read the resistor
|
||||
continuously. The window displays the value. If the scale is good, you should
|
||||
be able to adjust the resistor, achieving a 0-255 reading for the value (or as
|
||||
close as possible). To change the scale value and repeat this step, just
|
||||
uncheck the box. Continue this process until you find the best scale.</li>
|
||||
</ol>
|
||||
<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>
|
136
help/BasicStampHelp/Content/LanguageTopics/Commands/PULSIN.htm
Normal file
136
help/BasicStampHelp/Content/LanguageTopics/Commands/PULSIN.htm
Normal file
@ -0,0 +1,136 @@
|
||||
<?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>PULSIN</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">PULSIN</h1>
|
||||
<div class="ImagePlusCaption">
|
||||
<div class="Col2">
|
||||
<p>
|
||||
<img src="../../graphics/pgm_icon1.gif" border="0" alt="BS1 icon" title="BS1 icon" />
|
||||
<img src="../../graphics/pgm_icon2.gif" border="0" alt="BS2 icon" title="BS2 icon" />
|
||||
<img src="../../graphics/pgm_icon2e.gif" border="0" alt="BS2e icon" title="BS2e icon" />
|
||||
<img src="../../graphics/pgm_icon2sx.gif" border="0" alt="BS2sx icon" title="BS2sx icon" />
|
||||
<img src="../../graphics/pgm_icon2p.gif" border="0" alt="BS2p icon" title="BS2p icon" />
|
||||
<img src="../../graphics/pgm_icon2pe.gif" border="0" alt="BS2pe icon" title="BS2pe icon" />
|
||||
<img src="../../graphics/pgm_icon2px.gif" border="0" alt="BS2px icon" title="BS2px icon" />
|
||||
</p>
|
||||
</div>
|
||||
<p style="text-align: right;"><a href="../ExampleTopics/PulsinEx.htm" target="" title="" alt="" class="MCXref_0">PULSIN Example</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: <span class="keyword_in_text">PULSIN</span> <![CDATA[ ]]><i>Pin</i>,<i> State</i>,<i> Variable</i></p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Measure the width of a pulse on <i>Pin</i> described by <i>State</i> and store the
|
||||
result in <i>Variable</i>.
|
||||
|
||||
</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Pin</i></b> is a variable/constant/expression* (0 - 15) that specifies
|
||||
the I/O pin to use. This pin will be set to input mode.</li>
|
||||
<li value="2"><b><i>State</i></b> is a variable/constant/expression* (0 - 1) that specifies
|
||||
whether the pulse to be measured is low (0) or high (1). A low pulse begins
|
||||
with a 1-to-0 transition and a high pulse begins with a 0-to-1 transition.</li>
|
||||
<li value="3"><b><i>Variable</i></b> is a variable (usually a word) in which the measured
|
||||
pulse duration will be stored. The unit of time for <i>Variable</i> is
|
||||
described below.</li>
|
||||
</ul>
|
||||
<p class="PlainText">*<img src="../../graphics/bs1note.gif" style="vertical-align: super;" /> Note: expressions are not allowed as arguments on the BS1. The range
|
||||
of the <i>Pin</i> argument on the BS1 is 0–7.</p>
|
||||
<h2>Quick Facts</h2>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr align="center" bgcolor="#CFCFCF">
|
||||
<td width="16%"> </td>
|
||||
<td width="12%">BS1</td>
|
||||
<td width="12%">BS2</td>
|
||||
<td width="12%">BS2e</td>
|
||||
<td width="12%">BS2sx</td>
|
||||
<td width="12%">BS2p</td>
|
||||
<td width="12%">BS2pe</td>
|
||||
<td width="12%">BS2px</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td bgcolor="#CFCFCF">Units in <i>Variable</i></td>
|
||||
<td>10 µs</td>
|
||||
<td>2 µs</td>
|
||||
<td>2 µs</td>
|
||||
<td>0.8 µs</td>
|
||||
<td>0.75 µs</td>
|
||||
<td>2 µs</td>
|
||||
<td>0.81 µs</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td align="center" bgcolor="#CFCFCF">Maximum pulse width</td>
|
||||
<td>655.35 ms</td>
|
||||
<td>131.07 ms</td>
|
||||
<td>131.07 ms</td>
|
||||
<td>52.428 ms</td>
|
||||
<td>49.151 ms</td>
|
||||
<td>123.6 ms</td>
|
||||
<td>53.08 ms</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
||||
<td align="center" colspan="7">
|
||||
<p colspan="7" align="center"><a href="PULSOUT.htm" target="" title="" alt="" class="MCXref_0">PULSOUT</a>, <a href="COUNT.htm" target="" title="" alt="" class="MCXref_0">COUNT</a></p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText"><span class="keyword_in_text">PULSIN</span> is like a fast stopwatch that is triggered by a change in state
|
||||
(0 or 1) on the specified pin. The entire width of the specified pulse (high or
|
||||
low) is measured, in units shown above and stored in <i>Variable</i>. </p>
|
||||
<p class="PlainText">Many analog properties (voltage, resistance, capacitance, frequency, duty cycle)
|
||||
can be measured in terms of pulse duration. This makes <span class="keyword_in_text">PULSIN</span> a valuable
|
||||
form of analog-to-digital conversion. </p>
|
||||
<p class="PlainText"><span class="keyword_in_text">PULSIN</span> will wait for the desired pulse, for up to the maximum pulse
|
||||
width it can measure, shown in the table above. If it sees the desired pulse it
|
||||
measures the time until the end of the pulse and stores the result in <i>Variable</i>.
|
||||
If it never sees the start of the pulse, or the pulse is too long (greater than
|
||||
the Maximum Pulse Width shown above), <span class="keyword_in_text">PULSIN</span> "times out" and store 0 in
|
||||
<i>Variable</i>. This operation keeps your program from locking-up should the
|
||||
desired pulse never occur.</p>
|
||||
<p class="PlainText">Regardless of the size of <i>Variable</i>, <span class="keyword_in_text">PULSIN</span> internally uses a
|
||||
16-bit timer. Unless the pulse widths are known to be short enough to fit in an
|
||||
8-bit result, it is recommended using a word-sized variable. Not doing so may
|
||||
result in strange and misleading results as the BASIC Stamp will only store the
|
||||
lower 8-bits into a byte variable. </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>
|
145
help/BasicStampHelp/Content/LanguageTopics/Commands/PULSOUT.htm
Normal file
145
help/BasicStampHelp/Content/LanguageTopics/Commands/PULSOUT.htm
Normal file
@ -0,0 +1,145 @@
|
||||
<?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>PULSOUT</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">PULSOUT</h1>
|
||||
<div class="ImagePlusCaption">
|
||||
<div class="Col2">
|
||||
<p>
|
||||
<img src="../../graphics/pgm_icon1.gif" border="0" alt="BS1 icon" title="BS1 icon" />
|
||||
<img src="../../graphics/pgm_icon2.gif" border="0" alt="BS2 icon" title="BS2 icon" />
|
||||
<img src="../../graphics/pgm_icon2e.gif" border="0" alt="BS2e icon" title="BS2e icon" />
|
||||
<img src="../../graphics/pgm_icon2sx.gif" border="0" alt="BS2sx icon" title="BS2sx icon" />
|
||||
<img src="../../graphics/pgm_icon2p.gif" border="0" alt="BS2p icon" title="BS2p icon" />
|
||||
<img src="../../graphics/pgm_icon2pe.gif" border="0" alt="BS2pe icon" title="BS2pe icon" />
|
||||
<img src="../../graphics/pgm_icon2px.gif" border="0" alt="BS2px icon" title="BS2px icon" />
|
||||
</p>
|
||||
</div>
|
||||
<p style="text-align: right;"><a href="../ExampleTopics/PulsoutEx.htm" target="" title="" alt="" class="MCXref_0">PULSOUT Example</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: <span class="keyword_in_text">PULSOUT</span> <![CDATA[ ]]><i>Pin</i>,<i> Duration</i></p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Generate a pulse on <i>Pin</i> with a width of <i>Duration</i>.
|
||||
|
||||
</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Pin</i></b> is a variable/constant/expression* (0 - 15) that specifies
|
||||
the I/O pin to use. This pin will be set to output mode.</li>
|
||||
<li value="2"><b><i>Duration</i></b> is a variable/constant/expression* (0 - 65535) that
|
||||
specifies the duration of the pulse. The unit of time for <i>Duration</i> is
|
||||
described below.</li>
|
||||
</ul>
|
||||
<p class="PlainText">*<img src="../../graphics/bs1note.gif" style="vertical-align: super;" /> Note: expressions are not allowed as arguments on the BS1. The range
|
||||
of the <i>Pin</i> argument on the BS1 is 0–7.</p>
|
||||
<h2>Quick Facts</h2>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr align="center" bgcolor="#CFCFCF">
|
||||
<td width="16%"> </td>
|
||||
<td width="12%">BS1</td>
|
||||
<td width="12%">BS2</td>
|
||||
<td width="12%">BS2e</td>
|
||||
<td width="12%">BS2sx</td>
|
||||
<td width="12%">BS2p</td>
|
||||
<td width="12%">BS2pe</td>
|
||||
<td width="12%">BS2px</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td bgcolor="#CFCFCF">Units in <i>Variable</i></td>
|
||||
<td>10 µs</td>
|
||||
<td>2 µs</td>
|
||||
<td>2 µs</td>
|
||||
<td>0.8 µs</td>
|
||||
<td>0.8 µs</td>
|
||||
<td>2 µs</td>
|
||||
<td>0.81 µs</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td align="center" bgcolor="#CFCFCF">Maximum pulse width</td>
|
||||
<td>655.35 ms</td>
|
||||
<td>131.07 ms</td>
|
||||
<td>131.07 ms</td>
|
||||
<td>52.428 ms</td>
|
||||
<td>52.428 ms</td>
|
||||
<td>123.6 ms</td>
|
||||
<td>53.08 ms</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
||||
<td align="center" colspan="7">
|
||||
<p colspan="7" align="center"><a href="PULSIN.htm" target="" title="" alt="" class="MCXref_0">PULSIN</a>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText"><span class="keyword_in_text">PULSOUT</span> sets <i>Pin</i> to output mode, inverts the state of that pin;
|
||||
waits for the specified <i>Duration</i>; then inverts the state of the pin again;
|
||||
returning the bit to its original state. The unit of <i>Duration</i> is described
|
||||
above. The following example will generate a 100 µs pulse on I/O pin 5: </p><pre class="BScode" xml:space="preserve">
|
||||
PULSOUT 5, 50 ' generate a pulse on pin 5
|
||||
</pre>
|
||||
<p class="PlainText">The polarity of the pulse depends on the state of the pin before the command
|
||||
executes. In the example above, if pin 5 was low, <span class="keyword_in_text">PULSOUT</span> would produce
|
||||
a positive pulse. If the pin was high, <span class="keyword_in_text">PULSOUT</span> would produce a negative
|
||||
pulse.</p>
|
||||
<p class="PlainText">If the pin is an input, the output state bit, OUT5 (PIN5 on the BS1) won't
|
||||
necessarily match the state of the pin. What happens then? For example: Pin 7 is
|
||||
an input (DIR7 = 0) and pulled high by a resistor as shown below. Suppose that
|
||||
pin 7 is low when we execute the instruction: </p><pre class="BScode" xml:space="preserve">
|
||||
PULSOUT 7, 5 ' generate a pulse on pin 7
|
||||
</pre>
|
||||
<p class="PlainText">The figure below shows the sequence of events on that pin. Initially, pin 7
|
||||
is high. Its output driver is turned off (because it is in input mode), so the
|
||||
10 kΩ resistor sets the state on the pin. When <span class="keyword_in_text">PULSOUT</span> executes, it
|
||||
turns on the output driver, allowing OUT7 (PIN7 on the BS1) to control the pin.</p>
|
||||
<center>
|
||||
<img src="../../graphics/pulsout_sch.gif" border="0">
|
||||
</img>
|
||||
</center>
|
||||
<p> </p>
|
||||
<p class="PlainText">Since OUT7 (PIN7 on the BS1) is 0, the pin goes low when made an output. After
|
||||
a few microseconds of preparation, <span class="keyword_in_text">PULSOUT</span> inverts the state of the pin;
|
||||
from low to high. It leaves the pin in that state for the specified time (10µs
|
||||
if using a BS2) and then inverts it again, leaving the pin in its original
|
||||
(output) state. </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>
|
167
help/BasicStampHelp/Content/LanguageTopics/Commands/PUT.htm
Normal file
167
help/BasicStampHelp/Content/LanguageTopics/Commands/PUT.htm
Normal file
@ -0,0 +1,167 @@
|
||||
<?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>PUT</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">PUT</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/GetPutEx.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">GET / PUT Examples</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: <span class="keyword_in_text">PUT</span> <![CDATA[ ]]><i>Location</i>, {<i>WORD</i>}<i> Value</i>{,<i><![CDATA[ ]]></i>{<i>WORD</i>}<i> Value ...</i>}</p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Write one or more values to the Scratchpad RAM, starting at <i>Location</i> and
|
||||
building upward.
|
||||
|
||||
</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Location</i></b> is a variable/constant/expression (0 – 62 for BS2e
|
||||
and BS2sx, and 0 – 126 for BS2p, BS2pe, and BS2px) that specifies the
|
||||
Scratchpad RAM location to write to.</li>
|
||||
<li value="2"><b><i>Value</i></b> is a variable/constant/expression to store
|
||||
in RAM.*</li>
|
||||
</ul>
|
||||
<p class="PlainText">*Note: The optional arguments require PBASIC 2.5.</p>
|
||||
<h2>Quick Facts</h2>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr>
|
||||
<td width="24%" align="center" bgcolor="#CFCFCF"> </td>
|
||||
<td width="38%" align="center" bgcolor="#CFCFCF">BS2e and BS2sx</td>
|
||||
<td width="38%" align="center" bgcolor="#CFCFCF">BS2p, BS2pe, and BS2px</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Scratchpad RAM size and organization</td>
|
||||
<td align="center">64 bytes (0 – 63). Organized as bytes only.</td>
|
||||
<td align="center">136 bytes (0 – 135). Organized as bytes only.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">General purpose locations</td>
|
||||
<td align="center">0 - 62</td>
|
||||
<td align="center">0 – 126</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Special use location</td>
|
||||
<td align="center">Current program slot number in read-only location 63.</td>
|
||||
<td align="center">Current program slot number in lowest nibble of read-only location 127. Current read/write slot number in highest nibble of location 127. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Additional locations</td>
|
||||
<td align="center">None</td>
|
||||
<td align="center">Locations 128 - 135 (read-only) hold state of polled input pins.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
||||
<td align="center"><a href="GET.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">GET</a>
|
||||
</td>
|
||||
<td align="center"><a href="GET.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">GET</a>, <a href="STORE.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">STORE</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">PBASIC 2.5 Syntax Options</td>
|
||||
<td align="center" colspan="2">
|
||||
<p colspan="2" align="center">Multiple sequential variables may be read from the Scratchpad RAM. </p>
|
||||
<p colspan="2" align="center">The optional WORD modifier may be specified to retrieve 16-bit values.</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText">The <span class="keyword_in_text">PUT</span> command writes a value into the specified Scratchpad RAM location(s).
|
||||
All values in the general-purpose locations can be written to from within any of
|
||||
the eight program slots.</p>
|
||||
<p class="PlainText">Scratchpad RAM is useful for passing data to programs in other program slots
|
||||
and for additional workspace. It is different than regular RAM in that symbol
|
||||
names cannot be assigned directly to locations and each location is always
|
||||
configured as a byte only. The following code will write the value 100 to location
|
||||
25, read it back out with <span class="keyword_in_text">GET</span> and display it:</p>
|
||||
<p class="PlainText">The following example illustrates this:<br></br></p><pre class="BScode" xml:space="preserve">
|
||||
temp VAR Byte
|
||||
|
||||
Main:
|
||||
PUT 25, 100
|
||||
GET 25, temp
|
||||
DEBUG DEC temp
|
||||
END
|
||||
</pre>
|
||||
<p class="PlainText">When using $PBASIC 2.5 syntax, Word-sized variables can be written to the
|
||||
Scratchpad RAM with a single <span class="keyword_in_text">PUT</span> statement, as well as multiple items to
|
||||
consecutive locations. The Word modifier writes the low-byte first, then the
|
||||
high-byte (<i>"Little Endian"</i>).</p>
|
||||
<p>
|
||||
<img src="../../graphics/bsesxppepx_inline.gif" border="0">
|
||||
</img>
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
' {$PBASIC 2.5}
|
||||
|
||||
value VAR Word
|
||||
value2 VAR Word
|
||||
addr VAR Word ' EEPROM address
|
||||
test VAR Byte ' test byte read back
|
||||
|
||||
Main:
|
||||
value = $11
|
||||
value2 = $2003
|
||||
PUT 0, value, Word value2 ' write value to SP location 0
|
||||
' and value2 to SP locations 1 & 2
|
||||
|
||||
value = $FF ' modify variables
|
||||
value2 = $FFFF
|
||||
|
||||
GET 0, value, Word value2 ' retrieve from Scratchpad
|
||||
|
||||
DEBUG HEX2 ? value ' display
|
||||
DEBUG HEX4 ? value2
|
||||
END
|
||||
</pre>
|
||||
<p class="PlainText">Most Scratchpad RAM locations are available for general use. The highest
|
||||
location (63 for BS2e/BS2sx and 127 for BS2p/BS2pe) is a special, read-only,
|
||||
location that always contains the number of the currently running program slot.
|
||||
On the BS2p/BS2pe, the upper nibble of location 127 also contains the current
|
||||
program slot that will be used for the <span class="keyword_in_text">READ</span> and <span class="keyword_in_text">WRITE</span> commands.
|
||||
Any values written to this location will be ignored.</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>
|
201
help/BasicStampHelp/Content/LanguageTopics/Commands/PWM.htm
Normal file
201
help/BasicStampHelp/Content/LanguageTopics/Commands/PWM.htm
Normal file
@ -0,0 +1,201 @@
|
||||
<?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>PWM</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">PWM</h1>
|
||||
<div class="ImagePlusCaption">
|
||||
<div class="Col2">
|
||||
<p>
|
||||
<img src="../../graphics/pgm_icon1.gif" border="0" alt="BS1 icon" title="BS1 icon" />
|
||||
<img src="../../graphics/pgm_icon2.gif" border="0" alt="BS2 icon" title="BS2 icon" />
|
||||
<img src="../../graphics/pgm_icon2e.gif" border="0" alt="BS2e icon" title="BS2e icon" />
|
||||
<img src="../../graphics/pgm_icon2sx.gif" border="0" alt="BS2sx icon" title="BS2sx icon" />
|
||||
<img src="../../graphics/pgm_icon2p.gif" border="0" alt="BS2p icon" title="BS2p icon" />
|
||||
<img src="../../graphics/pgm_icon2pe.gif" border="0" alt="BS2pe icon" title="BS2pe icon" />
|
||||
<img src="../../graphics/pgm_icon2px.gif" border="0" alt="BS2px icon" title="BS2px icon" />
|
||||
</p>
|
||||
</div>
|
||||
<p style="text-align: right;"><a href="../ExampleTopics/PwmEx.htm" target="" title="" alt="" class="MCXref_0">PWM Examples</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: <span class="keyword_in_text">PWM</span> <![CDATA[ ]]><i>Pin</i>,<i> Duty</i>,<i> Duration</i></p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Convert a digital value to analog output via pulse-width modulation.
|
||||
|
||||
</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Pin</i></b> is a variable/constant/expression* (0 - 15) that specifies
|
||||
the I/O pin to use. This pin will be set to output mode initially then set to
|
||||
input mode when the command finishes.</li>
|
||||
<li value="2"><b><i>Duty</i></b> is a variable/constant/expression* (0 - 255) that specifies
|
||||
the analog output level as a number of 256<sup>ths</sup> of 5 V (0 to 4.98 V).</li>
|
||||
<li value="3"><b><i>Duration</i></b> is a variable/constant/expression* (0 - 255) that
|
||||
specifies the duration of the PWM output.</li>
|
||||
</ul>
|
||||
<p class="PlainText">*<img src="../../graphics/bs1note.gif" style="vertical-align: super;" /> Note: expressions are not allowed as arguments on the BS1. The range
|
||||
of the <i>Pin</i> argument on the BS1 is 0–7.</p>
|
||||
<h2>Quick Facts</h2>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr align="center" bgcolor="#CFCFCF">
|
||||
<td nowrap="" width="150"> </td>
|
||||
<td width="12%">BS1</td>
|
||||
<td width="12%">BS2 and BS2e</td>
|
||||
<td width="12%">BS2sx</td>
|
||||
<td width="12%">BS2p</td>
|
||||
<td width="12%">BS2pe</td>
|
||||
<td width="12%">BS2px</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td bgcolor="#CFCFCF">Units in <i>Duration</i></td>
|
||||
<td>5 ms</td>
|
||||
<td>1 ms</td>
|
||||
<td>0.4 ms</td>
|
||||
<td>0.65 ms</td>
|
||||
<td>1.62 ms</td>
|
||||
<td>0.4 ms</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td bgcolor="#CFCFCF">Average voltage equation</td>
|
||||
<td colspan="6">Average Voltage = (<i>Duty</i> ÷ 256) x 5 volts</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td bgcolor="#CFCFCF">Require charge time (<i>Duration</i> ) equation</td>
|
||||
<td colspan="6">Charge time = 5 x R x C,
|
||||
<i>Duration</i> = Charge time ÷ Units in Duration</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td bgcolor="#CFCFCF">Special Notes</td>
|
||||
<td colspan="6"><i>Pin</i> is set to output initially, and set to input at end</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
||||
<td align="center" colspan="6">
|
||||
<p colspan="6" align="center"><a href="FREQOUT.htm" target="" title="" alt="" class="MCXref_0">FREQOUT</a>, <a href="DTMFOUT.htm" target="" title="" alt="" class="MCXref_0">DTMFOUT</a></p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText">Pulse-width modulation (<span class="keyword_in_text">PWM</span>) allows the BASIC Stamp (a purely digital device)
|
||||
to generate an analog voltage. The basic idea is this: If you make a pin output
|
||||
high, the voltage at that pin will be close to 5 V. Output low is close to 0 V.
|
||||
What if you switched the pin rapidly between high and low so that it was high half
|
||||
the time and low half the time? The average voltage over time would be halfway
|
||||
between 0 and 5 V (2.5 V). <span class="keyword_in_text">PWM</span> emits a burst of 1s and 0s whose ratio is
|
||||
proportional to the duty value you specify.</p>
|
||||
<p class="PlainText">The proportion of 1s to 0s in <span class="keyword_in_text">PWM</span> is called the duty cycle. The duty
|
||||
cycle controls the analog voltage in a very direct way; the higher the duty cycle
|
||||
the higher the voltage. In the case of the BASIC Stamp, the duty cycle can range
|
||||
from 0 to 255. <i>Duty</i> is literally the proportion of 1s to 0s output by the
|
||||
<span class="keyword_in_text">PWM</span> command. To determine the proportional <span class="keyword_in_text">PWM</span> output voltage, use
|
||||
this formula: (<i>Duty</i> ÷ 256) x 5 V. For example, if <i>Duty</i>
|
||||
is 100, (100 ÷ 256) x 5 V = 1.953 V; <span class="keyword_in_text">PWM</span> outputs a train of pulses
|
||||
whose average voltage is 1.953 V.</p>
|
||||
<p class="PlainText">In order to convert <span class="keyword_in_text">PWM</span> into an analog voltage we have to filter out the
|
||||
pulses and store the average voltage. The resistor/capacitor combination shown
|
||||
below will do the job. The capacitor will hold the voltage set by <span class="keyword_in_text">PWM</span> even
|
||||
after the instruction has finished. How long it will hold the voltage depends on
|
||||
how much current is drawn from it by external circuitry, and the internal leakage
|
||||
of the capacitor. In order to hold the voltage relatively steady, a program must
|
||||
periodically repeat the <span class="keyword_in_text">PWM</span> instruction to give the capacitor a fresh
|
||||
charge. </p>
|
||||
<p class="PlainText">Just as it takes time to discharge a capacitor, it also takes time to charge
|
||||
it in the first place. The <span class="keyword_in_text">PWM</span> command lets you specify the charging time
|
||||
in terms of <span class="keyword_in_text">PWM</span> duration. The timing for the units in <i>Duration</i> is
|
||||
shown in in the table above. So, on the BS2, to charge a capacitor for five
|
||||
milliseconds, you would specify five units in <i>Duration</i>. </p>
|
||||
<p class="PlainText">How do you determine how long to charge a capacitor? Use this rule-of-thumb
|
||||
formula: Charge time = 5 x R x C. For instance, the circuit below uses a 10 kΩ
|
||||
(10 x 10<sup>3</sup> ohm) resistor and a 1 µF (1 x 10<sup>-6</sup> F) capacitor:</p>
|
||||
<p class="PlainText">Charge time = 5 x 10 x 10<sup>3</sup> x 1 x 10<sup>-6</sup> = 50 x 10<sup>-3</sup>
|
||||
seconds, or 50 milliseconds.</p>
|
||||
<center>
|
||||
<img src="../../graphics/pwm_sch.gif" border="0">
|
||||
</img>
|
||||
</center>
|
||||
<p> </p>
|
||||
<p class="PlainText">Since, on the BS2, each unit in <i>Duration</i> is approximately a millisecond,
|
||||
it would take at least 50 units to charge the capacitor. Assuming the circuit is
|
||||
connected to P0, here's the complete <span class="keyword_in_text">PWM</span> instruction: </p>
|
||||
<p>
|
||||
<img src="../../graphics/bs2e_inline.gif" border="0">
|
||||
</img>
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
PWM 0, 100, 50 ' Put a 1.96V charge on cap (BS2, BS2e)
|
||||
</pre>
|
||||
<p class="PlainText">To charge the same circuit to the same level using a BS2sx, the <i>Duration</i>would require adjustment as follows:</p>
|
||||
<p>
|
||||
<img src="../../graphics/bs2sx_inline.gif" border="0">
|
||||
</img>
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
PWM 0, 100, 125 ' Put a 1.96V charge on cap (BS2sx)
|
||||
</pre>
|
||||
<p class="PlainText">After outputting the <span class="keyword_in_text">PWM</span> pulses, the BASIC Stamp leaves the pin in input
|
||||
mode (0 in the corresponding bit of DIRS). In input mode, the pin's output driver
|
||||
is effectively disconnected. If it were not, the steady output state of the pin
|
||||
would change the voltage on the capacitor and undo the voltage setting established
|
||||
by <span class="keyword_in_text">PWM</span>. Keep in mind that leakage currents of up to 1 µA can flow into
|
||||
or out of this "disconnected" pin. Over time, these small currents will cause the
|
||||
voltage on the capacitor to drift. The same applies for leakage current from an
|
||||
op-amp's input, as well as the capacitor's own internal leakage. Executing
|
||||
<span class="keyword_in_text">PWM</span> occasionally will reset the capacitor voltage to the intended value.</p>
|
||||
<p class="PlainText"><span class="keyword_in_text">PWM</span> charges the capacitor; the load presented by your circuit discharges
|
||||
it. How long the charge lasts (and therefore how often your program should repeat
|
||||
the <span class="keyword_in_text">PWM</span> command to refresh the charge) depends on how much current the
|
||||
circuit draws, and how stable the voltage must be. You may need to buffer <span class="keyword_in_text">PWM</span>output with a simple op-amp follower if your load or stability requirements are
|
||||
more than the passive circuit can handle. </p>
|
||||
<p class="PlainText">The term "PWM" applies only loosely to the action of the BASIC Stamp's <span class="keyword_in_text">PWM</span>
|
||||
command. Most systems that output <span class="keyword_in_text">PWM</span> do so by splitting a fixed period
|
||||
of time into an on time (1) and an off time (0). Suppose the interval is 1 ms
|
||||
and the duty cycle is 100 ÷ 256. Conventional <span class="keyword_in_text">PWM</span> would turn the
|
||||
output on for 0.39 ms and off for 0.61 ms, repeating this process each millisecond.
|
||||
The main advantage of this kind of <span class="keyword_in_text">PWM</span> is its predictability; you know the
|
||||
exact frequency of the pulses (in this case, 1 kHz), and their widths are
|
||||
controlled by the duty cycle. </p>
|
||||
<p class="PlainText">BASIC Stamp's <span class="keyword_in_text">PWM</span> <![CDATA[ ]]><u>does not work this way</u>. It outputs a rapid
|
||||
sequence of on/off pulses, as short as 1.6 µs in duration, whose overall proportion
|
||||
over the course of a full <span class="keyword_in_text">PWM</span> cycle of approximately a millisecond is equal
|
||||
to the duty cycle. This has the advantage of very quickly zeroing in on the desired
|
||||
output voltage, but it does not produce the neat, orderly pulses that you might
|
||||
expect. All BS2 modules also uses this high-speed <span class="keyword_in_text">PWM</span>technique to generate pseudo-sine wave tones with the
|
||||
<a href="DTMFOUT.htm" target="" title="" alt="" class="MCXref_0">DTMFOUT</a> and <a href="FREQOUT.htm" target="" title="" alt="" class="MCXref_0">FREQOUT</a>
|
||||
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>
|
146
help/BasicStampHelp/Content/LanguageTopics/Commands/RANDOM.htm
Normal file
146
help/BasicStampHelp/Content/LanguageTopics/Commands/RANDOM.htm
Normal file
@ -0,0 +1,146 @@
|
||||
<?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>RANDOM</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">RANDOM</h1>
|
||||
<div class="ImagePlusCaption">
|
||||
<div class="Col2">
|
||||
<p>
|
||||
<img src="../../graphics/pgm_icon1.gif" border="0" alt="BS1 icon" title="BS1 icon" />
|
||||
<img src="../../graphics/pgm_icon2.gif" border="0" alt="BS2 icon" title="BS2 icon" />
|
||||
<img src="../../graphics/pgm_icon2e.gif" border="0" alt="BS2e icon" title="BS2e icon" />
|
||||
<img src="../../graphics/pgm_icon2sx.gif" border="0" alt="BS2sx icon" title="BS2sx icon" />
|
||||
<img src="../../graphics/pgm_icon2p.gif" border="0" alt="BS2p icon" title="BS2p icon" />
|
||||
<img src="../../graphics/pgm_icon2pe.gif" border="0" alt="BS2pe icon" title="BS2pe icon" />
|
||||
<img src="../../graphics/pgm_icon2px.gif" border="0" alt="BS2px icon" title="BS2px icon" />
|
||||
</p>
|
||||
</div>
|
||||
<p style="text-align: right;"><a href="../ExampleTopics/RandomEx.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">RANDOM Examples</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: <span class="keyword_in_text">RANDOM</span> <![CDATA[ ]]><i>Variable</i></p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Generate a pseudo-random number.
|
||||
|
||||
</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Variable</i></b> is a variable (usually a word) whose bits will be
|
||||
scrambled to produce a random number. <i>Variable</i> acts as <span class="keyword_in_text">RANDOM</span>'s
|
||||
input and its result output. Each pass through <span class="keyword_in_text">RANDOM</span> stores the next
|
||||
number, in the pseudo-random sequence, in <i>Variable</i>.</li>
|
||||
</ul>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText"><span class="keyword_in_text">RANDOM</span> generates pseudo-random numbers ranging from 0 to 65535. They're
|
||||
called "pseudo-random" because they appear random, but are generated by a logic
|
||||
operation that uses the initial value in <i>Variable</i> to "tap" into a sequence
|
||||
of 65535 essentially random numbers. If the same initial value, called the "seed",
|
||||
is always used, then the same sequence of numbers is generated. The following
|
||||
example demonstrates this:</p>
|
||||
<p>
|
||||
<img src="../../graphics/bs1_inline.gif" border="0">
|
||||
</img>
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
SYMBOL result = W1
|
||||
|
||||
Main:
|
||||
result = 11000 ' set initial "seed" value
|
||||
RANDOM result ' generate random number
|
||||
DEBUG result ' show the result on screen
|
||||
GOTO Main
|
||||
</pre>
|
||||
<p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0">
|
||||
</img>
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
result VAR Word
|
||||
|
||||
Main:
|
||||
result = 11000 ' set initial "seed" value
|
||||
RANDOM result ' generate random number
|
||||
DEBUG DEC ? result ' show the result on screen
|
||||
GOTO Main
|
||||
</pre>
|
||||
<p class="PlainText">In this example, the same number would appear on the screen over and over again.
|
||||
This is because the same seed value was used each time; specifically, the first
|
||||
line of the loop sets result to 11000. The <span class="keyword_in_text">RANDOM</span> command really needs
|
||||
a different seed value each time. Moving the "Result =" line out of the loop will
|
||||
solve this problem, as in:</p>
|
||||
<p>
|
||||
<img src="../../graphics/bs1_inline.gif" border="0">
|
||||
</img>
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
SYMBOL result = W1
|
||||
|
||||
Setup:
|
||||
result = 11000 ' set initial "seed" value
|
||||
|
||||
Main:
|
||||
RANDOM result ' generate random number
|
||||
DEBUG result ' show the result on screen
|
||||
GOTO Main
|
||||
END
|
||||
</pre>
|
||||
<p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0">
|
||||
</img>
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
result VAR Word
|
||||
|
||||
Setup:
|
||||
result = 11000 ' set initial "seed" value
|
||||
|
||||
Main:
|
||||
RANDOM result ' generate random number
|
||||
DEBUG DEC ? result ' show the result on screen
|
||||
GOTO Main
|
||||
END
|
||||
</pre>
|
||||
<p class="PlainText">Here, result is only initialized once, before the loop. Each time through the
|
||||
loop, the previous value of result, generated by <span class="keyword_in_text">RANDOM</span>, is used as the
|
||||
next seed value. This generates a more desirable set of pseudo-random numbers.</p>
|
||||
<p class="PlainText">In applications requiring more apparent randomness, it's necessary to "seed"
|
||||
<span class="keyword_in_text">RANDOM</span> with a more random value every time. For instance, in the
|
||||
example program, <span class="keyword_in_text">RANDOM</span> is executed continuously
|
||||
(using the previous resulting number as the next seed value) while the program
|
||||
waits for the user to press a button. Since the user can't control the timing of
|
||||
button presses very accurately, the results approach true randomness. </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>
|
182
help/BasicStampHelp/Content/LanguageTopics/Commands/RCTIME.htm
Normal file
182
help/BasicStampHelp/Content/LanguageTopics/Commands/RCTIME.htm
Normal file
@ -0,0 +1,182 @@
|
||||
<?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>RCTIME</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">RCTIME</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" />
|
||||
</p>
|
||||
</div>
|
||||
<p> </p>
|
||||
<p style="text-align: right;"><a href="../ExampleTopics/RctimeEx.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">RCTIME Examples</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: <span class="keyword_in_text">RCTIME</span> <![CDATA[ ]]><i>Pin</i>,<i> State</i>,<i> Variable</i></p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Measure time while <i>Pin</i> remains in <i>State</i>; usually to measure the
|
||||
charge/discharge time of resistor/capacitor (RC) circuit..
|
||||
|
||||
</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Pin</i></b> is a variable/constant/expression (0 - 15) that specifies
|
||||
the I/O pin to use. This pin will be placed into input mode.</li>
|
||||
<li value="2"><b><i>State</i></b> is a variable/constant/expression (0 - 1) that specifies
|
||||
the desired state to measure. Once <i>Pin</i> is not in <i>State</i>, the
|
||||
command ends and stores the result in <i>Variable</i>.</li>
|
||||
<li value="3"><b><i>Variable</i></b> is a variable (usually a word) in which the time
|
||||
measurement will be stored. The unit of time for <i>Variable</i> is described
|
||||
below.</li>
|
||||
</ul>
|
||||
<p>Note: See <a href="POT.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">POT</a> for the BS1.</p>
|
||||
<h2>Quick Facts</h2>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF" align="center">
|
||||
<td nowrap="" width="150"> </td>
|
||||
<td width="23%">BS2, BS2e, and BS2pe</td>
|
||||
<td width="23%">BS2sx</td>
|
||||
<td width="23%">BS2p</td>
|
||||
<td width="23%">BS2px</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td bgcolor="#CFCFCF">Units in <i>Variable</i></td>
|
||||
<td>2 µs</td>
|
||||
<td>0.8 µs</td>
|
||||
<td>0.75 µs</td>
|
||||
<td>0.75 µs</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td bgcolor="#CFCFCF"><i>Maximum pulse width</i>
|
||||
</td>
|
||||
<td>131.07 ms</td>
|
||||
<td>52.428 ms</td>
|
||||
<td>49.151 ms</td>
|
||||
<td>49.151 ms</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText"><span class="keyword_in_text">RCTIME</span> can be used to measure the charge or discharge time of a
|
||||
resistor/capacitor circuit. This allows you to measure resistance or capacitance;
|
||||
use R or C sensors such as thermistors or capacitive humidity sensors or respond
|
||||
to user input through a potentiometer. In a broader sense, <span class="keyword_in_text">RCTIME</span> can also
|
||||
serve as a fast, precise stopwatch for events of very short duration. </p>
|
||||
<p class="PlainText">When <span class="keyword_in_text">RCTIME</span> executes, it starts a counter (who's unit of time is shown
|
||||
above). It stops this counter as soon as the specified pin is no longer in
|
||||
<i>State</i> (0 or 1). If pin is not in <i>State</i> when the instruction executes,
|
||||
<span class="keyword_in_text">RCTIME</span> will return 1 in <i>Variable</i>, since the instruction requires one
|
||||
timing cycle to discover this fact. If pin remains in <i>State</i> longer than
|
||||
65535 timing cycles <span class="keyword_in_text">RCTIME</span> returns 0. </p>
|
||||
<p class="PlainText">The figure below shows suitable RC circuits for use with <span class="keyword_in_text">RCTIME</span>. Circuits
|
||||
A are preferred, because the BASIC Stamp's logic threshold is approximately 1.4
|
||||
volts. This means that the voltage seen by the pin will start at 5V then fall
|
||||
to 1.4V (a span of 3.6V) before <span class="keyword_in_text">RCTIME</span> stops. With Circuit B, the voltage
|
||||
will start at 0V and rise to 1.4V (spanning only 1.4V) before <span class="keyword_in_text">RCTIME</span> stops.
|
||||
For the same combination of R and C, Circuits A will yield a higher count, and
|
||||
therefore more resolution than Circuit B. </p>
|
||||
<center>
|
||||
<img src="../../graphics/rctime_sch_new.gif" border="0">
|
||||
</img>
|
||||
</center>
|
||||
<p> </p>
|
||||
<p class="PlainText">Before <span class="keyword_in_text">RCTIME</span> executes, the capacitor must be put into the state
|
||||
specified in the <span class="keyword_in_text">RCTIME</span> instruction. For example, with Circuit A, the
|
||||
capacitor must be charged until the top plate at 5V.</p>
|
||||
<p class="PlainText">Here's a typical sequence of instructions for Circuit A (assuming I/O pin
|
||||
7 is used):</p><pre class="BScode" xml:space="preserve">
|
||||
result VAR Word
|
||||
|
||||
Test:
|
||||
HIGH 7 ' charge the cap
|
||||
PAUSE 1 ' for 1 ms
|
||||
RCTIME 7, 1, result ' measure RC discharge time
|
||||
DEBUG DEC ? result ' display result
|
||||
END
|
||||
</pre>
|
||||
<p class="PlainText">Using <span class="keyword_in_text">RCTIME</span> is very straightforward, except for one detail: For a given
|
||||
R and C, what value will <span class="keyword_in_text">RCTIME</span> return? It's easy to figure, based on a
|
||||
value called the RC time constant, or tau (τ) for short. Tau represents the time
|
||||
required for a given RC combination to charge or discharge by 63 percent of the
|
||||
total change in voltage that they will undergo. More importantly, the value t is
|
||||
used in the generalized RC timing calculation. Tau's formula is just R multiplied
|
||||
by C: </p>
|
||||
<p class="PlainText">τ = R x C</p>
|
||||
<p class="PlainText">The general RC timing formula uses τ to tell us the time required for an RC
|
||||
circuit to change from one voltage to another: </p>
|
||||
<p class="PlainText">time = -τ x ( ln(V<sub>final</sub> / V<sub>initial</sub>) )</p>
|
||||
<p class="PlainText">In this formula ln is the natural logarithm; it's a key on most scientific
|
||||
calculators. Let's do some math. Assume we're interested in a 10 kΩ
|
||||
resistor and 0.1 µF capacitor. Calculate τ: </p>
|
||||
<p class="PlainText">τ = (10 x 10<sup>3</sup>) x (0.1 x 10<sup>-6</sup>) = 1 x 10<sup>-3</sup></p>
|
||||
<p class="PlainText">The RC time constant is 1 x 10<sup>-3</sup> or 1 millisecond. Now calculate
|
||||
the time required for this RC circuit to go from 5V to 1.4V (as in Circuit A): </p>
|
||||
<p class="PlainText">Time = -1 x 10<sup>-3</sup> x ( ln(1.4v ÷ 5.0v) ) =
|
||||
1.273 x 10<sup>-3</sup></p>
|
||||
<p class="PlainText">On the BS2, the unit of time is 2 µs, that time (1.273 x 10<sup>-3</sup>) works
|
||||
out to about 635 units. With a 10 kΩ resistor and 0.1 µF capacitor,
|
||||
<span class="keyword_in_text">RCTIME</span> would return a value of approximately 635. Since V<sub>initial</sub>and V<sub>final</sub> doesn't change, we can use a simplified rule of thumb to
|
||||
estimate <span class="keyword_in_text">RCTIME</span> results for Circuit A: </p>
|
||||
<p class="PlainText"><span class="keyword_in_text">RCTIME</span> units = 635 x R (in kΩ) x C (in µF)</p>
|
||||
<p class="PlainText">Another handy rule of thumb can help you calculate how long to charge/discharge
|
||||
the capacitor before <span class="keyword_in_text">RCTIME</span>. In the example above that's the purpose of the
|
||||
<span class="keyword_in_text">HIGH</span> and <span class="keyword_in_text">PAUSE</span> commands. A given RC charges or discharges 98 percent
|
||||
of the way in five time constants (5 x R x C). In Circuits A and B, the
|
||||
charge/discharge current passes through the 220 Ω series resistor and the
|
||||
capacitor. So if the capacitor were 0.1 µF, the minimum charge/discharge time
|
||||
should be: </p>
|
||||
<p class="PlainText">Charge time = 5 x 220 x (0.1 x 10<sup>-6</sup>) = 110 x 10<sup>-6</sup></p>
|
||||
<p class="PlainText">So it takes only 110 µs for the capacitor to charge/discharge, meaning that the
|
||||
one millisecond charge/discharge time of the example is plenty. </p>
|
||||
<p class="PlainText">A final note about the circuits above: You may be wondering why the 220 Ω
|
||||
resistor is necessary at all. Consider what would happen if resistor R was a
|
||||
potentiometer, and were adjusted to 0 Ω. When the I/O pin went high to
|
||||
discharge the capacitor, it would see a short direct to ground. The 220 Ω
|
||||
series resistor would limit the short circuit current to 5V ÷ 220 Ω
|
||||
= 23 mA and protect the BASIC Stamp from damage. (Actual current would be quite
|
||||
a bit less due to internal resistance of the pin's output driver, but you get
|
||||
the idea.)</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>
|
227
help/BasicStampHelp/Content/LanguageTopics/Commands/READ.htm
Normal file
227
help/BasicStampHelp/Content/LanguageTopics/Commands/READ.htm
Normal file
@ -0,0 +1,227 @@
|
||||
<?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>READ</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">READ</h1>
|
||||
<div class="ImagePlusCaption">
|
||||
<div class="Col2">
|
||||
<p>
|
||||
<img src="../../graphics/pgm_icon1.gif" border="0" alt="BS1 icon" title="BS1 icon" />
|
||||
<img src="../../graphics/pgm_icon2.gif" border="0" alt="BS2 icon" title="BS2 icon" />
|
||||
<img src="../../graphics/pgm_icon2e.gif" border="0" alt="BS2e icon" title="BS2e icon" />
|
||||
<img src="../../graphics/pgm_icon2sx.gif" border="0" alt="BS2sx icon" title="BS2sx icon" />
|
||||
<img src="../../graphics/pgm_icon2p.gif" border="0" alt="BS2p icon" title="BS2p icon" />
|
||||
<img src="../../graphics/pgm_icon2pe.gif" border="0" alt="BS2pe icon" title="BS2pe icon" />
|
||||
<img src="../../graphics/pgm_icon2px.gif" border="0" alt="BS2px icon" title="BS2px icon" />
|
||||
</p>
|
||||
</div>
|
||||
<p style="text-align: right;"><a href="../ExampleTopics/ReadEx.htm" target="" title="" alt="" class="MCXref_0">READ Examples</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax <img align="absmiddle" src="../../graphics/mini_1.gif" />:
|
||||
<span class="keyword_in_text">READ</span><i>Location</i>,<i> Variable</i><br />Syntax <img align="absmiddle" src="../../graphics/mini_2.gif" />:
|
||||
<span class="keyword_in_text">READ</span><i>Location, </i>{WORD}<i> Variable </i>{, {WORD}<i> Variable</i>, ...}</p>
|
||||
<h2>Function</h2>
|
||||
<ul>
|
||||
<li value="1"><b><i>Location</i></b> Location is a variable/constant/expression*
|
||||
(0 - 255 on BS1, 0 - 2047 on all other BASIC Stamp models) that specifies the
|
||||
EEPROM address to read from.</li>
|
||||
<li value="2"><b><i>Variable</i></b> is a variable (usually a byte) where the value
|
||||
is stored.*</li>
|
||||
</ul>
|
||||
<p class="PlainText">*<img src="../../graphics/bs1note.gif" style="vertical-align: super;" /> Note: expressions are not allowed as arguments on the BS1.</p>
|
||||
<p class="PlainText">*Note: The optional arguments require PBASIC 2.5.</p>
|
||||
<h2>Quick Facts</h2>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr>
|
||||
<td width="19%" align="center" bgcolor="#CFCFCF"> </td>
|
||||
<td width="27%" align="center" bgcolor="#CFCFCF">BS1</td>
|
||||
<td width="27%" align="center" bgcolor="#CFCFCF">BS2, BS2e, and BS2sx</td>
|
||||
<td width="27%" align="center" bgcolor="#CFCFCF">BS2p, BS2pe, and BS2px</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Range of EEPROM locations</td>
|
||||
<td align="center">0 to 255</td>
|
||||
<td align="center">0 to 2047</td>
|
||||
<td align="center">0 to 2047<br></br>(see notes below)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Special Notes</td>
|
||||
<td align="center">n/a</td>
|
||||
<td align="center"><span class="keyword_in_text">READ</span> only works with current program slot on
|
||||
BS2e and BS2sx.</td>
|
||||
<td align="center"><span class="keyword_in_text">READ</span> works with any program slot as set by the
|
||||
<span class="keyword_in_text">STORE</span> command.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
||||
<td align="center" colspan="1"><a href="WRITE.htm" target="" title="" alt="" class="MCXref_0">WRITE</a>, <a href="EEPROM.htm" target="" title="" alt="" class="MCXref_0">EEPROM</a></td>
|
||||
<td align="center">
|
||||
<p colspan="1" align="center"><a href="WRITE.htm" target="" title="" alt="" class="MCXref_0">WRITE</a>, <a href="DATA.htm" target="" title="" alt="" class="MCXref_0">DATA</a></p>
|
||||
</td>
|
||||
<td align="center">
|
||||
<p colspan="1" align="center"><a href="WRITE.htm" target="" title="" alt="" class="MCXref_0">WRITE</a>, <a href="DATA.htm" target="" title="" alt="" class="MCXref_0">DATA</a>, <a href="STORE.htm" target="" title="" alt="" class="MCXref_0">STORE</a></p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">PBASIC 2.5 Syntax Options</td>
|
||||
<td align="center" colspan="1">
|
||||
<p colspan="1" align="center">n/a</p>
|
||||
</td>
|
||||
<td align="center" colspan="2">
|
||||
<p colspan="2" align="center">Multiple sequential variables may be read from the Scratchpad RAM, and the optional WORD modifier may be specified to retrieve 16-bit values.</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText">The EEPROM is used for both program storage (which builds downward from address
|
||||
255 on BS1, 2047 on all other BASIC Stamp models) and data storage (which builds upward
|
||||
from address 0). The <span class="keyword_in_text">READ</span> instruction retrieves a value from any
|
||||
EEPROM address and stores it in <i>Variable</i>. When the optional Word modifier
|
||||
($PBASIC 2.5 required) is used, the low byte of <i>Variable</i> is read from
|
||||
<i>Location</i>, the high byte of <i>Variable</i> from <i>Location + 1.</i></p>
|
||||
<p class="PlainText">Any location within the EEPROM can be read (including your PBASIC program's
|
||||
tokens) at run-time. This feature is mainly used to retrieve long-term data from
|
||||
EEPROM; data stored in EEPROM is not lost when the power is removed.</p>
|
||||
<p class="PlainText">The following <span class="keyword_in_text">READ</span> command retrieves the value at location 100 and
|
||||
stores it into the variable called <i>Result</i>:</p>
|
||||
<p>
|
||||
<img src="../../graphics/bs1_inline.gif" border="0">
|
||||
</img>
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
SYMBOL result = B2
|
||||
|
||||
Main:
|
||||
READ 100, result
|
||||
END
|
||||
</pre>
|
||||
<p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0">
|
||||
</img>
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
result VAR Byte
|
||||
|
||||
Main:
|
||||
READ 100, result
|
||||
END
|
||||
</pre>
|
||||
<p class="PlainText">The EEPROM is organized as a sequential set of byte-sized memory locations. The READ command retrieves byte-sized values from EEPROM. This does not mean that you can't read word-sized values, however. A word consists of two bytes, called a low-byte and a high-byte. If you wanted to read a word-sized value, you can use two READ commands and a word-size variable (along with some handy modifiers). For example:</p>
|
||||
<p>
|
||||
<img src="../../graphics/bs1_inline.gif" border="0">
|
||||
</img>
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
SYMBOL result = W1 ' word-sized variable
|
||||
SYMBOL resLo = B2 ' low-byte of W1
|
||||
SYMBOL resHi = B3 ' high-byte of W1
|
||||
|
||||
EEPROM (101, 4) ' Store word-sized value
|
||||
|
||||
Main:
|
||||
READ 0, resLo
|
||||
READ 1, resHi
|
||||
DEBUG #result
|
||||
END
|
||||
</pre>
|
||||
<p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0">
|
||||
</img>
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
result VAR Word
|
||||
|
||||
DATA Word 1125 ' Store word-sized value
|
||||
|
||||
Main:
|
||||
READ 0, result.LowByte
|
||||
READ 1, result.HighByte
|
||||
DEBUG DEC ? result
|
||||
END
|
||||
</pre>
|
||||
<p class="PlainText">This code uses the <b>EEPROM</b> or <span class="keyword_in_text">DATA</span> directive to write the low-byte
|
||||
and high-byte of the number 1125 into locations 0 and 1 during download. When the
|
||||
program runs, the two <span class="keyword_in_text">READ</span> commands will read the low-byte and high-byte
|
||||
out of EEPROM (reconstructing it in a word-size variable) and then display the
|
||||
value on the screen.</p>
|
||||
<p class="PlainText">When using $PBASIC 2.5 syntax, word-sized variables can be retrieved with a single
|
||||
<span class="keyword_in_text">READ</span> statement, as well as multiple items from consecutive locations.</p>
|
||||
<p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0">
|
||||
</img>
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
' {$PBASIC 2.5}
|
||||
|
||||
idNum VAR Word
|
||||
score VAR Byte
|
||||
|
||||
ID_Rec DATA Word 1125, 75 ' Store multiple items
|
||||
|
||||
Main:
|
||||
READ ID_Rec, Word idNum, score ' Read multiple variables
|
||||
DEBUG DEC ? idNum ' Display them
|
||||
DEBUG DEC ? score
|
||||
END
|
||||
</pre>
|
||||
<p class="PlainText">Note that the <span class="keyword_in_text">EEPROM</span> and <span class="keyword_in_text">DATA</span> directives store data in the EEPROM
|
||||
before the program runs, however, the <span class="keyword_in_text">WRITE</span> command can be used to store
|
||||
data while the program is running. Additionally, the EEPROM locations can be read
|
||||
an unlimited number of times, but EEPROM locations can be worn out by excessive
|
||||
writes. See the <a href="WRITE.htm" target="" title="" alt="" class="MCXref_0">WRITE</a> command for more information.</p>
|
||||
<p class="PlainText">When using the <span class="keyword_in_text">READ</span> and <span class="keyword_in_text">WRITE</span> commands, take care to ensure that
|
||||
your program doesn't overwrite itself. On the BS1, location 255 holds the address
|
||||
of the last instruction in your program. Therefore, your program can use any space
|
||||
below the address given in location 255. For example, if location 255 holds the
|
||||
value 100, then your program can use locations 0-99 for data.</p>
|
||||
<p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0">
|
||||
</img>
|
||||
</p>
|
||||
<p class="PlainText">On other BASIC Stamp models, you'll need to view the Memory Map of the program before
|
||||
you download it, to determine the last EEPROM location used.</p>
|
||||
<p>
|
||||
<img src="../../graphics/bs2ppepx_inline.gif" border="0">
|
||||
</img>
|
||||
</p>
|
||||
<p class="PlainText">On the BS2p, BS2pe, and BS2px the <span class="keyword_in_text">READ</span> and <span class="keyword_in_text">WRITE</span> commands can
|
||||
affect locations in any program slot as set by the <span class="keyword_in_text">STORE</span> command. See the
|
||||
<a href="STORE.htm" target="" title="" alt="" class="MCXref_0">STORE</a> command for more information.</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>
|
120
help/BasicStampHelp/Content/LanguageTopics/Commands/RETURN.htm
Normal file
120
help/BasicStampHelp/Content/LanguageTopics/Commands/RETURN.htm
Normal file
@ -0,0 +1,120 @@
|
||||
<?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>RETURN</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">RETURN</h1>
|
||||
<div class="ImagePlusCaption">
|
||||
<div class="Col2">
|
||||
<p>
|
||||
<img src="../../graphics/pgm_icon1.gif" border="0" alt="BS1 icon" title="BS1 icon" />
|
||||
<img src="../../graphics/pgm_icon2.gif" border="0" alt="BS2 icon" title="BS2 icon" />
|
||||
<img src="../../graphics/pgm_icon2e.gif" border="0" alt="BS2e icon" title="BS2e icon" />
|
||||
<img src="../../graphics/pgm_icon2sx.gif" border="0" alt="BS2sx icon" title="BS2sx icon" />
|
||||
<img src="../../graphics/pgm_icon2p.gif" border="0" alt="BS2p icon" title="BS2p icon" />
|
||||
<img src="../../graphics/pgm_icon2pe.gif" border="0" alt="BS2pe icon" title="BS2pe icon" />
|
||||
<img src="../../graphics/pgm_icon2px.gif" border="0" alt="BS2px icon" title="BS2px icon" />
|
||||
</p>
|
||||
</div>
|
||||
<p style="text-align: right;"><a href="../ExampleTopics/ReturnEx.htm" target="" title="" alt="" class="MCXref_0">RETURN Example</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: <span class="keyword_in_text">RETURN</span></p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Return from a subroutine, assuming there was a previous <span class="keyword_in_text">GOSUB</span> or
|
||||
<span class="keyword_in_text">ON...GOSUB</span> executed.
|
||||
|
||||
</p>
|
||||
<h2>Quick Facts</h2>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr>
|
||||
<td width="30%" align="center" bgcolor="#CFCFCF"> </td>
|
||||
<td width="35%" align="center" bgcolor="#CFCFCF">BS1</td>
|
||||
<td width="35%" align="center" bgcolor="#CFCFCF">All BS2 Models</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
||||
<td align="center">
|
||||
<p align="center"><a href="GOSUB.htm" target="" title="" alt="" class="MCXref_0">GOSUB</a>
|
||||
</p>
|
||||
</td>
|
||||
<td align="center">
|
||||
<p align="center"><a href="GOSUB.htm" target="" title="" alt="" class="MCXref_0">GOSUB</a>, <a href="ON_GOSUB.htm" target="" title="" alt="" class="MCXref_0">ON...GOSUB</a></p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Maximum number of <span class="keyword_in_text">RETURN</span>s per
|
||||
program</td>
|
||||
<td align="center" colspan="2">Unlimited. However, the number of <span class="keyword_in_text">GOSUB</span>s is limited.
|
||||
See <a href="GOSUB.htm" target="" title="" alt="" class="MCXref_0">GOSUB</a> for more information.</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText"><span class="keyword_in_text">RETURN</span> sends the program back to the address (instruction) immediately
|
||||
following the most recent <span class="keyword_in_text">GOSUB</span>. If <span class="keyword_in_text">RETURN</span> is executed without a
|
||||
prior <span class="keyword_in_text">GOSUB</span>, the BASIC Stamp will return to the first executable line of
|
||||
the program; usually resulting in a logical bug in the code. See the <span class="keyword_in_text">GOSUB</span>command for more information.</p>
|
||||
<p class="PlainText">
|
||||
<img src="../../graphics/bs1note.gif" style="vertical-align: super;" /> Note: On the BS1, a <span class="keyword_in_text">RETURN</span> without a <span class="keyword_in_text">GOSUB</span> will
|
||||
return the program to the last <span class="keyword_in_text">GOSUB</span> (or will end the program if
|
||||
no <span class="keyword_in_text">GOSUB</span> was executed)</p>
|
||||
<p class="PlainText">The example below will start out by <span class="keyword_in_text">GOSUB</span>-ing to the section of code beginning with the label Hello. It will print "Hello my friend." on the screen then <span class="keyword_in_text">RETURN</span> to the line after the <span class="keyword_in_text">GOSUB</span>, which prints "How are you?" and <span class="keyword_in_text">END</span>s.</p><pre class="BScode" xml:space="preserve">
|
||||
Main:
|
||||
GOSUB Hello
|
||||
DEBUG "How are you?", CR
|
||||
END
|
||||
|
||||
Hello:
|
||||
DEBUG "Hello my friend.", CR
|
||||
RETURN
|
||||
</pre>
|
||||
<h3>Watch Out For Subroutines That Your Program Can "Fall Into"</h3>
|
||||
<p class="PlainText">There's another interesting lesson here; what would happen if we removed the
|
||||
<span class="keyword_in_text">END</span> command from this example? Since the BASIC Stamp reads the code from
|
||||
left to right, top to bottom (like the English language) once it had returned
|
||||
to and run the "How are you?" line, it would naturally "fall into" the Hello
|
||||
routine again. Additionally, at the end of the Hello routine, it would see the
|
||||
<span class="keyword_in_text">RETURN</span> again (although it didn't <span class="keyword_in_text">GOSUB</span> to that routine this time)
|
||||
and because there wasn't a previous place to return to, the BASIC Stamp will start
|
||||
the entire program over again. This would cause an endless loop. The important
|
||||
thing to remember here is to always make sure your program doesn't allow itself
|
||||
to "fall into" a subroutine.</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>
|
101
help/BasicStampHelp/Content/LanguageTopics/Commands/REVERSE.htm
Normal file
101
help/BasicStampHelp/Content/LanguageTopics/Commands/REVERSE.htm
Normal file
@ -0,0 +1,101 @@
|
||||
<?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>REVERSE</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">REVERSE</h1>
|
||||
<div class="ImagePlusCaption">
|
||||
<div class="Col2">
|
||||
<p>
|
||||
<img src="../../graphics/pgm_icon1.gif" border="0" alt="BS1 icon" title="BS1 icon" />
|
||||
<img src="../../graphics/pgm_icon2.gif" border="0" alt="BS2 icon" title="BS2 icon" />
|
||||
<img src="../../graphics/pgm_icon2e.gif" border="0" alt="BS2e icon" title="BS2e icon" />
|
||||
<img src="../../graphics/pgm_icon2sx.gif" border="0" alt="BS2sx icon" title="BS2sx icon" />
|
||||
<img src="../../graphics/pgm_icon2p.gif" border="0" alt="BS2p icon" title="BS2p icon" />
|
||||
<img src="../../graphics/pgm_icon2pe.gif" border="0" alt="BS2pe icon" title="BS2pe icon" />
|
||||
<img src="../../graphics/pgm_icon2px.gif" border="0" alt="BS2px icon" title="BS2px icon" />
|
||||
</p>
|
||||
</div>
|
||||
<p style="text-align: right;"><a href="../ExampleTopics/ReverseEx.htm" target="" title="" alt="" class="MCXref_0">REVERSE Examples</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: <span class="keyword_in_text">REVERSE</span> <![CDATA[ ]]><i>Pin</i></p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Reverse the data direction of the specified pin.
|
||||
|
||||
</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Pin</i></b> is a variable/constant/expression* (0 – 15) that specifies the
|
||||
I/O pin to use. This pin will be placed into the mode opposite of its current
|
||||
input/output mode.</li>
|
||||
</ul>
|
||||
<p class="PlainText">*<img src="../../graphics/bs1note.gif" style="vertical-align: super;" /> Note: expressions are not allowed as arguments on the BS1. The range
|
||||
of the <i>Pin</i> argument on the BS1 is 0–7.</p>
|
||||
<h2>Quick Facts</h2>
|
||||
<table cellpadding="4" cellspacing="0" border="1" style="caption-side: top;width: 100%;">
|
||||
<col />
|
||||
<col />
|
||||
<tr bgcolor="#CFCFCF">
|
||||
<td width="15%" align="center"> </td>
|
||||
<td width="85%" align="center">BS1 and all BS2 models</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
||||
<td>
|
||||
<p align="center"><a href="HIGH.htm" target="" title="" alt="" class="MCXref_0">HIGH</a>, <a href="TOGGLE.htm" target="" title="" alt="" class="MCXref_0">TOGGLE</a></p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText"><span class="keyword_in_text">Reverse</span> is convenient way to switch the I/O direction of a pin. If the pin
|
||||
is an input, <span class="keyword_in_text">Reverse</span> makes it an output; if it's an output, <span class="keyword_in_text">Reverse</span>makes it an input.</p>
|
||||
<p class="PlainText">Remember that "input" really has two meanings: (1) Setting a pin to input
|
||||
makes it possible to check the state (1 or 0) of external circuitry connected
|
||||
to that pin. The current state is in the corresponding bit of the INS register
|
||||
(PINS on the BS1). (2) Setting a pin to input also disconnects the output
|
||||
driver, the corresponding bit of OUTS (PINS on the BS1).</p>
|
||||
<p class="PlainText">The example programs illustrate this second fact
|
||||
with a two-tone LED blinker, using the circuit below:</p>
|
||||
<p> </p>
|
||||
<p style="text-align: center;">
|
||||
<img src="../../graphics/reverse_sch.gif" />
|
||||
</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>
|
194
help/BasicStampHelp/Content/LanguageTopics/Commands/RUN.htm
Normal file
194
help/BasicStampHelp/Content/LanguageTopics/Commands/RUN.htm
Normal file
@ -0,0 +1,194 @@
|
||||
<?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>
|
@ -0,0 +1,168 @@
|
||||
<?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>SELECT...CASE</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">SELECT...CASE</h1>
|
||||
<div class="ImagePlusCaption">
|
||||
<div class="Col2">
|
||||
<p class="PlainText">
|
||||
<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;"><a href="../ExampleTopics/SelectCaseEx.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">SELECT...CASE Example</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: <br></br><br></br>   <span class="keyword_in_text">SELECT</span> <![CDATA[ ]]><i>Expression</i><br></br>     <span class="keyword_in_text">CASE</span> <![CDATA[ ]]><i>Condition(s)</i><br></br>       <i>Statement(s)</i><br></br>   { <span class="keyword_in_text">CASE</span> <![CDATA[ ]]><i>Condition(s)</i><br></br>       <i>Statement(s)</i><br></br>     <span class="keyword_in_text">CASE ELSE</span><br></br>       <i>Statement(s)</i> }<br></br>   <span class="keyword_in_text">ENDSELECT</span></p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Evaluate <i>Expression</i> and then conditionally execute a block of code based
|
||||
on comparison to <i>Condition(s)</i>. After executing a block of code the
|
||||
program continues at the line that follows <span class="keyword_in_text">ENDSELECT</span>. 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 execute. </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. The <i>Condition</i> can be a very simple or very complex
|
||||
relationship, as described below. 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.
|
||||
Multiple statements may be placed on the same line (though not recommended)
|
||||
by separating each statement with a colon ( : ).</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="80%" align="center" bgcolor="#CFCFCF">BS2 Family</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Comparison operators</td>
|
||||
<td align="center">= (assumed if no operator), <>, >, <, >=,
|
||||
<=</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Conditional Logic Operators</td>
|
||||
<td align="center">NOT, AND, OR, XOR</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF"><i>Condition</i> format</td>
|
||||
<td align="center">condition_op <i>value</i>   or  
|
||||
<i>value1</i> TO <i>value2</i></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Parentheses</td>
|
||||
<td align="center">Allowed</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Nesting</td>
|
||||
<td align="center">Up to 16 levels</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
||||
<td align="center" colspan="1">
|
||||
<p colspan="1" align="center"><a href="IF_THEN_ELSE.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">IF…THEN…ELSE</a>, <a href="ON_GOSUB.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">ON...GOSUB</a>, <a href="BRANCH.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">BRANCH</a></p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText"><span class="keyword_in_text">SELECT...CASE</span> is an advanced decision-making structure and is often used
|
||||
to replace compound <span class="keyword_in_text">IF...THEN...ELSE</span> structures. The available comparison
|
||||
operators are:</p>
|
||||
<center>
|
||||
<table cellpadding="4" cellspacing="0" border="1">
|
||||
<tr>
|
||||
<td width="130" align="center" bgcolor="#CFCFCF">Comparison Operator Symbol</td>
|
||||
<td width="170" align="center" bgcolor="#CFCFCF">Definition</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">=</td>
|
||||
<td align="center">Equal (assumed)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><></td>
|
||||
<td align="center">Not Equal</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">></td>
|
||||
<td align="center">Greater Than</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><</td>
|
||||
<td align="center">Less Than</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">>=</td>
|
||||
<td align="center">Greater Than or Equal To</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><=</td>
|
||||
<td align="center">Less Than or Equal To</td>
|
||||
</tr>
|
||||
</table>
|
||||
</center>
|
||||
<p> </p>
|
||||
<p class="PlainText">Example:</p><pre class="BScode" xml:space="preserve">
|
||||
SELECT irCmd
|
||||
CASE 0 TO 3
|
||||
HIGH irCmd ' enable selected output
|
||||
FREQOUT Spkr, 50, 880 ' beep
|
||||
|
||||
CASE AllOff, Mute
|
||||
OutA = %0000 ' all outputs off
|
||||
|
||||
CASE ELSE ' invalid command
|
||||
DEBUG "Bad Command", CR
|
||||
ENDSELECT
|
||||
</pre>
|
||||
<p class="PlainText">Here, the BASIC Stamp will examine the value of variable irCmd. If irCmd is
|
||||
between zero and three (inclusive), the associated output (P0 .. P3) will be
|
||||
made high and and the speaker will beep. If irCmd is equal to either AllOff or
|
||||
Mute (constants), then outputs P0 - P3 will be made low. On any other value of
|
||||
irCmd, a message will be displayed that indicates an invalid command.</p>
|
||||
<p class="PlainText">See <a href="IF_THEN.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">IF…THEN</a> for additional details on the use of
|
||||
comparison and conditional operators.</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>
|
1235
help/BasicStampHelp/Content/LanguageTopics/Commands/SERIN.htm
Normal file
1235
help/BasicStampHelp/Content/LanguageTopics/Commands/SERIN.htm
Normal file
File diff suppressed because it is too large
Load Diff
1059
help/BasicStampHelp/Content/LanguageTopics/Commands/SEROUT.htm
Normal file
1059
help/BasicStampHelp/Content/LanguageTopics/Commands/SEROUT.htm
Normal file
File diff suppressed because it is too large
Load Diff
205
help/BasicStampHelp/Content/LanguageTopics/Commands/SHIFTIN.htm
Normal file
205
help/BasicStampHelp/Content/LanguageTopics/Commands/SHIFTIN.htm
Normal file
@ -0,0 +1,205 @@
|
||||
<?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>SHIFTIN</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">SHIFTIN</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" />
|
||||
</p>
|
||||
</div>
|
||||
<p style="text-align: right;"><a href="../ExampleTopics/ShiftinEx.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">SHIFTIN Example</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: <span class="keyword_in_text">SHIFTIN</span> <![CDATA[ ]]><i>Dpin</i>,<i> Cpin</i>,<i> Mode</i>,<i><![CDATA[ ]]></i>[<i>Variable </i>{\<i>Bits</i>} {,<i> Variable </i>{\<i>Bits</i>}...}]</p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Shift data in from a synchronous serial device.
|
||||
|
||||
</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Dpin</i></b> is a variable/constant/expression (0 - 15) that specifies
|
||||
the I/O pin that will be connected to the synchronous serial device's data
|
||||
output. This pin will be set to input mode.</li>
|
||||
<li value="2"><b><i>Cpin</i></b> is a variable/constant/expression (0 - 15) that specifies
|
||||
the I/O pin that will be connected to the synchronous serial device's clock
|
||||
input. This pin will be set to output mode.</li>
|
||||
<li value="3"><b><i>Mode</i></b> is a variable/constant/expression (0 - 3), or one of four
|
||||
predefined symbols, that tells <span class="keyword_in_text">SHIFTIN</span> the order in which data bits are
|
||||
to be arranged and the relationship of clock pulses to valid data. See the
|
||||
table below for value and symbol definitions.</li>
|
||||
<li value="4"><b><i>Variable</i></b> is a variable in which incoming data bits will be
|
||||
stored.</li>
|
||||
<li value="5"><b><i>Bits</i></b> is an optional variable/constant/expression (1 - 16)
|
||||
specifying how many bits are to be input by <span class="keyword_in_text">SHIFTIN</span>. If no <i>Bits</i>
|
||||
entry is given, <span class="keyword_in_text">SHIFTIN</span> defaults to 8 bits.</li>
|
||||
</ul>
|
||||
<h2>Quick Facts</h2>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF">
|
||||
<td width="250" align="center"> </td>
|
||||
<td width="25%" align="center">BS2, BS2e, and BS2pe</td>
|
||||
<td width="25%" align="center">BS2sx and BS2p</td>
|
||||
<td width="25%" align="center">BS2px</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Timing of T<sub>0</sub> and T<sub>1</sub></td>
|
||||
<td align="center">14 µs / 46 µs</td>
|
||||
<td align="center">5.6 µs / 18 µs</td>
|
||||
<td align="center">3.6 µs / 11.8 µs</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Transmission Rate</td>
|
||||
<td align="center">~ 16 kBits/Sec</td>
|
||||
<td align="center">~ 42 kBits/Sec</td>
|
||||
<td align="center">~ 65 kBits/Sec</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
||||
<td align="center" colspan="3">
|
||||
<p colspan="3" align="center"><a href="SHIFTOUT.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">SHIFTOUT</a>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText"><span class="keyword_in_text">SHIFTIN</span> and <span class="keyword_in_text">SHIFTOUT</span> provide an easy method of acquiring data from
|
||||
synchronous serial devices. Synchronous serial differs from asynchronous serial
|
||||
(like <span class="keyword_in_text">SERIN</span> and <span class="keyword_in_text">SEROUT</span>) in that the timing of data bits (on a data
|
||||
line) is specified in relationship to clock pulses (on a clock line). Data bits
|
||||
may be valid after the rising or falling edge of the clock line. This kind of
|
||||
serial protocol is commonly used by controller peripherals like ADCs, DACs, clocks,
|
||||
memory devices, etc. </p>
|
||||
<p class="PlainText">At their heart, synchronous-serial devices are essentially shift-registers;
|
||||
trains of flip-flops that pass data bits along in a bucket brigade fashion to a
|
||||
single data output pin. Another bit is output each time the appropriate edge
|
||||
(rising or falling, depending on the device) appears on the clock line. </p>
|
||||
<p class="PlainText">The <span class="keyword_in_text">SHIFTIN</span> instruction first causes the clock pin to output low and
|
||||
the data pin to switch to input mode. Then, <span class="keyword_in_text">SHIFTIN</span> either reads the data
|
||||
pin and generates a clock pulse (PRE mode) or generates a clock pulse then reads
|
||||
the data pin (POST mode). <span class="keyword_in_text">SHIFTIN</span> continues to generate clock pulses and
|
||||
read the data pin for as many data bits as are required.</p>
|
||||
<p class="PlainText">Making <span class="keyword_in_text">SHIFTIN</span> work with a particular device is a matter of matching
|
||||
the mode and number of bits to that device's protocol. Most manufacturers use a
|
||||
timing diagram to illustrate the relationship of clock and data. Items to look
|
||||
for include: 1) which bit of the data arrives first; most significant bit (MSB)
|
||||
or least significant bit (LSB) and 2) is the first data bit ready before the
|
||||
first clock pulse (PRE) or after the first clock pulse (POST). The table below
|
||||
shows the values and symbols available for the <i>Mode</i> argument.</p>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF">
|
||||
<td width="75" align="center">Symbol</td>
|
||||
<td width="65" align="center">Value</td>
|
||||
<td width="80%" align="center">Meaning</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">MSBPRE</td>
|
||||
<td align="center">0</td>
|
||||
<td align="left">Data is MSB-first; sample bits before clock pulse</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">LSBPRE</td>
|
||||
<td align="center">1</td>
|
||||
<td align="left">Data is lsb-first; sample bits before clock pulse</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">MSBPOST</td>
|
||||
<td align="center">2</td>
|
||||
<td align="left">Data is MSB-first; sample bits after clock pulse</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">LSBPOST</td>
|
||||
<td align="center">3</td>
|
||||
<td align="left">Data is LSB-first; sample bits after clock pulse</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h3>SHIFTIN Timing</h3>
|
||||
<center>
|
||||
<img src="../../graphics/shiftin_timing.gif" border="0">
|
||||
</img>
|
||||
</center>
|
||||
<p class="PlainText">Here is a simple example:</p><pre class="BScode" xml:space="preserve">
|
||||
result VAR Byte
|
||||
|
||||
Main:
|
||||
SHIFTIN 0, 1, MSBPRE, [result]
|
||||
END
|
||||
</pre>
|
||||
<p class="PlainText">Here, the <span class="keyword_in_text">SHIFTIN</span> command will read I/O pin 0 (the Dpin) and will
|
||||
generate a clock signal on I/O 1 (the <i>Cpin</i>). The data that arrives on the
|
||||
Dpin depends on the device connected to it. Let's say, for example, that a shift
|
||||
register is connected and has a value of $AF (10101111) waiting to be sent.
|
||||
Additionally, let's assume that the shift register sends out the most significant
|
||||
bit first, and the first bit is on the <i>Dpin</i> before the first clock pulse
|
||||
(MSBPRE). The <span class="keyword_in_text">SHIFTIN</span> command above will generate eight clock pulses and
|
||||
sample the data pin (<i>Dpin</i>) eight times. Afterward, the result variable
|
||||
will contain the value $AF.</p>
|
||||
<p class="PlainText">By default, <span class="keyword_in_text">SHIFTIN</span> acquires eight bits, but you can set it to shift
|
||||
any number of bits from 1 to 16 with the <i>Bits</i> argument. For example:</p><pre class="BScode" xml:space="preserve">
|
||||
result VAR Byte
|
||||
|
||||
Main:
|
||||
SHIFTIN 0, 1, MSBPRE, [result\4]
|
||||
END
|
||||
</pre>
|
||||
<p class="PlainText">Will only input the first 4 bits. In the example discussed above, the result
|
||||
variable will be left with %1010. </p>
|
||||
<p class="PlainText">Some devices return more than 16 bits. For example, most 8-bit shift registers
|
||||
can be daisy-chained together to form any multiple of 8 bits; 16, 24, 32, 40...
|
||||
To solve this, you can use a single <span class="keyword_in_text">SHIFTIN</span> instruction with multiple
|
||||
variables. Each variable can be assigned a particular number of bits with the
|
||||
<i>Bits</i> argument. As in: </p><pre class="BScode" xml:space="preserve">
|
||||
dataLo VAR Word
|
||||
dataHi VAR Byte
|
||||
|
||||
Main:
|
||||
SHIFTIN 0, 1, MSBPRE, [dataHi\4, dataLo\16]
|
||||
STOP
|
||||
</pre>
|
||||
<p class="PlainText">The code above will first shift in four bits into dataHi and then 16 bits
|
||||
into dataLo. The two variables together make up a 20 bit value.</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>
|
187
help/BasicStampHelp/Content/LanguageTopics/Commands/SHIFTOUT.htm
Normal file
187
help/BasicStampHelp/Content/LanguageTopics/Commands/SHIFTOUT.htm
Normal file
@ -0,0 +1,187 @@
|
||||
<?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>SHIFTOUT</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">SHIFTOUT</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" />
|
||||
</p>
|
||||
</div>
|
||||
<p style="text-align: right;"><a href="../ExampleTopics/ShiftoutEx.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">SHIFTOUT Example</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: <span class="keyword_in_text">SHIFTOUT</span> <![CDATA[ ]]><i>Dpin</i>,<i> Cpin</i>,<i> Mode, </i>[<i>OutputData </i>{\<i>Bits</i>} {,<i>OutputData </i>{\<i>Bits</i>}...}]</p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Shift data out to a synchronous serial device.
|
||||
|
||||
</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Dpin</i></b> is a variable/constant/expression (0 - 15) that specifies
|
||||
the I/O pin that will be connected to the synchronous serial device's data
|
||||
input. This pin will be set to output mode.</li>
|
||||
<li value="2"><b><i>Cpin</i></b> is a variable/constant/expression (0 - 15) that specifies
|
||||
the I/O pin that will be connected to the synchronous serial device's clock
|
||||
input. This pin will be set to output mode.</li>
|
||||
<li value="3"><b><i>Mode</i></b> is a variable/constant/expression (0 - 1), or one of two
|
||||
predefined symbols, that tells <span class="keyword_in_text">SHIFTOUT</span> the order in which data bits
|
||||
are to be arranged. See the table below for value and symbol definitions.</li>
|
||||
<li value="4"><b><i>OutputData</i></b> is a variable/constant/expression containing the
|
||||
data to be sent. </li>
|
||||
<li value="5"><b><i>Bits</i></b> is an optional variable/constant/expression (1 - 16)
|
||||
specifying how many bits are to be output by <span class="keyword_in_text">SHIFTOUT</span>. If no <i>Bits</i>entry is given <span class="keyword_in_text">SHIFTOUT</span> defaults to 8 bits. When the <i>Bits</i> entry
|
||||
is given, the BASIC Stamp transmits the rightmost number of bits specified,
|
||||
regardless of the <i>Mode</i>.</li>
|
||||
</ul>
|
||||
<h2>Quick Facts</h2>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF">
|
||||
<td width="250" align="center"> </td>
|
||||
<td width="25%" align="center">BS2, BS2e, and BS2pe</td>
|
||||
<td width="25%" align="center">BS2sx and BS2p</td>
|
||||
<td width="25%" align="center">BS2px</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Timing of T<sub>h</sub>, T<sub>l</sub>,
|
||||
T<sub>a</sub> and T<sub>b</sub></td>
|
||||
<td align="center">14 µs / 46 µs / 15 µs / 30 µs</td>
|
||||
<td align="center">5.6 µs / 18 µs / 6.3 µs / 12.5 µs</td>
|
||||
<td align="center">3.6 µs / 11.8 µs / 4.0 µs / 7.8 µs</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Transmission Rate</td>
|
||||
<td align="center">~ 16 kBits/Sec</td>
|
||||
<td align="center">~ 42 kBits/Sec</td>
|
||||
<td align="center">~ 65 kBits/Sec</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
||||
<td align="center" colspan="2">
|
||||
<p colspan="2" align="center"><a href="SHIFTIN.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">SHIFTIN</a>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText"><span class="keyword_in_text">SHIFTIN</span> and <span class="keyword_in_text">SHIFTOUT</span> provide an easy method of acquiring data from
|
||||
synchronous serial devices. Synchronous serial differs from asynchronous serial
|
||||
(like <span class="keyword_in_text">SERIN</span> and <span class="keyword_in_text">SEROUT</span>) in that the timing of data bits (on a data
|
||||
line) is specified in relationship to clock pulses (on a clock line). Data bits
|
||||
may be valid after the rising or falling edge of the clock line. This kind of
|
||||
serial protocol is commonly used by controller peripherals like ADCs, DACs, clocks,
|
||||
memory devices, etc. </p>
|
||||
<p class="PlainText">At their heart, synchronous-serial devices are essentially shift-registers;
|
||||
trains of flip-flops that pass data bits along in a bucket brigade fashion to a
|
||||
single data output pin. Another bit is output each time the appropriate edge
|
||||
(rising or falling, depending on the device) appears on the clock line. </p>
|
||||
<p class="PlainText">The <span class="keyword_in_text">SHIFTOUT</span> instruction first causes the clock pin to output low and
|
||||
the data pin to switch to output mode. Then, <span class="keyword_in_text">SHIFTOUT</span> sets the data pin
|
||||
to the next bit state to be output and generates a clock pulse. <span class="keyword_in_text">SHIFTOUT</span>continues to generate clock pulses and places the next data bit on the data pin
|
||||
for as many data bits as are required for transmission.</p>
|
||||
<p class="PlainText">Making <span class="keyword_in_text">SHIFTOUT</span> work with a particular device is a matter of matching
|
||||
the mode and number of bits to that device's protocol. Most manufacturers use a
|
||||
timing diagram to illustrate the relationship of clock and data. One of the most
|
||||
important items to look for is which bit of the data should be transmitted first;
|
||||
most significant bit (MSB) or least significant bit (LSB). The table below shows
|
||||
the values and symbols available for the <i>Mode</i> argument</p>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr bgcolor="#CFCFCF">
|
||||
<td width="75" align="center">Symbol</td>
|
||||
<td width="65" align="center">Value</td>
|
||||
<td width="80%" align="center">Meaning</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">LSBFIRST</td>
|
||||
<td align="center">0</td>
|
||||
<td align="left">Data is shifted out LSB-first</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">MSBFIRST</td>
|
||||
<td align="center">1</td>
|
||||
<td align="left">Data is shifted out MSB-first</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p> </p>
|
||||
<p class="PlainText">(MSB is most-significant bit; the highest or left-most bit of a Nibble, Byte,
|
||||
or Word. LSB is the least-significant bit; the lowest or right-most bit of a
|
||||
Nibble, Byte, or Word.)</p>
|
||||
<h3>SHIFTOUT Timing</h3>
|
||||
<center>
|
||||
<img src="../../graphics/shiftout_timing.gif" border="0">
|
||||
</img>
|
||||
</center>
|
||||
<p class="PlainText">Here is a simple example:</p><pre class="BScode" xml:space="preserve">
|
||||
SHIFTOUT 0, 1, MSBFIRST, [250]
|
||||
</pre>
|
||||
<p class="PlainText">Here, the <span class="keyword_in_text">SHIFTOUT</span> command will write to I/O pin 0 (the Dpin) and will
|
||||
generate a clock signal on I/O 1 (the <i>Cpin</i>). The <span class="keyword_in_text">SHIFTOUT</span> command
|
||||
will generate eight clock pulses while writing each bit (of the 8-bit value 250)
|
||||
onto the data pin (<i>Dpin</i>). In this case, it will start with the most
|
||||
significant bit first as indicated by the <i>Mode</i> value of MSBFIRST.</p>
|
||||
<p class="PlainText">By default, <span class="keyword_in_text">SHIFTOUT</span> transmits eight bits, but you can set it to shift
|
||||
any number of bits from 1 to 16 with the <i>Bits</i> argument. For example:</p><pre class="BScode" xml:space="preserve">
|
||||
SHIFTOUT 0, 1, MSBFIRST, [250\4]
|
||||
</pre>
|
||||
<p class="PlainText">Will output only the lowest (rightmost) four bits (%1010 in this case). But
|
||||
what if you want to output the leftmost bits of a given value? By adding the
|
||||
right-shift operator (>>) to the code you can adjust the output as required:</p><pre class="BScode" xml:space="preserve">
|
||||
SHIFTOUT 0, 1, MSBFIRST, [(250 >> 2)\6]
|
||||
</pre>
|
||||
<p class="PlainText">...will output the upper six bits (%111110 in this case).</p>
|
||||
<p class="PlainText">Some devices require more than 16 bits. To solve this, you can use a single
|
||||
<span class="keyword_in_text">SHIFTOUT</span> command with multiple values. Each value can be assigned a
|
||||
particular number of bits with the <i>Bits</i> argument. As in: </p><pre class="BScode" xml:space="preserve">
|
||||
SHIFTOUT 0, 1, MSBFIRST, [250\4, 1045\16]
|
||||
</pre>
|
||||
<p class="PlainText">The preceding example will first shift out four bits of the number 250 (%1010)
|
||||
and then 16 bits of the number 1045 (%0000010000010101). The two values together
|
||||
make up a 20 bit value.</p>
|
||||
<p class="PlainText">In the examples above, specific numbers were entered as the data to transmit,
|
||||
but, of course, the <span class="keyword_in_text">SHIFTOUT</span> command will accept variables and expressions
|
||||
for the <i>OutputData</i> and even for the <i>Bits</i> argument.</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>
|
211
help/BasicStampHelp/Content/LanguageTopics/Commands/SLEEP.htm
Normal file
211
help/BasicStampHelp/Content/LanguageTopics/Commands/SLEEP.htm
Normal file
@ -0,0 +1,211 @@
|
||||
<?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>SLEEP</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">SLEEP</h1>
|
||||
<div class="ImagePlusCaption">
|
||||
<div class="Col2">
|
||||
<p>
|
||||
<img src="../../graphics/pgm_icon1.gif" border="0" alt="BS1 icon" title="BS1 icon" />
|
||||
<img src="../../graphics/pgm_icon2.gif" border="0" alt="BS2 icon" title="BS2 icon" />
|
||||
<img src="../../graphics/pgm_icon2e.gif" border="0" alt="BS2e icon" title="BS2e icon" />
|
||||
<img src="../../graphics/pgm_icon2sx.gif" border="0" alt="BS2sx icon" title="BS2sx icon" />
|
||||
<img src="../../graphics/pgm_icon2p.gif" border="0" alt="BS2p icon" title="BS2p icon" />
|
||||
<img src="../../graphics/pgm_icon2pe.gif" border="0" alt="BS2pe icon" title="BS2pe icon" />
|
||||
<img src="../../graphics/pgm_icon2px.gif" border="0" alt="BS2px icon" title="BS2px icon" />
|
||||
</p>
|
||||
</div>
|
||||
<p style="text-align: right;"><a href="../ExampleTopics/SleepEx.htm" target="" title="" alt="" class="MCXref_0">SLEEP Example</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: <span class="keyword_in_text">SLEEP</span> <![CDATA[ ]]><i>Duration</i></p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Put the BASIC Stamp into low-power mode for a specified period of time.
|
||||
|
||||
</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Duration</i></b> is a variable/constant/expression* (1 - 65535) that
|
||||
specifies the duration of sleep. The unit of time for <i>Duration</i> is one
|
||||
second, though the BASIC Stamp rounds up to the nearest multiple of 2.3
|
||||
seconds. </li>
|
||||
</ul>
|
||||
<p class="PlainText">*<img src="../../graphics/bs1note.gif" style="vertical-align: super;" /> Note: expressions are not allowed as arguments on the BS1.</p>
|
||||
<h2>Quick Facts</h2>
|
||||
<table cellpadding="4" cellspacing="0" border="1" style="caption-side: top;width: 100%;">
|
||||
<col />
|
||||
<col />
|
||||
<col />
|
||||
<col />
|
||||
<col />
|
||||
<col />
|
||||
<col />
|
||||
<col />
|
||||
<tr align="center" bgcolor="#CFCFCF">
|
||||
<td width="16%"> </td>
|
||||
<td width="12%">BS1</td>
|
||||
<td width="12%">BS2</td>
|
||||
<td width="12%">BS2e</td>
|
||||
<td width="12%">BS2sx</td>
|
||||
<td width="12%">BS2p</td>
|
||||
<td width="12%">BS2pe</td>
|
||||
<td width="12%">BS2px</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td bgcolor="#CFCFCF">Current Draw<br></br>during Run</td>
|
||||
<td>1 mA</td>
|
||||
<td>3 mA</td>
|
||||
<td>25 mA</td>
|
||||
<td>60 mA</td>
|
||||
<td>40 mA</td>
|
||||
<td>15 mA</td>
|
||||
<td>55 mA</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td bgcolor="#CFCFCF">Current Draw<br></br>during <span class="keyword_in_text">SLEEP</span></td>
|
||||
<td>25 µA</td>
|
||||
<td>50 µA</td>
|
||||
<td>200 µA</td>
|
||||
<td>500 µA</td>
|
||||
<td>350 µA</td>
|
||||
<td>36 µA</td>
|
||||
<td>450 µA</td>
|
||||
</tr>
|
||||
<TR ALIGN="center">
|
||||
<TD BGCOLOR="#CFCFCF">Related Commands</TD>
|
||||
<TD COLSPAN="4"><a href="END.htm" target="" title="" alt="" class="MCXref_0">END</a> , <a href="NAP.htm" target="" title="" alt="" class="MCXref_0">NAP</a></TD>
|
||||
<TD COLSPAN="3"><a href="END.htm" target="" title="" alt="" class="MCXref_0">END</a>, <a href="NAP.htm" target="" title="" alt="" class="MCXref_0">NAP</a>, <a href="POLLWAIT.htm" target="" title="" alt="" class="MCXref_0">POLLWAIT</a></TD>
|
||||
</TR>
|
||||
<tr align="center">
|
||||
<td bgcolor="#CFCFCF">Accuracy of <span class="keyword_in_text">SLEEP</span></td>
|
||||
<td colspan="8">±1% @ 75°F with stable power supply</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText"><span class="keyword_in_text">SLEEP</span> allows the BASIC Stamp to turn itself off, then turn back on after
|
||||
a programmed duration. The length of <span class="keyword_in_text">SLEEP</span> can range from 2.3 seconds
|
||||
to slightly over 18 hours. Power consumption is reduced to the amount described
|
||||
in the table above, assuming no loads are being driven. </p>
|
||||
<h3><a name="Sleep"></a>Sleep Units vs Sleep Resolution</h3>
|
||||
<p class="PlainText">The units for <b style="font-style: italic;">Duration</b> are 1 second, but the resolution of the
|
||||
<span class="keyword_in_text">SLEEP</span> instruction is 2.304 seconds. <span class="keyword_in_text">SLEEP</span> rounds the specified
|
||||
number of seconds up to the nearest multiple of 2.304. Because of this, <b style="font-style: italic;">Duration</b> values below 10 are not very accurate.</p>
|
||||
<table cellpadding="4" cellspacing="0" border="1" style="caption-side: top;width: 100%;">
|
||||
<col style="width: 279px;" />
|
||||
<col />
|
||||
<col />
|
||||
<col />
|
||||
<col />
|
||||
<col />
|
||||
<col />
|
||||
<col />
|
||||
<col />
|
||||
<col />
|
||||
<col />
|
||||
<tbody>
|
||||
<tr align="center" bgcolor="#CFCFCF">
|
||||
<td>When the <i>Duration</i> value is...</td>
|
||||
<td style="text-align: center;">1</td>
|
||||
<td style="text-align: center;">2</td>
|
||||
<td style="text-align: center;">3</td>
|
||||
<td style="text-align: center;">4</td>
|
||||
<td style="text-align: center;">5</td>
|
||||
<td style="text-align: center;">6</td>
|
||||
<td style="text-align: center;">7</td>
|
||||
<td style="text-align: center;">8</td>
|
||||
<td style="text-align: center;">9</td>
|
||||
<td style="text-align: center;">10</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td bgcolor="#CFCFCF">Sleep time (in seconds) is approximately...</td>
|
||||
<td style="text-align: center;">2.304</td>
|
||||
<td style="text-align: center;">2.304</td>
|
||||
<td style="text-align: center;">4.608</td>
|
||||
<td style="text-align: center;">4.608</td>
|
||||
<td style="text-align: center;">6.912</td>
|
||||
<td style="text-align: center;">6.912</td>
|
||||
<td style="text-align: center;">9.216</td>
|
||||
<td style="text-align: center;">9.216</td>
|
||||
<td style="text-align: center;">9.216</td>
|
||||
<td style="text-align: center;">11.52</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p> </p>
|
||||
<p class="PlainText">To estimate the actual sleeping period for any <i>Duration</i> value, use this equation:</p>
|
||||
<p class="PlainText">
|
||||
<img src="../../GeneratedImages/Equations/Equation1.png" style="width: 197px;height: 16px;" title="Equation for Sleep period" alt="Ceiling of Duration units divided by 2.304, result multiplied by 2.304" class="MCEquation mcReset" />
|
||||
</p>
|
||||
<p class="PlainText">The open-bottom square brackets indicate the <i>ceiling function</i>, which essentially means "round up the quantity inside to the next integer."</p>
|
||||
<p class="PlainText">For example, <span class="code_in_text">SLEEP 1</span> sleeps for 2.304 seconds:</p>
|
||||
<p>
|
||||
<img src="../../GeneratedImages/Equations/Equation2.png" style="width: 159px;height: 110px;" class="MCEquation mcReset" />
|
||||
</p>
|
||||
<p class="PlainText">And, <span class="code_in_text">SLEEP 10 </span>sleeps for approximately 11.52 seconds:</p>
|
||||
<p> </p>
|
||||
<p>
|
||||
<img src="../../GeneratedImages/Equations/Equation3.png" style="width: 169px;height: 110px;" class="MCEquation mcReset" />
|
||||
</p>
|
||||
<h3>The Watchdog Timer Improves Sleep Accuracy Automatically</h3>
|
||||
<p class="PlainText">Pins retain their previous I/O directions during <span class="keyword_in_text">SLEEP</span>. However, outputs
|
||||
are interrupted every 2.3 seconds during <span class="keyword_in_text">SLEEP</span> due to the way the chip keeps
|
||||
time. The alarm clock that wakes the BASIC Stamp up is called the watchdog timer.
|
||||
The watchdog is a resistor/capacitor oscillator built into the interpreter chip.
|
||||
During <span class="keyword_in_text">SLEEP</span>, the chip periodically wakes up and adjusts a counter to
|
||||
determine how long it has been asleep. If it isn't time to wake up, the chip "hits
|
||||
the snooze bar" and goes back to sleep. </p>
|
||||
<p class="PlainText">To ensure accuracy of <span class="keyword_in_text">SLEEP</span> intervals, the BASIC Stamp periodically
|
||||
compares the watchdog timer to the more-accurate resonator time base. It calculates
|
||||
a correction factor that it uses during <span class="keyword_in_text">SLEEP</span>. As a result, longer
|
||||
<span class="keyword_in_text">SLEEP</span> intervals are accurate to approximately ±1 percent.</p>
|
||||
<p class="PlainText">During execution of power conserving commands (<span class="keyword_in_text">END</span>, <span class="keyword_in_text">NAP</span>, <span class="keyword_in_text">POLLWAIT</span>, and <span class="keyword_in_text">SLEEP</span>), current will occasionally be interrupted
|
||||
on I/O pins for about 18 ms durations (60 µs on the BS2pe). The reason is that the
|
||||
watchdog-timer reset that awakens the BASIC Stamp during these commands also causes all of the pins to
|
||||
switch to input mode for approximately 18 ms (60 µs on the BS2pe). When the interpreter
|
||||
firmware regains control of the processor, it restores the I/O direction dictated
|
||||
by your program.</p>
|
||||
<p class="PlainText">If you plan to use <span class="keyword_in_text">END</span>, <span class="keyword_in_text">NAP</span>, <span class="keyword_in_text">POLLWAIT</span>, or <span class="keyword_in_text">SLEEP</span> in your programs,
|
||||
make sure that your loads can tolerate these power outages. The simplest solution
|
||||
is often to connect resistors high or low (to +5V or ground) as appropriate to
|
||||
ensure a continuing supply of current during the reset. </p>
|
||||
<p class="PlainText">The <a href="../ExampleTopics/SleepEx.htm" target="" title="" alt="" class="MCXref_0">SLEEP Example</a> can be used to demonstrate the
|
||||
effects of this reset with an LED and resistor.</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>
|
113
help/BasicStampHelp/Content/LanguageTopics/Commands/SOUND.htm
Normal file
113
help/BasicStampHelp/Content/LanguageTopics/Commands/SOUND.htm
Normal file
@ -0,0 +1,113 @@
|
||||
<?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>SOUND</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">SOUND</h1>
|
||||
<div class="ImagePlusCaption">
|
||||
<div class="Col2">
|
||||
<p>
|
||||
<img src="../../graphics/pgm_icon1.gif" border="0" alt="BS1 icon" title="BS1 icon" /><span class="code_in_text"> {PBASIC 1.0}</span>
|
||||
</p>
|
||||
</div>
|
||||
<p style="text-align: right;"><a href="../ExampleTopics/SoundEx.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">SOUND Example</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: <span class="keyword_in_text">SOUND</span> <![CDATA[ ]]><i>Pin</i>, (<i>Note</i>,<i> Duration </i>{,<i> Note, Duration</i>...})</p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Generate square-wave tones for a specified duration.
|
||||
|
||||
</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Pin</i></b> is a variable/constant (0 - 7) that specifies the I/O pin
|
||||
to use. This pin will be set to output mode.</li>
|
||||
<li value="2"><b><i>Note</i></b> is a variable/constant (0 - 255) specifying the type and
|
||||
frequency of the tone. 1 - 127 are ascending tones and 128 - 255 are ascending
|
||||
white noises ranging from buzzing (128) to hissing (255).</li>
|
||||
<li value="3"><b><i>Duration</i></b> is a variable/constant (1 - 255) specifying the amount
|
||||
of time to generate the tone(s). The unit of time for <i>Duration</i> is 12
|
||||
ms.</li>
|
||||
</ul>
|
||||
<p class="PlainText">Note: See <a href="FREQOUT.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">FREQOUT</a> for all BS2 models.</p>
|
||||
<h2>Quick Facts</h2>
|
||||
<table cellpadding="4" cellspacing="0" border="1" style="caption-side: top;width: 100%;">
|
||||
<col />
|
||||
<col />
|
||||
<tr bgcolor="#CFCFCF">
|
||||
<td width="15%" align="center"> </td>
|
||||
<td width="85%" align="center">BS1</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Units in Duration</td>
|
||||
<td>
|
||||
<p align="center">12 ms</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Available Sounds</td>
|
||||
<td>
|
||||
<p align="center">256</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Frequency Range</td>
|
||||
<td>
|
||||
<p align="center">94.8 Hz to 10,550 Hz</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText"><span class="keyword_in_text">SOUND</span> generates one of 255 square-wave frequencies on an I/O pin. The output
|
||||
pin should be connected as shown in the circuits below. </p>
|
||||
<p class="PlainText">The tones produced by <span class="keyword_in_text">SOUND</span> can vary in frequency from 94.8 Hz (1) to
|
||||
10,550 Hz (127). If you need to determine the frequency corresponding to a given
|
||||
note value, or need to find the note value that will give you best approximation
|
||||
for a given frequency, use the equations below.</p>
|
||||
<center>Note = 127 - (((1 ÷ Frequency) - 0.000095) ÷ 0.000083)
|
||||
<br></br><br></br>-- and --
|
||||
<br></br><br></br>Frequency = (1 ÷ (0.000095 + ((127 - Note) x 0.000083))
|
||||
</center>
|
||||
<p class="PlainText"> </p>
|
||||
<p class="PlainText">Note, in the above equations, Frequency is in Hertz (Hz).</p>
|
||||
<center>
|
||||
<img src="../../graphics/freqout_sch.gif" border="0" />
|
||||
</center>
|
||||
<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>
|
94
help/BasicStampHelp/Content/LanguageTopics/Commands/STOP.htm
Normal file
94
help/BasicStampHelp/Content/LanguageTopics/Commands/STOP.htm
Normal file
@ -0,0 +1,94 @@
|
||||
<?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>STOP</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">STOP</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" />
|
||||
</p>
|
||||
</div>
|
||||
<p style="text-align: right;"><a href="../ExampleTopics/StopEx.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">STOP Example</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: <span class="keyword_in_text">STOP</span></p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Stops program execution.</p>
|
||||
<h2>Quick Facts</h2>
|
||||
<table cellpadding="4" cellspacing="0" border="1" style="caption-side: top;width: 100%;">
|
||||
<col />
|
||||
<col />
|
||||
<tr bgcolor="#CFCFCF">
|
||||
<td width="15%" align="center"> </td>
|
||||
<td width="85%" align="center">All BS2 models</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Command</td>
|
||||
<td>
|
||||
<p align="center"><a href="END.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">END</a>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText"><span class="keyword_in_text">STOP</span> prevents the BASIC Stamp from executing any further instructions
|
||||
until it is reset. The following actions will reset the BASIC Stamp:</p>
|
||||
<ol>
|
||||
<li value="1">Pressing and releasing the RESET button on the development board.</li>
|
||||
<li value="2">Driving the RES pin low then letting it float (high).</li>
|
||||
<li value="3">Downloading a new program.</li>
|
||||
<li value="4">Disconnecting then reconnecting the power.</li>
|
||||
</ol>
|
||||
<p class="PlainText"><span class="keyword_in_text">STOP</span> differs from <span class="keyword_in_text">END</span> in two respects:</p>
|
||||
<ol>
|
||||
<li value="1"><span class="keyword_in_text">STOP</span> does not put the BASIC Stamp into low-power mode. The BASIC
|
||||
Stamp draws just as much current as if it were actively running program
|
||||
instructions.</li>
|
||||
<li value="2">The output glitch that occurs after a program has been halted with <span class="keyword_in_text">END</span> does not occur after a program that uses <span class="keyword_in_text">STOP</span>.</li>
|
||||
</ol>
|
||||
<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>
|
125
help/BasicStampHelp/Content/LanguageTopics/Commands/STORE.htm
Normal file
125
help/BasicStampHelp/Content/LanguageTopics/Commands/STORE.htm
Normal file
@ -0,0 +1,125 @@
|
||||
<?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>STORE</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">STORE</h1>
|
||||
<div class="ImagePlusCaption">
|
||||
<div class="Col2">
|
||||
<p>
|
||||
<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/StoreEx.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">STORE Examples</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: <span class="keyword_in_text">STORE </span> <![CDATA[ ]]><i>ProgramSlot</i></p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Designate a program slot for the <span class="keyword_in_text">READ</span> and <span class="keyword_in_text">WRITE</span> instructions to
|
||||
operate upon.
|
||||
|
||||
</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>ProgramSlot</i></b> is a variable/constant/expression (BS2p and
|
||||
BS2px: 0 – 7, BS2pe: 0 - 15) that specifies the program slot<sup>†</sup>to use for <span class="keyword_in_text">READ</span> and <span class="keyword_in_text">WRITE</span> instructions.</li>
|
||||
</ul>
|
||||
<p><sup>†</sup> Note: On the BS2pe, slots 8 - 15 are only available
|
||||
for data (<span class="keyword_in_text">READ</span> and <span class="keyword_in_text">WRITE</span>); they cannot be used to run programs.
|
||||
|
||||
</p>
|
||||
<h2>Quick Facts</h2>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr>
|
||||
<td width="20%" align="center" bgcolor="#CFCFCF"> </td>
|
||||
<td width="40%" align="center" bgcolor="#CFCFCF">BS2p and BS2px</td>
|
||||
<td width="40%" align="center" bgcolor="#CFCFCF">BS2pe</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Program Slot Range</td>
|
||||
<td align="center">0 - 7</td>
|
||||
<td align="center">0 - 15</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
||||
<td colspan="2" align="center"><a href="READ.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">READ</a>, <a href="WRITE.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">WRITE</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText"><span class="keyword_in_text">STORE</span> tells the BS2p, BS2pe, or BS2px which program slot to use
|
||||
when a <span class="keyword_in_text">READ</span> or <span class="keyword_in_text">WRITE</span> instruction is executed. The <span class="keyword_in_text">STORE</span> command
|
||||
only affects the <span class="keyword_in_text">READ</span> and <span class="keyword_in_text">WRITE</span> instructions.</p>
|
||||
<p class="PlainText">The <span class="keyword_in_text">STORE</span> command allows a program to access all EEPROM locations that
|
||||
exist on the BS2p, BS2pe, and BS2px, regardless of which program is running or which
|
||||
program slot is active. The <span class="keyword_in_text">READ</span> and <span class="keyword_in_text">WRITE</span> commands can only access
|
||||
locations 0 to 2047 within a single program slot. The <span class="keyword_in_text">STORE</span> command
|
||||
switches the program slot that the <span class="keyword_in_text">READ</span> and <span class="keyword_in_text">WRITE</span> commands operate
|
||||
on. This short subroutine demonstrates the use of <span class="keyword_in_text">STORE</span>:</p><pre class="BScode" xml:space="preserve">
|
||||
Move_Block:
|
||||
FOR idx = 0 TO (blockLen - 1) ' move blockLen bytes
|
||||
STORE srcSlot ' point to source slot
|
||||
READ srcAddr + idx, eeByte ' read source byte
|
||||
STORE tgtSlot ' point to target slot
|
||||
WRITE tgtAddr + idx, eeByte ' write byte to target slot
|
||||
NEXT
|
||||
RETURN
|
||||
</pre>
|
||||
<p class="PlainText">The default program slot that the <span class="keyword_in_text">READ</span> and <span class="keyword_in_text">WRITE</span> instructions
|
||||
operate on is the currently running program. The <span class="keyword_in_text">STORE</span> command can be used
|
||||
to temporarily change this, to any program slot. The change will remain in effect
|
||||
until another <span class="keyword_in_text">STORE</span> command is issued, or until another program slot is
|
||||
executed. The current slot used by <span class="keyword_in_text">READ</span> and <span class="keyword_in_text">WRITE</span> (as set by
|
||||
<span class="keyword_in_text">STORE</span>) can be read from byte 127 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
|
||||
GET 63, pgmSlot ' read current slot
|
||||
rwSlot = pgmSlot ' READ/WRITE slot is same
|
||||
#CASE BS2P, BS2PE, BS2PX
|
||||
GET 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>
|
142
help/BasicStampHelp/Content/LanguageTopics/Commands/TOGGLE.htm
Normal file
142
help/BasicStampHelp/Content/LanguageTopics/Commands/TOGGLE.htm
Normal file
@ -0,0 +1,142 @@
|
||||
<?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>TOGGLE</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">TOGGLE</h1>
|
||||
<div class="ImagePlusCaption">
|
||||
<div class="Col2">
|
||||
<p>
|
||||
<img src="../../graphics/pgm_icon1.gif" border="0" alt="BS1 icon" title="BS1 icon" />
|
||||
<img src="../../graphics/pgm_icon2.gif" border="0" alt="BS2 icon" title="BS2 icon" />
|
||||
<img src="../../graphics/pgm_icon2e.gif" border="0" alt="BS2e icon" title="BS2e icon" />
|
||||
<img src="../../graphics/pgm_icon2sx.gif" border="0" alt="BS2sx icon" title="BS2sx icon" />
|
||||
<img src="../../graphics/pgm_icon2p.gif" border="0" alt="BS2p icon" title="BS2p icon" />
|
||||
<img src="../../graphics/pgm_icon2pe.gif" border="0" alt="BS2pe icon" title="BS2pe icon" />
|
||||
<img src="../../graphics/pgm_icon2px.gif" border="0" alt="BS2px icon" title="BS2px icon" />
|
||||
</p>
|
||||
</div>
|
||||
<p style="text-align: right;"><a href="../ExampleTopics/ToggleEx.htm" target="" title="" alt="" class="MCXref_0">TOGGLE Examples</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: <span class="keyword_in_text">TOGGLE</span> <![CDATA[ ]]><i>Pin</i></p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Invert the state of an output pin.
|
||||
|
||||
</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Pin</i></b> is a variable/constant/expression* (0 – 15) that
|
||||
specifies which I/O pin to set high. This pin will be placed into output
|
||||
mode.</li>
|
||||
</ul>
|
||||
<p class="PlainText">*<img src="../../graphics/bs1note.gif" style="vertical-align: super;" /> Note: expressions are not allowed as arguments on the BS1. The range
|
||||
of the <i>Pin</i> argument on the BS1 is 0–7.</p>
|
||||
<h2>Quick Facts</h2>
|
||||
<table cellpadding="4" cellspacing="0" border="1" style="caption-side: top;width: 100%;">
|
||||
<col />
|
||||
<col />
|
||||
<tr bgcolor="#CFCFCF">
|
||||
<td width="20%" align="center"> </td>
|
||||
<td width="40%" align="center">BS1</td>
|
||||
<td width="40%" align="center">All BS2 models</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="20%" align="center" bgcolor="#CFCFCF">Affected Register</td>
|
||||
<td width="40%" align="center">PINS</td>
|
||||
<td width="40%" align="center">OUTS</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
||||
<td align="center" colspan="2">
|
||||
<p colspan="2" align="center"><a href="HIGH.htm" target="" title="" alt="" class="MCXref_0">HIGH</a>, <a href="LOW.htm" target="" title="" alt="" class="MCXref_0">LOW</a></p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText"><span class="keyword_in_text">TOGGLE</span> sets a pin to output mode and inverts the output state of the pin,
|
||||
changing 0 to 1 and 1 to 0.</p>
|
||||
<p class="PlainText">In some situations <span class="keyword_in_text">TOGGLE</span> may appear to have no effect on a pin's state.
|
||||
For example, suppose pin 2 is in input mode and pulled to +5V by a 10 kΩ
|
||||
resistor. Then the following code executes:</p>
|
||||
<p>
|
||||
<img src="../../graphics/bs1_inline.gif" border="0">
|
||||
</img>
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
Main:
|
||||
DIR2 = 0 ' pin 2 in input mode
|
||||
PIN2 = 0 ' pin 2 output driver low
|
||||
DEBUG PIN2 ' show state of pin 2
|
||||
TOGGLE 2 ' toggle pin 2
|
||||
DEBUG PIN2 ' show state of pin 2
|
||||
END
|
||||
</pre>
|
||||
<p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0">
|
||||
</img>
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
Main:
|
||||
DIR2 = 0 ' pin 2 in input mode
|
||||
OUT2 = 0 ' pin 2 output driver low
|
||||
DEBUG ? IN2 ' show state of pin 2
|
||||
TOGGLE 2 ' toggle pin 2
|
||||
DEBUG ? IN2 ' show state of pin 2
|
||||
END
|
||||
</pre>
|
||||
<p class="PlainText">The state of pin 2 doesn't change; it's high (due to the pull-up resistor)
|
||||
before <span class="keyword_in_text">TOGGLE</span>, and it's high (due to the pin being output high) afterward.
|
||||
The point is that <span class="keyword_in_text">TOGGLE</span> works on the OUTS register, which may not match
|
||||
the pin's state when the pin is initially an input. To guarantee that the state
|
||||
actually changes, regardless of the initial input or output mode, do this:</p>
|
||||
<p>
|
||||
<img src="../../graphics/bs1_inline.gif" border="0">
|
||||
</img>
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
PIN2 = PIN2 ' make output driver match pin state
|
||||
TOGGLE 2 ' then toggle
|
||||
</pre>
|
||||
<p>
|
||||
<img valign="bottom" src="../../graphics/bs2all_inline.gif" border="0">
|
||||
</img>
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
OUT2 = IN2 ' make output driver match pin state
|
||||
TOGGLE 2 ' then toggle
|
||||
</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>
|
244
help/BasicStampHelp/Content/LanguageTopics/Commands/WRITE.htm
Normal file
244
help/BasicStampHelp/Content/LanguageTopics/Commands/WRITE.htm
Normal file
@ -0,0 +1,244 @@
|
||||
<?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>WRITE</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">WRITE</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" /><span class="code_in_text"> {PBASIC 2.5}</span>
|
||||
</p>
|
||||
</div>
|
||||
<p style="text-align: right;"><a href="../ExampleTopics/WriteEx.htm" target="" title="" alt="" class="MCXref_0">WRITE Examples</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax <img align="absmiddle" src="../../graphics/mini_1.gif" />:
|
||||
<span class="keyword_in_text">WRITE</span> <![CDATA[ ]]><i>Location</i>,<i><![CDATA[ ]]>Value</i><br />Syntax <img align="absmiddle" src="../../graphics/mini_2_inline.gif" />:
|
||||
<span class="keyword_in_text">WRITE</span> <![CDATA[ ]]><i>Location, </i>{Word}<i><![CDATA[ ]]>Value <![CDATA[ ]]></i>{, {Word}<i><![CDATA[ ]]>Value ...</i>}</p>
|
||||
<h2>Function</h2>
|
||||
<p class="PlainText">Write <i>Value</i> into <i>Location</i> in EEPROM. On the BS2 family, multiple
|
||||
<i>Value</i> may be written to consecutive locations.‡
|
||||
|
||||
</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Location</i></b> is a variable/constant/expression* (0 - 255 on BS1,
|
||||
0 - 2047 on all other BASIC Stamp modules) that specifies the EEPROM address to
|
||||
write to.</li>
|
||||
<li value="2"><b><i>Value</i></b> is a variable/constant/expression* (0 - 255, or 0 - 65535 if using the optional Word modifier‡) specifying the
|
||||
value to be stored. </li>
|
||||
</ul>
|
||||
<p class="PlainText">*<img src="../../graphics/bs1note.gif" style="vertical-align: super;" /> Note: expressions are not allowed as arguments on the BS1.</p>
|
||||
<p class="PlainText">‡Note: The optional arguments require PBASIC 2.5.</p>
|
||||
<h2>Quick Facts</h2>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<col />
|
||||
<col style="width: 214px;" />
|
||||
<col />
|
||||
<col />
|
||||
<col />
|
||||
<tr>
|
||||
<td width="16%" align="center" bgcolor="#CFCFCF"> </td>
|
||||
<td align="center" bgcolor="#CFCFCF">BS1</td>
|
||||
<td width="21%" align="center" bgcolor="#CFCFCF">BS2</td>
|
||||
<td width="21%" align="center" bgcolor="#CFCFCF">BS2e and BS2sx</td>
|
||||
<td width="21%" align="center" bgcolor="#CFCFCF">BS2p, BS2pe, and BS2px</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Range of EEPROM locations</td>
|
||||
<td align="center">0 to 255</td>
|
||||
<td align="center">0 to 2047</td>
|
||||
<td align="center">0 to 2047</td>
|
||||
<td align="center">0 to 2047<br></br>(see notes below)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Maximum number of writes per location</td>
|
||||
<td align="center">10 million</td>
|
||||
<td align="center">10 million</td>
|
||||
<td align="center">100,000</td>
|
||||
<td align="center">100,000</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Special Notes</td>
|
||||
<td align="center">N/A</td>
|
||||
<td align="center">N/A</td>
|
||||
<td align="center"><span class="keyword_in_text">WRITE</span> only works with current program slot on BS2e
|
||||
and BS2sx.</td>
|
||||
<td align="center"><span class="keyword_in_text">WRITE</span> works with any program slot as set by the
|
||||
<span class="keyword_in_text">STORE</span> command.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
||||
<td align="center" colspan="1">
|
||||
<p colspan="1" align="center"><a href="READ.htm" target="" title="" alt="" class="MCXref_0">READ</a>, <a href="EEPROM.htm" target="" title="" alt="" class="MCXref_0">EEPROM</a></p>
|
||||
</td>
|
||||
<td align="center" colspan="2">
|
||||
<p colspan="2" align="center"><a href="READ.htm" target="" title="" alt="" class="MCXref_0">READ</a>, <a href="DATA.htm" target="" title="" alt="" class="MCXref_0">DATA</a></p>
|
||||
</td>
|
||||
<td align="center" colspan="1">
|
||||
<p colspan="1" align="center"><a href="READ.htm" target="" title="" alt="" class="MCXref_0">READ</a>, <a href="DATA.htm" target="" title="" alt="" class="MCXref_0">DATA</a>, <a href="STORE.htm" target="" title="" alt="" class="MCXref_0">STORE</a></p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">PBASIC 2.5 Syntax Options</td>
|
||||
<td align="center">n/a</td>
|
||||
<td align="center" colspan="3">Multiple sequential variables may be writtten to the Scratch Pad RAM, and the optional WORD modifier may be specified to store 16-bit values.</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText">The EEPROM is used for both program storage (which builds downward from address
|
||||
255 on BS1, 2047 on all other BASIC Stamp models) and data storage (which builds upward
|
||||
from address 0). The <span class="keyword_in_text">WRITE</span> instruction stores a value to any EEPROM
|
||||
address. Any location within the EEPROM can be written to (including your PBASIC
|
||||
program's locations) at run-time. This feature is mainly used to store long-term
|
||||
data to EEPROM; data stored in EEPROM is not lost when the power is removed.</p>
|
||||
<p class="PlainText">The following <span class="keyword_in_text">WRITE</span> command stores the value 245 at location 100:</p><pre class="BScode" xml:space="preserve">
|
||||
WRITE 100, 245
|
||||
</pre>
|
||||
<p class="PlainText">The EEPROM is organized as a sequential set of byte-sized memory locations.
|
||||
With the BS1, the <span class="keyword_in_text">WRITE</span> instruction only stores byte-sized values into
|
||||
EEPROM. This does not mean that you can't write word-sized values, however.
|
||||
A word consists of two bytes, called a low-byte and a high-byte. If you wanted
|
||||
to write a word-sized value, you'll need to use two <span class="keyword_in_text">WRITE</span> commands and a
|
||||
word-size value or variable (along with some handy modifiers). For example:</p>
|
||||
<p>
|
||||
<img src="../../graphics/bs1_inline.gif" border="0">
|
||||
</img>
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
SYMBOL value = W1 ' word-sized variable
|
||||
SYMBOL valLo = B2 ' B2 is the low-byte of W1
|
||||
SYMBOL valHi = B3 ' B3 is the high-byte of W1
|
||||
|
||||
Main:
|
||||
value = 1125
|
||||
|
||||
WRITE 0, valLo
|
||||
WRITE 1, valHi
|
||||
END
|
||||
</pre>
|
||||
<p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0">
|
||||
</img>
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
value VAR Word
|
||||
|
||||
Main:
|
||||
value = 1125
|
||||
WRITE 0, value.LowByte
|
||||
WRITE 1, value.HighByte
|
||||
END
|
||||
</pre>
|
||||
<p class="PlainText">When this program runs, the two <span class="keyword_in_text">WRITE</span> commands will store the low-byte
|
||||
and high-byte of the number 1125 into EEPROM.</p>
|
||||
<p class="PlainText">With the BS2 family, the Word modifier can be used to write 16-bit values.
|
||||
The low byte of the value will be written to <i>Location</i>, the high byte will
|
||||
be written to <i>Location + 1</i> (<i>"Little Endian"</i> ).</p>
|
||||
<p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0">
|
||||
</img>
|
||||
</p><pre class="BScode" xml:space="preserve">
|
||||
' {$PBASIC 2.5}
|
||||
|
||||
value VAR Word
|
||||
value2 VAR Word
|
||||
addr VAR Word ' EEPROM address
|
||||
test VAR Byte ' test byte read back
|
||||
|
||||
Main:
|
||||
value = $1125
|
||||
value2 = $2003
|
||||
WRITE 0, Word value, Word value2 ' write value at locations 0 & 1
|
||||
' and value2 at locations 2 & 3
|
||||
|
||||
FOR addr = 0 TO 3 ' display "25 11 03 20"
|
||||
READ addr, test
|
||||
DEBUG HEX2 test, " "
|
||||
NEXT
|
||||
|
||||
END
|
||||
</pre>
|
||||
<p class="PlainText">EEPROM differs from RAM, the memory in which variables are stored, in several
|
||||
respects: </p>
|
||||
<ol>
|
||||
<li value="1">Writing to EEPROM takes more time than storing a value in a variable.
|
||||
Depending on many factors, it may take several milliseconds for the EEPROM to
|
||||
complete a write. RAM storage is nearly instantaneous. </li>
|
||||
<li value="2">The EEPROM can only accept a finite number of write cycles per location
|
||||
before it wears out. The table above indicates the guaranteed number of writes
|
||||
before failure. If a program frequently writes to the same EEPROM location,
|
||||
it makes sense to estimate how long it might take to exceed the guaranteed
|
||||
maximum. For example, on the BS2, at one write per second (86,400 writes/day)
|
||||
it would take nearly 116 days of continuous operation to exceed 10 million. </li>
|
||||
<li value="3">The primary function of the EEPROM is to store programs (data is stored in
|
||||
leftover space). If data overwrites a portion of your program, the program
|
||||
will most likely crash. </li>
|
||||
</ol>
|
||||
<p class="PlainText">Check the program's memory map to determine what portion of memory your program
|
||||
occupies and make sure that EEPROM writes cannot stray into this area. You may also
|
||||
use the DATA directive on the BS2, BS2e, BS2sx, BS2p, and BS2pe to set aside EEPROM
|
||||
space. </p>
|
||||
<p>
|
||||
<img src="../../graphics/bs1_inline.gif" border="0">
|
||||
</img>
|
||||
</p>
|
||||
<p class="PlainText">On the BS1, location 255 holds the address of the last instruction in your
|
||||
program. Therefore, your program can use any space below the address given in
|
||||
location 255. For example, if location 255 holds the value 100, then your program
|
||||
can use locations 0-99 for data.</p>
|
||||
<p>
|
||||
<img src="../../graphics/bs2all_inline.gif" border="0">
|
||||
</img>
|
||||
</p>
|
||||
<p class="PlainText">On other BASIC Stamp models, you'll need to view the Memory Map of the program before
|
||||
you download it, to determine the last EEPROM location used. </p>
|
||||
<p>
|
||||
<img src="../../graphics/bs2ppepx_inline.gif" border="0">
|
||||
</img>
|
||||
</p>
|
||||
<p class="PlainText">On the BS2p, BS2pe and BS2px the <span class="keyword_in_text">READ</span> and <span class="keyword_in_text">WRITE</span> commands can
|
||||
affect locations in any program slot as set by the <span class="keyword_in_text">STORE</span> command. See the <a href="STORE.htm" target="" title="" alt="" class="MCXref_0">STORE</a> command for more information.</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>
|
199
help/BasicStampHelp/Content/LanguageTopics/Commands/XOUT.htm
Normal file
199
help/BasicStampHelp/Content/LanguageTopics/Commands/XOUT.htm
Normal file
@ -0,0 +1,199 @@
|
||||
<?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>XOUT</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">XOUT</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" />
|
||||
</p>
|
||||
</div>
|
||||
<p style="text-align: right;"><a href="../ExampleTopics/XoutEx.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">XOUT Example</a>
|
||||
</p>
|
||||
<p> </p>
|
||||
</div>
|
||||
<p class="clear"> </p>
|
||||
<p> </p>
|
||||
<p class="PlainText">Syntax: <span class="keyword_in_text">XOUT</span> <![CDATA[ ]]><i>Mpin</i>,<i> Zpin</i>,<i><![CDATA[ ]]></i>[<i>House</i>\<i>Command </i>{\<i>Cycles</i>} {,<i> House</i>\<i>Command </i>{\<i>Cycles</i>}...}]</p>
|
||||
<h2>Function</h2>
|
||||
<p>Send an X-10 power-line control command (through the appropriate power-line interface).
|
||||
|
||||
</p>
|
||||
<ul>
|
||||
<li value="1"><b><i>Mpin</i></b> is a variable/constant/expression (0 - 15) that specifies
|
||||
the I/O pin to output X-10 signals (modulation) to the power-line interface
|
||||
device. This pin will be set to output mode.</li>
|
||||
<li value="2"><b><i>Zpin</i></b> is a variable/constant/expression (0 - 15) that specifies
|
||||
the I/O pin that inputs the zero-crossing signal from the power-line interface
|
||||
device. This pin will be set to input mode.</li>
|
||||
<li value="3"><b><i>House</i></b> is a variable/constant/expression (0 - 15) that specifies
|
||||
the X-10 house code (values 0 - 15 representing letters A through P).</li>
|
||||
<li value="4"><b><i>Command</i></b> is a variable/constant/expression (0 - 30) that specifies
|
||||
the command to send. Values 0 - 15 correspond to unit codes 1 - 16. Other
|
||||
commands are shown below.</li>
|
||||
<li value="5"><b><i>Cycles</i></b><i>is an optional variable/constant/expression (1 - 255)
|
||||
specifying the number of times to transmit a given key or command. If no
|
||||
I>Cycles </i> entry is used, XOUT defaults to two. The <i>Cycles</i> entry
|
||||
should be used only with the DIM and BRIGHT command codes.</li>
|
||||
</ul>
|
||||
<h2>Quick Facts</h2>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr>
|
||||
<td width="25%" align="center" bgcolor="#CFCFCF"> </td>
|
||||
<td width="75%" align="center" bgcolor="#CFCFCF">All BS2 Models</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Compatible power-line interfaces</td>
|
||||
<td align="center">PL-513 and TW-523</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Special Notes</td>
|
||||
<td align="left">The <span class="keyword_in_text">XOUT</span> command will stop the BASIC Stamp program
|
||||
until it is able to send the transmission. If there is no AC power to the
|
||||
power-line interface, the BASIC Stamp program will halt forever.</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2>Explanation</h2>
|
||||
<p class="PlainText"><span class="keyword_in_text">XOUT</span> lets you control appliances via signals sent through household AC wiring
|
||||
to X-10 modules. The appliances plugged into these modules can be switched on or
|
||||
off; lights may also be dimmed. Each module is assigned a house code and unit code
|
||||
by setting dials or switches on the module. To talk to a particular module,
|
||||
<span class="keyword_in_text">XOUT</span> sends the appropriate house code and unit code. The module with the
|
||||
corresponding code listens for its house code again followed by a command (on,
|
||||
off, dim, or bright).</p>
|
||||
<p class="PlainText">X-10 signals are digital codes imposed on a 120 kHz carrier that is transmitted
|
||||
during zero crossings of the AC line. To send X-10 commands, a controller must
|
||||
synchronize to the AC line frequency with 50 ms precision, and transmit an 11-bit
|
||||
code sequence representing the command.</p>
|
||||
<p class="PlainText"><span class="keyword_in_text">XOUT</span> interfaces to the AC power-line through an approved interface device
|
||||
such as a PL-513 or TW-523, available from Parallax or X-10 dealers. The hookup
|
||||
requires a length of four-conductor phone cable and a standard modular phone-base
|
||||
connector (6P4C type). Connections are shown below. </p>
|
||||
<center>
|
||||
<img src="../../graphics/xout_sch.gif" width="233" height="326" border="0">
|
||||
</img>
|
||||
</center>
|
||||
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
||||
<tr>
|
||||
<td width="20%" align="center" bgcolor="#CFCFCF">Command</td>
|
||||
<td width="20%" align="center" bgcolor="#CFCFCF">Value</td>
|
||||
<td width="60%" align="center" bgcolor="#CFCFCF">Function</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">UnitOn</td>
|
||||
<td align="center">%10010</td>
|
||||
<td align="left">Turn on the currently selected unit.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">UnitOff</td>
|
||||
<td align="center">%11010</td>
|
||||
<td align="left">Turn off the currently selected unit.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">UnitsOff</td>
|
||||
<td align="center">%11100</td>
|
||||
<td align="left">Turn off all modules in this house code.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">LightsOn</td>
|
||||
<td align="center">%10100</td>
|
||||
<td align="left">Turn on all lamp modules in this house code.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Dim</td>
|
||||
<td align="center">%11110</td>
|
||||
<td align="left">Reduce brightness of currently selected lamp.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" bgcolor="#CFCFCF">Bright</td>
|
||||
<td align="center">%10110</td>
|
||||
<td align="left">Increase brightness of currently selected lamp.</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p> </p>
|
||||
<p class="Tip" MadCap:autonum="Tip:  "><span class="autonumber"><span class="TipSpan">Tip:  </span></span>In most applications, it's not necessary to know the code for a
|
||||
given X-10 instruction. Just use the command constant (UnitOn, Dim, etc.) instead.
|
||||
But knowing the codes leads to some interesting possibilities. For example, XORing
|
||||
a UnitOn command with the value %1000 turns it into a UnitOff command, and vice-versa.
|
||||
This makes it possible to write the equivalent of an X-10 "toggle" instruction. </p>
|
||||
<p class="PlainText">Here is an example of the <span class="keyword_in_text">XOUT</span> instruction: </p><pre class="BScode" xml:space="preserve">
|
||||
Mpin PIN 1 ' modulation pin
|
||||
Zpin PIN 0 ' zero-cross input
|
||||
|
||||
HouseA CON 0 ' House code A = 0
|
||||
Unit1 CON 0 ' Unit code 1 = 0
|
||||
|
||||
Main:
|
||||
XOUT Mpin, Zpin, [HouseA\Unit1] ' Get unit 1's attention..
|
||||
XOUT Mpin, Zpin, [HouseA\UnitOn] ' ..and tell it to turn on
|
||||
END
|
||||
</pre>
|
||||
<p class="PlainText">You can combine those two <span class="keyword_in_text">XOUT</span> instructions into one like so: <br /></p><pre class="BScode" xml:space="preserve">
|
||||
XOUT Mpin, Zpin, [HouseA\Unit1\2, HouseA\UnitOn]
|
||||
</pre>
|
||||
<p class="PlainText">Note that to complete the attention-getting code HouseA\Unit1 we tacked on the
|
||||
normally optional cycles entry \2 to complete the command before beginning the next
|
||||
one. Always specify two cycles in multiple commands unless you're adjusting the
|
||||
brightness of a lamp module. </p>
|
||||
<p class="PlainText">Here is an example of a lamp-dimming instruction: </p><pre class="BScode" xml:space="preserve">
|
||||
Mpin PIN 1 ' modulation pin
|
||||
Zpin PIN 0 ' zero-cross input
|
||||
|
||||
HouseA CON 0 ' House code A = 0
|
||||
Unit1 CON 0 ' Unit code 1 = 0
|
||||
|
||||
Main:
|
||||
' Get unit 1's attention
|
||||
XOUT Mpin, Zpin, [HouseA\Unit1]
|
||||
' Dim halfway
|
||||
XOUT Mpin, Zpin, [HouseA\UnitOff\2, HouseA\Dim\10]
|
||||
END
|
||||
</pre>
|
||||
<p class="PlainText">The dim/bright commands support 19 brightness levels. Lamp modules may also be
|
||||
turned on and off using the standard UnitOn and UnitOff commands. In the example
|
||||
instruction above, we dimmed the lamp by first turning it completely off, then
|
||||
sending 10 cycles of the Dim command. This may seem odd, but it follows the
|
||||
peculiar logic of the X-10 system. </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