|
|
View previous topic :: View next topic |
Author |
Message |
ljbeng
Joined: 10 Feb 2004 Posts: 205
|
If interested.... Code for Multiple 24LC256 |
Posted: Mon May 03, 2004 9:29 am |
|
|
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
|
|
Posted: Mon May 03, 2004 9:37 am |
|
|
Hi ljbeng,
Good
Thanks for upload & share !!!
Humberto |
|
|
Gabriel Caffese
Joined: 09 Oct 2003 Posts: 39 Location: LA PLATA, ARGENTINA
|
Thanks for sharing, but... |
Posted: Mon May 03, 2004 10:17 am |
|
|
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
|
|
Posted: Mon May 03, 2004 10:31 am |
|
|
Your right, bad math on my part. I thought that sounded low. |
|
|
|
|
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
|