Device = 16F876
XTAL 20
ALL_DIGITAL = True
Declare SCL_PIN PORTB.0
Declare SDA_PIN PORTB.1
Dim TX As PORTB.2
Dim DATA_OUT As Byte
Dim DATA_IN(20) As Byte
Dim Address As Word ' 16-bit address required
For Address = 1 To 20
DATA_OUT = Address
BStart ' Send the start command on I2C
BusOut %10100010,Address,[DATA_OUT] ' Send the byte to the EEPROM
BStop ' Send the stop command on I2C
DelayMS 5 ' Allow time for allocation of byte
Next Address
For Address = 1 To 20
BStart ' Send the start command on I2C
BusOut %10100010,[Address] ' Send the address to read
Brestart ' Send a restart command on I2C
BusIn %10100011, [DATA_IN[Address]] ' Grab data at the above address
BStop ' Send the stop command on I2C
Next Address
Stop