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/SHIFTIN.htm

205 lines
12 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>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>&#160;</p>
</div>
<p class="clear">&#160;</p>
<p>&#160;</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">&#160;</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 ©&#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>