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

how to get a varible from external - eeprom

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



Joined: 17 Feb 2004
Posts: 23

View user's profile Send private message

how to get a varible from external - eeprom
PostPosted: Wed Mar 17, 2004 3:05 am     Reply with quote

Hi,


BYTE string1[] = "hello world";

printf("%s", string1);

This is valid if i use the internal eeprom (18F452).

What if i want to store the string to i2c external eeprom (24LC256)?
do I have to supply every BYTE with a eeprom address?

It will be tedious if i have to specify address for each byte in the string.
When i want to retrieve the string, do i have to repeat the same thing?
Humberto



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

View user's profile Send private message

PostPosted: Wed Mar 17, 2004 5:57 am     Reply with quote

Hi janet,

PCM programmer posted a complete test code that answer your question:

[url]
http://www.ccsinfo.com/forum/viewtopic.php?t=17787&highlight=
[/url]

regards,

Humberto
janet_smith2000
Guest







PostPosted: Wed Mar 17, 2004 7:33 am     Reply with quote

actually i can read and write the external eeprom Smile

the problem i face is that

I CANNT get a value by specifying the varible name. instead, i have to supply memory address for that.

for example, i cannt read a value by simply writing
printf("%u", variable_name");
instead, i have to KNOW the address of the content in ADVANCE!.

What is the conventional way of retrieving data from eeprom?
SteveS



Joined: 27 Oct 2003
Posts: 126

View user's profile Send private message

eeprom access
PostPosted: Wed Mar 17, 2004 8:02 am     Reply with quote

EEPROM is handy, but not easily accessed in that it does not appear as straight memory. I don't think there is a 'convential' way to read from EEPROM; you need to come up with some trick that will work for you and make your code read and work cleanly.

Fo example if you have a bunch of constant strings in internal EEPROM you could access them via a function call:

Code:
void GetEEString(char * ramstr, int8 EEstart, int8 EElen)
{
    while( EElen-- > 0 )
        *ramstr++ = read_eeprom(EEStart++);
}


I haven't tested that , but you should get the general idea.

This would copy a particular string in EEPROM into 'ramstr'. And yes, you will need to know the start location and length of each string beforehand. I would define constants for each. If you had a variety of variables you could define a structure and have routines that save and retrieve the structure.

Basically you need to write something to encapsulate the EEPROM access. A 'go between' to make the EEPROM look more like a normal memory. Think of the EEPROM as disk drive - you need to provide the driver and file struture to access it.


- SteveS
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