Be sure you have the WP (pin #7) tied to ground, and pull-up
resistors on SDA & SCL (pins #4 & #5)
A0, A1 and A2 are not used on the 24LC16B, so you can leave
these pins (#1,#2,#3) floating.
The control byte consists of a 4-bit control code of %1010 which
remains constant.
The next 3-bits in the control byte are the "block select bits".
These can be from %000 to %111 for blocks 0 to 7 (8 blocks total).
Note that these 3-bits are the high-order "address" bits, so you do
not follow the control byte with a word sized variable for the address
of this EEPROM. The upper 3-bits of the word address are the lower
nibble bits 1,2,3 in the control byte.
The last bit of the control byte is for read or write, but PBP will
automatically flip this bit for you.
So, the control byte can be from %1010 000 0 to %1010 111 0 to
access blocks 0 to 8. The low-order address byte can be from 0-255.
Code:B0 var byte B1 var byte B2 var byte Cont con %10100110 ' Control 1010 + block #3 address 011 SYMBOL SDA = PORTB.4 ' Data pin SYMBOL SCL = PORTB.5 ' Clock pin Main: FOR B0=0 to 63 ' Locations 0 to 63 = 64 bytes B1=B0+4 ' Write address + 4 to each location I2cWrite SDA,SCL,Cont,B0,[B1] ' Cont + B0 = word address PAUSE 10 ' Pause for writes NEXT B0 FOR B0=0 to 63 ' Locations 0 to 63 = 64 bytes I2cRead SDA,SCL,Cont,B0,[B2] ' Cont + B0 = word address WRITE B0,B2 NEXT B0 Display: FOR B0 = 0 to 63 READ B0,B2 HSEROUT ["ADD: ",DEC B0," VAL: ",DEC B2,13,10] NEXT B0 Here: GOTO Here




Bookmarks