18F External EEPROM Example

24LC256 Microchip IC

    External EEPROMS are great for storing data, and to interface with them is not all that hard. Most use the I2C protocol. In this example the 24LC256 is used. I2C communication is great as it can allow serial data communication between many devices on a single 2 wire bus. These two lines are referred too as SDA and SCL. Basically SDA is the serial data and SCL maintains the clock/frequency in which data is transferred.

    Like most peripherals, I've made my own Swordfish Library for the 24LC series EEPROM's. Pins 1, 2, 3 set the address of the EEPROM. As you can see in the diagram below, the highest 24LC256 has one connection to earth (Pin 3), and two connections to 5V (Pins 1 & 2).. this defines it as %011 (don't forget that binary starts from the right!) on the I2C Bus.

Pin 4 on 24LC256 = Vss (Earth)
Pin 8 on
24LC256 = Vdd (5V)
Note the PIC's power supply/oscillator are not shown

Click here to see this circuit in action!

    Here is an example of how to use the Library with a single EEPROM (24LC256)

Device = 18F452
Clock = 20
// import libraries...
Include "ExtEEPROM.bas"
Include "usart.bas" 
Include "Convert.bas"
Dim 
    Variable As Byte,       // Variable used for data 
    Device_Address As Byte, // Register for I2C Address reference
    Memory_Address As Byte, // Register for EEPROM memory address
    Family As Byte          // Register for External EEPROM family setting
    
    USART.SetBaudrate(br19200) 
    
    Variable = 123          // Place the value "1" in the variable register
    Device_Address = %000   // Set the EEPROM I2C address
    Memory_Address = 10     // Set the EEPROM address location to 0
    Family = %1010          // Set the Family configeration as the binary number 1010
    // Write the value 123 to EEPROM 000 at memory location 10
    ExtEEPROM.Write(Variable, Memory_Address, Device_Address, Family)        
    // Read from EEPROM 000, memory location 10
    Variable = ExtEEPROM.Read(Memory_Address, Device_Address, Family)
    
    USART.Write(Convert.DecToStr(Variable))
    
    While True
    Wend

 

     Video Tutorials:

    Download Spency's External EEPROM Library

    Link: What is a Swordfish Library?

Where you can get the components;

 Skip Navigation Links.

Collapse Site Tutorial IndexSite Tutorial Index
Expand 16F PIC Examples16F PIC Examples
Collapse 18F PIC Examples18F PIC Examples
LED's
Switches
Expand 7 Segment Displays7 Segment Displays
LCD's
Expand 7 Segment Displays7 Segment Displays
ADC
ADC (Another Example)
EEPROM's
DS1307
Expand RS232 and UARTRS232 and UART
DS18B20
External ADC
Hall Effect Sensor
Pulse Width Modulation (PWM)
Infrared UART
Swordfish Modules
Expand Code SnippetsCode Snippets
Expand Handy TipsHandy Tips