227 lines
13 KiB
HTML
227 lines
13 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>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>
|