© Parallax, Inc. • 24LC128 (#602-00013) • 08/2005 v2.0 Page 3 of 5
Communication Protocol
The 24LC128 communicates over the I²C bus with various types of transactions, such as Byte Write,
Page Write, Random Read and Sequential Read.
All communication with the 24LC128 requires a control byte to be sent. This control byte includes a Start
Bit, the Control Code (4 bits), the Chip Select (3 bits) and the R/W bit.
The address lines (A0, A1, A2) are used to select multiple 24LC128 devices on the same bus. Up to 8
24LC128 devices can be connected to the same bus.
Please see the manufacturer datasheet from Microchip for more information on reading/writing data to
the 24LC128.
Source Code
BASIC Stamp
®
2, 2e, 2sx Program
This program will allow you to use the 24LC128 with the BASIC Stamp 2, 2e and 2sx.
' =========================================================================
' File....... 24LC128.bs2
' Purpose.... Interface To A 24LC128 16KB EEPROM
' Author..... Parallax, Inc.
' E-mail..... support@parallax.com
' Updated.... 08-09-2005
' {$STAMP BS2}
' {$PBASIC 2.5}
' -----[ Program Description ]---------------------------------------------
' This code will interface the BS2, BS2e and BS2sx to a 24LC128 16KB EEPROM
' -----[ I/O Definitions ]-------------------------------------------------
SDA PIN 0 ' I2C Serial Data Line
SCL PIN 1 ' I2C Serial Clock Line
' -----[ Constants ]-------------------------------------------------------
Address CON $A0 ' Address Of 24LC128
Ack CON 0 ' Acknowledge Bit
' -----[ Variables ]-------------------------------------------------------
temp VAR Byte ' Variable Used For Work
i2cWork VAR Word ' Work Byte For I2C I/O
i2cAck VAR Bit ' Ack Bit From Device
eeprom_add VAR Word ' EEPROM Address
' -----[ Main Routine ]----------------------------------------------------
DO
DEBUG "Enter value to store from 0 to 255: "