CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

If interested.... Code for Multiple 24LC256

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ljbeng



Joined: 10 Feb 2004
Posts: 205

View user's profile Send private message

If interested.... Code for Multiple 24LC256
PostPosted: Mon May 03, 2004 9:29 am     Reply with quote

I have a box that uses 8 24LC256 external eeproms. I modified 24256.c to allow for addressing all 8 chips. My board has the address line (A0,A1,A2) of the eeproms tied to +5 or ground to create a different address for each chip. With this code you can put up to 8 eeproms on the same board and get 32K bytes x 8 chips = 256K bytes of memory.

Code:
///////////////////////////////////////////////////////////////////////////
////   Library for Multiple 24LC256 serial EEPROMs                     ////
////                                                                   ////
////   init_ext_eeprom();    Call before the other functions are used  ////
////                                                                   ////
////   write_ext_eeprom(c, a, d);  Write the byte d to the address a   ////
////                               using chip c                        ////
////                                                                   ////
////   d = read_ext_eeprom(c, a);   Read the byte d from the address a ////
////                                using chip c                       ////
////                                                                   ////
////   c = chip address: Pins a0, a1, a2 of chip define address for    ////
////                     each 24256 chip up to 8 chips can be addressed////
////                                                                   ////
////   Change the pin assignments inside the #use i2c statement        ////
////                                                                   ////
///////////////////////////////////////////////////////////////////////////


#use i2c(master, sda=PIN_C4, scl=PIN_C3)

#define EEPROM_ADDRESS long int
#define EEPROM_SIZE   32768

void init_ext_eeprom()
{
   output_float(PIN_C3);
   output_float(PIN_C4);

}


void write_ext_eeprom(BYTE chadd,long int address, BYTE data)
{
   short int status;
   chadd = (chadd<<1) + 0xa0;
   i2c_start();
   i2c_write(chadd);
   i2c_write(address>>8);
   i2c_write(address);
   i2c_write(data);
   i2c_stop();
   i2c_start();
   status=i2c_write(chadd);
   while(status==1)
   {
   i2c_start();
   status=i2c_write(chadd);
   }
}


BYTE read_ext_eeprom(BYTE chadd,long int address) {
   BYTE data;
   chadd = (chadd<<1) + 0xa0;
   i2c_start();
   i2c_write(chadd);
   i2c_write(address>>8);
   i2c_write(address);
   i2c_start();
   chadd = chadd | 1;
   i2c_write(chadd);
   data=i2c_read(0);
   i2c_stop();
   return(data);
}


Last edited by ljbeng on Mon May 03, 2004 10:32 am; edited 1 time in total
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Mon May 03, 2004 9:37 am     Reply with quote

Hi ljbeng,

Good Idea

Thanks for upload & share !!! Very Happy

Humberto
Gabriel Caffese



Joined: 09 Oct 2003
Posts: 39
Location: LA PLATA, ARGENTINA

View user's profile Send private message Visit poster's website MSN Messenger

Thanks for sharing, but...
PostPosted: Mon May 03, 2004 10:17 am     Reply with quote

Ljbeng,

Thanks for sharing your code, but take care that 24256 eeproms are 32kbyte size, so 8*32kb = 256kbytes !!
ljbeng



Joined: 10 Feb 2004
Posts: 205

View user's profile Send private message

PostPosted: Mon May 03, 2004 10:31 am     Reply with quote

Your right, bad math on my part. I thought that sounded low.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group