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 CCS Technical Support

Help please!! Programing EEPROM with PIC18F452

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



Joined: 31 Mar 2004
Posts: 23
Location: Switzerland

View user's profile Send private message

Help please!! Programing EEPROM with PIC18F452
PostPosted: Wed Mar 31, 2004 7:04 am     Reply with quote

hello
I'm beginner with PICs. I want to write and read to an EEPROM memory (24LC256) via I2C Bus.
I'm looking for a code example.
My HW:

PICDEM 2 Plus
MPLAB ICD 2
CCS Compiler (PCH and PCM)
PIC 18F452

Thanks, Pablo[/b]
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Wed Mar 31, 2004 1:04 pm     Reply with quote

First, make sure you read through the data sheet for the eeprom. It will tell you just how you are supposed to write to and read from the eeprom. I've used that same combination so here is a small bit of code that might be helpful.

//write sequence
void eewrite(int16 address, int8 value)
{
unsigned int8 add;

output_low(wp);// write enable the eeprom
delay_us(15);
i2c_start();// send start signal
i2c_write(0xA0);// address the eeprom
add = (address >> 8) & 0xFF;
i2c_write(add);// send the MSB of the memory location
add = address & 0xFF;
i2c_write(add);// send the LSB of the memory location
i2c_write(value);// write the data
i2c_stop();// stop i2c communications
output_high(wp);// write disable the eeprom

}// end of eewrite()

// read sequence
int8 eeread(int16 address)
{
unsigned int8 add;
unsigned int8 clipboard;

i2c_start();
i2c_write(0xA0);// address the eeprom(write mode)
add = (address >> 8) & 0xFF;
i2c_write(add);// send the MSB of the memory location you want to read
add = address & 0xFF;
i2c_write(add);// send the LSB of the memory location you want to read
i2c_start();
i2c_write(0xA1);// address the eeprom(read mode)
clipboard = i2c_read(0);// read data from the eeprom
i2c_stop();

return(clipboard);
}// end of eeread()

If you want to write more than just one byte to the eeprom, you can have succesive i2c_write's, before the i2c_stop, and the eeprom will automatically increment it's address to store the data. The same goes for reads, also.

Hope this helps.

Ronald
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