270 lines
15 KiB
HTML
270 lines
15 KiB
HTML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|
<html xmlns:MadCap="http://www.madcapsoftware.com/Schemas/MadCap.xsd" MadCap:lastBlockDepth="6" MadCap:lastHeight="94" MadCap:lastWidth="853" MadCap:disableMasterStylesheet="true" MadCap:tocPath="" MadCap:InPreviewMode="false" MadCap:PreloadImages="false" MadCap:RuntimeFileType="Topic" MadCap:TargetType="WebHelp" lang="en-us" xml:lang="en-us" MadCap:PathToHelpSystem="../../../" MadCap:HelpSystemFileName="Default.xml" MadCap:SearchType="Stem">
|
|
<head><title>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> |