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/ExampleTopics/StoreEx.htm

239 lines
9.3 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>STORE Examples</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>STORE Examples</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;">Syntax: <a href="../Commands/STORE.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">STORE</a></p>
<p>&#160;</p>
</div>
<p class="clear">&#160;</p>
<p class="PlainText">&#160;</p>
<p>NOTE: This is written for the BS2p and will also run on the BS2pe and BS2px. Modify the $STAMP directive (as required) before downloading to the BS2pe or BS2px.</p><pre class="BScode" xml:space="preserve">' STORE0.BSP
' This program demonstrates the STORE command and how it affects the READ
' and WRITE commands. This program "STORE0.BSP" is intended to be down-
' loaded into program slot 0. It is meant to work with STORE1.BSP and
' STORE2.BSP. Each program is very similar (they display the current
' Program Slot and READ/WRITE Slot numbers and the values contained in the
' first five EEPROM locations. Each program slot will have different data
' due to different DATA commands in each of the programs downloaded.
' {$STAMP BS2p, STORE1.BSP, STORE2.BSP}
' {$PBASIC 2.5}
#IF ($STAMP &lt; BS2P) #THEN
#ERROR "This program requires BS2p, BS2pe, or BS2px"
#ENDIF
idx VAR Word ' index
value VAR Byte
LocalData DATA @0, 1, 2, 3, 4, 5
Main:
GOSUB Show_Slot_Info ' show slot info/data
PAUSE 2000
STORE 1 ' point READ/WRITE to Slot 1
GOSUB Show_Slot_Info
PAUSE 2000
RUN 1 ' run program in Slot 1
END
Show_Slot_Info:
GET 127, value
DEBUG CR, "Pgm Slot: ", DEC value.NIB0,
CR, "R/W Slot: ", DEC value.NIB1,
CR, CR
FOR idx = 0 TO 4
READ idx, value
DEBUG "Location: ", DEC idx, TAB,
"Value: ", DEC3 value, CR
NEXT
RETURN
</pre><pre class="BScode" xml:space="preserve">' STORE1.BSP
' {$STAMP BS2p}
' {$PBASIC 2.5}
idx VAR Word ' index
value VAR Byte
LocalData DATA @0, 6, 7, 8, 9, 10
Main:
GOSUB Show_Slot_Info ' show slot info/data
PAUSE 2000
STORE 0 ' point READ/WRITE to Slot 0
GOSUB Show_Slot_Info
PAUSE 2000
RUN 2 ' run program in Slot 2
END
Show_Slot_Info:
GET 127, value
DEBUG CR, "Pgm Slot: ", DEC value.NIB0,
CR, "R/W Slot: ", DEC value.NIB1,
CR, CR
FOR idx = 0 TO 4
READ idx, value
DEBUG "Location: ", DEC idx, TAB,
"Value: ", DEC3 value, CR
NEXT
RETURN
</pre><pre class="BScode" xml:space="preserve">' STORE2.BSP
' {$STAMP BS2p}
' {$PBASIC 2.5}
idx VAR Word ' index
value VAR Byte
LocalData DATA @0, 11, 12, 13, 14, 15
Main:
GOSUB Show_Slot_Info ' show slot info/data
PAUSE 2000
STORE 0 ' point READ/WRITE to Slot 0
GOSUB Show_Slot_Info
END
Show_Slot_Info:
GET 127, value
DEBUG CR, "Pgm Slot: ", DEC value.NIB0,
CR, "R/W Slot: ", DEC value.NIB1,
CR, CR
FOR idx = 0 TO 4
READ idx, value
DEBUG "Location: ", DEC idx, TAB,
"Value: ", DEC3 value, CR
NEXT
RETURN
</pre>
<p class="PlainText">&#160;</p>
<p class="PlainText">The next program, STOREALL.BSP, is not related to the previous three programs. STOREALL.BSP demonstrates the use of the <span class="keyword_in_text">STORE</span> command to treat contiguous program slots as one block of memory (14 kBytes for the BS2p and BS2px, 30 kBytes for the BS2pe). This illustrates one of the most powerful uses of the <span class="keyword_in_text">STORE</span> command.</p>
<p>NOTE: This is written for the BS2p and will also run on the BS2pe and BS2px. Modify the $STAMP directive (as required) before downloading to the BS2pe or BS2px.</p><pre class="BScode" xml:space="preserve">' STOREALL.BSP
' This program demonstrates the STORE command and how it can be used to
' "flatten" the EEPROM space for applications requiring a lot of storage.
' This program writes to EEPROM locations within program slots 1 through 7
' on the BS2p and BS2px, and 1 through 15 on the BS2pe, thus, has access
' to 14- or 30-kBytes of space.
' {$STAMP BS2p}
' {$PBASIC 2.5}
#SELECT $STAMP
#CASE BS2, BS2E, BS2SX
#ERROR "This program requires BS2p, BS2pe, or BS2px"
#CASE BS2P, BS2PX
HiSlot CON 7
#CASE BS2PE
HiSlot CON 15
#ENDSELECT
LoSlot CON 1 ' first slot for "flat" EE
MemSize CON HiSlot - LoSlot + 1 * 2048
eeAddr VAR Word ' address pointer
value VAR Word ' cell value
slot VAR Byte ' current R/W slot
Main:
DEBUG "Flat Memory", CR,
"---------------------", CR,
"First Slot..... ", DEC LoSlot, CR,
"Last Slot...... ", DEC HiSlot, CR,
"Flat EE Size... ", DEC MemSize, CR, CR
PAUSE 2000
DEBUG "Writing to flat Memory...", CR
PAUSE 1000
FOR eeAddr = 0 TO (MemSize - 1) STEP 128 ' step through "flat" EE
value = eeAddr * 2 ' generate value
GOSUB Write_Word ' write it
GET 127, slot ' get R/W slot
DEBUG "--&gt; Location: ", DEC5 eeAddr, " ", ' show "flat" address
"Value: ", DEC5 value, " ", ' show value
"(", DEC slot.NIB1, ")", CR ' show slot
NEXT
DEBUG CR
DEBUG "Reading from flat Memory...", CR
PAUSE 1000
FOR eeAddr = 0 TO (MemSize - 1) STEP 128
GOSUB Read_Word ' read value from EE
GET 127, slot ' get W/R slot
DEBUG "&lt;-- Location: ", DEC5 eeAddr, " ",
"Value: ", DEC5 value, " ",
"(", DEC slot.NIB1, ") "
IF (value &lt;&gt; (2 * eeAddr)) THEN ' verify location
DEBUG "- Error"
ENDIF
DEBUG CR
NEXT
END
Write_Word:
STORE (eeAddr &gt;&gt; 11) + LoSlot ' set slot
WRITE eeAddr, Word value ' write value
RETURN
Read_Word:
STORE (eeAddr &gt;&gt; 11) + LoSlot ' set slot
READ eeAddr, Word value ' read value
RETURN
</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 ©&#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>