2402.C  


I2C Library Sub-Routines for 24LC02

///////////////////////////////////////////////////////////////////////////
////								       ////
////   Library for a MicroChip 24LC02B configured for a x8 org         ////
////                                                                   ////
////   init_ext_eeprom();    Call before the other functions are used  ////
////                                                                   ////
////   write_ext_eeprom(a, d);  Write the byte d to the address a      ////
////                                                                   ////
////   d = read_ext_eeprom(a);   Read the byte d from the address a    ////
////                                                                   ////
////   The main program may define eeprom_sda                          ////
////   and eeprom_scl to override the defaults below.                  ////
////                                                                   ////
////								       ////
////        (C) Copyright 1996,1997 Custom Computer Services           ////
////        					                       ////
///////////////////////////////////////////////////////////////////////////

#ifndef EEPROM_SDA

#define EEPROM_SDA  PIN_B7
#define EEPROM_SCL  PIN_B6

#endif

#use i2c(master,sda=EEPROM_SDA, scl=EEPROM_SCL)

#define EEPROM_ADDRESS byte
#define EEPROM_SIZE    256

void init_ext_eeprom() {
   output_low(eeprom_scl);
   output_high(eeprom_sda);
}


void write_ext_eeprom(byte address, byte data) {

   i2c_start();
   i2c_write(0xa0);
   i2c_write(address);
   i2c_write(data);
   i2c_stop();
   delay_ms(11);
}


byte read_ext_eeprom(byte address) {
   byte data;

   i2c_start();
   i2c_write(0xa0);
   i2c_write(address);
   i2c_start();
   i2c_write(0xa1);
   data=i2c_read(0);
   i2c_stop();
   return(data);
}


Navigation Bar
tech_support@blitzlogic.com