UFAnders
Joined: 13 Apr 2005 Posts: 36 Location: Michigan
|
Microchip 24AA512 512k I2C EEPROM driver |
Posted: Sat Jun 25, 2005 9:53 am |
|
|
This is a nice little header file to drive Microchip's 24xxyyy series of I2C EEPROMS. It works for me, but if there are any problems please let me know and I'll correct whatever is messed up.
Code: | #define baseAddress24AA512 0xA0
void writeByte24AA512(int8 deviceAddress, int16 memAddress, int8 data);
int8 readByte24AA512(int8 deviceAddress, int16 memAddress);
void writeByte24AA512(int8 deviceAddress, int16 memAddress, int8 data)
{
i2c_start();
i2c_write(baseAddress24AA512 + (deviceAddress<<1));
i2c_write(memAddress>>8);
i2c_write(memAddress);
i2c_write(data);
i2c_stop();
delay_ms(5);
}
int8 readByte24AA512(int8 deviceAddress, int16 memAddress)
{
int8 returnByte=0;
i2c_start();
i2c_write(baseAddress24AA512 + (deviceAddress<<1));
i2c_write(memAddress>>8);
i2c_write(memAddress);
i2c_start();
i2c_write((baseAddress24AA512 + (deviceAddress<<1))|1);
returnByte = i2c_read(0);
i2c_stop();
return returnByte;
} |
|
|