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

264 lines
16 KiB
HTML
Raw Normal View History

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns:MadCap="http://www.madcapsoftware.com/Schemas/MadCap.xsd" MadCap:lastBlockDepth="6" MadCap:lastHeight="94" MadCap:lastWidth="853" MadCap:disableMasterStylesheet="true" MadCap:tocPath="" MadCap:InPreviewMode="false" MadCap:PreloadImages="false" MadCap:RuntimeFileType="Topic" MadCap:TargetType="WebHelp" lang="en-us" xml:lang="en-us" MadCap:PathToHelpSystem="../../../" MadCap:HelpSystemFileName="Default.xml" MadCap:SearchType="Stem">
<head><title>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>&#160;</p>
</div>
<p class="clear">&#160;</p>
<p>&#160;</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">&#160;</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>&#160;</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 ©&#160;<span class="ContactInfoCompanyName">Parallax Inc.</span></p>
<p style="text-align: right;"><span class="SystemShortDate">8/8/2012</span>
</p>
</div>
</div>
<script type="text/javascript">/* <![CDATA[ */
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-285614-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
/* ]]> */</script>
<script type="text/javascript" src="../../SkinSupport/MadCapBodyEnd.js">
</script>
</body>
</html>