'program i2c seeprom by transferring all 256 bytes of Picaxe eeprom in 16 byte blocks
'useful for putting text in seeprom
'seepromAddOffset controls start address of where block will be written into seeprom
'seepromAddOffset should be multiple of 256 ex: 0,256,512,768
'program will have to be run multple times with Picaxe eeprom data and seepromAddOffset changed to fill seeprom
'should work on 24x32 on up
'tested on a tinyrtc board with a ds1307 and a 24c32 seeprom
'used i2cslow so ds1307 wouldn't get confused
#picaxe 08M2
symbol eepromAdd = b4 'address for Picaxe eeprom
symbol loopCnt = b5
symbol loopCnt2 = b7
symbol inByte = b8
symbol seepromAdd = w10 'address for serial eeprom
symbol seepromAddOffset = w11 'offset where 1st byte of data will be wriiten into seeprom
setfreq m8
pause 1000
hi2csetup i2cmaster, %10100000, i2cslow_8, i2cword
seepromAddOffset = 0 'address 0 - 255 of seeprom
'seepromAddOffset = 256 'address 256 - 511 of seeprom
'seepromAddOffset = 512 'address 512 - 767 of seeprom
'seepromAddOffset = 768 'address 768 - 1023 of seeprom
'seepromAddOffset = 3840 'address 3840 - 4095 of seeprom / last 256 bytes of 24x32
'etc...
seepromAdd = seepromAddOffset
eepromAdd = 0
for loopCnt = 0 to 15
sertxd("Programming Address = ",#seepromAdd,13,10)
'read 16 bytes of data out of eeprom and store in ram stating at address 64
bptr = 64
read eepromAdd,@bptrinc, @bptrinc, @bptrinc, @bptrinc, @bptrinc, @bptrinc, @bptrinc, @bptrinc,@bptrinc, @bptrinc, @bptrinc, @bptrinc, @bptrinc, @bptrinc, @bptrinc, @bptr 'read 16 bytes from eeprom
'write the 16 bytes starting at ram address 64 into seeprom
bptr = 64
hi2cout seepromAdd,(@bptrinc, @bptrinc, @bptrinc, @bptrinc, @bptrinc, @bptrinc, @bptrinc, @bptrinc,@bptrinc, @bptrinc, @bptrinc, @bptrinc, @bptrinc, @bptrinc, @bptrinc, @bptr) 'write 16 bytes to seeprom
pause 10
eepromAdd = eepromAdd + 16 'point to start of next 16 bytes in eeprom for next read
seepromAdd = seepromAdd + 16 'point to start of next 16 bytes in seeprom for next write
next
'now read what we just programmed into the seeprom and print it
sertxd("dump",13,10)
seepromAdd = seepromAddOffset
for loopCnt = 0 to 15
sertxd(#seepromAdd," ") 'print the address
for loopCnt2 = 0 to 15
hi2cin seepromAdd,(inByte) 'read a byte from th seeprom
if inByte > 31 and inByte < 127 then 'only printable characters
sertxd(inByte)
else
sertxd("#") 'unprintable characters
endif
inc seepromAdd
next
sertxd(13,10) 'new line
next
end
'---------------------------------------------------
'256 bytes of eeprom data (address 0 - 255) in 16 byte blocks
eeprom 0,("123456789012345",0) 'max 16 bytes
eeprom 16,("test 1",0) 'max 16 bytes
eeprom 32,("Hello World",0) 'max 16 bytes
eeprom 48,("1234567890123456") 'max 16 bytes
eeprom 64,("123456789012345",0) 'max 16 bytes
eeprom 80,("123456789012345",0) 'max 16 bytes
eeprom 96,("123456789012345",0) 'max 16 bytes
eeprom 112,("123456789012345",0) 'max 16 bytes
eeprom 128,("123456789012345",0) 'max 16 bytes
eeprom 144,("123456789012345",0) 'max 16 bytes
eeprom 160,("123456789012345",0) 'max 16 bytes
eeprom 176,("123456789012345",0) 'max 16 bytes
eeprom 192,("123456789012345",0) 'max 16 bytes
eeprom 208,("123456789012345",0) 'max 16 bytes
eeprom 224,(0) 'max 16 bytes
eeprom 240,("123456789012345X") 'max 16 bytes