118 lines
5.4 KiB
HTML
118 lines
5.4 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>I2CIN / I2COUT Example</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>I2CIN / I2COUT Example</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/I2CIN.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">I2CIN</a>, <a href="../Commands/I2COUT.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">I2COUT</a></p>
|
|||
|
<p> </p>
|
|||
|
</div>
|
|||
|
<p class="clear"> </p>
|
|||
|
<p> </p>
|
|||
|
<p class="PlainText" style="text-align: center;">
|
|||
|
<img src="../../graphics/24lc16_sch.gif" />
|
|||
|
</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">' I2C.BSP
|
|||
|
' This program demonstrates writing and reading every location in a 24LC16B
|
|||
|
' EEPROM using the BS2p/BS2pe.BS2px's I2C commands. Connect the BS2p, BS2pe,
|
|||
|
' or BS2px to the 24LC16B DIP EEPROM as shown in the diagram in the I2CIN
|
|||
|
' or I2COUT command description.
|
|||
|
|
|||
|
' {$STAMP BS2p}
|
|||
|
' {$PBASIC 2.5}
|
|||
|
|
|||
|
#IF ($STAMP < BS2P) #THEN
|
|||
|
#ERROR "Program requires BS2p, BS2pe, or BS2px."
|
|||
|
#ENDIF
|
|||
|
|
|||
|
SDA PIN 0 ' I2C SDA pin
|
|||
|
SCL PIN SDA + 1
|
|||
|
|
|||
|
addr VAR Word ' internal address
|
|||
|
block VAR Nib ' block address in 24LC16
|
|||
|
value VAR Byte ' value to write
|
|||
|
check VAR Nib ' for checking retuned values
|
|||
|
result VAR Byte(16) ' array for returned value
|
|||
|
|
|||
|
|
|||
|
Write_To_EEPROM:
|
|||
|
DEBUG "Writing...", CR
|
|||
|
PAUSE 2000
|
|||
|
FOR addr = 0 TO 2047 STEP 16 ' loop through all addresses
|
|||
|
block = addr.NIB2 << 1 ' calculate block address
|
|||
|
value = addr >> 4 ' create value from upper 8 bits
|
|||
|
' write 16 bytes
|
|||
|
I2COUT SDA, $A0 | block, addr, [REP value\16]
|
|||
|
PAUSE 5
|
|||
|
DEBUG "Addr: ", DEC4 addr, "-", DEC4 addr + 15, " ",
|
|||
|
"Value: ", DEC3 value, CR
|
|||
|
NEXT
|
|||
|
PAUSE 2000
|
|||
|
|
|||
|
Read_From_EEPROM:
|
|||
|
DEBUG CR, "Reading...", CR
|
|||
|
PAUSE 2000
|
|||
|
FOR addr = 0 TO 2047 STEP 16
|
|||
|
block = addr.NIB2 << 1
|
|||
|
value = addr >> 4
|
|||
|
I2CIN SDA, $A1 | block, addr, [STR result\16]
|
|||
|
FOR check = 0 TO 15
|
|||
|
IF (result(check) <> value) THEN Error
|
|||
|
NEXT
|
|||
|
DEBUG "Addr: ", DEC4 addr, "-", DEC4 addr + 15, " ",
|
|||
|
"Value: ", DEC3 result, CR
|
|||
|
NEXT
|
|||
|
PAUSE 100
|
|||
|
DEBUG CR, "All locations passed"
|
|||
|
END
|
|||
|
|
|||
|
|
|||
|
Error:
|
|||
|
DEBUG "Error at location: ", DEC4 addr + check, CR,
|
|||
|
"Found: ", DEC3 result(check), ", Expected: ", DEC3 value
|
|||
|
END
|
|||
|
</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 © <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>
|