BASIC stamp manual v2.2

I2COUT – BASIC Stamp Command Reference
Page 230 BASIC Stamp Syntax and Reference Manual 2.2 www.parallax.com
' 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