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

storing strings in eeprom

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



Joined: 19 Feb 2005
Posts: 11
Location: new york usa

View user's profile Send private message

storing strings in eeprom
PostPosted: Thu Mar 08, 2007 7:30 pm     Reply with quote

I have a barcode reader application that gets ascii data , up to 20 characters
that are all numeric, "0012345678905" for example. I need to store these codes in internal eeprom memory, 18f452. The only way i know is to split the barcode into two strings, then convert to long integers,
x=atoi32(string1);
y=atoi32(string2);
//then save

WRITE_LongEEPROM(20,string1);

WRITE_LongEEPROM(30,string2);

To retrieve the data I need to convert each part back
and reassamble them into the origional string.
One of the problems is that the atoi32 function strips the leading zeros.

any help would be greatly appreciated.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Mar 08, 2007 10:12 pm     Reply with quote

You could save it as packed BCD (two digits per byte), and also save a
byte the tells how many digits are in the number.

How many of these 20-digit numbers do you need to save ?
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Thu Mar 08, 2007 10:16 pm     Reply with quote

Depending on the amount of data that you need to store and the size of eeprom you could simply store the original ascii data to the eeprom. The number 0(zero) would be stored as 0x30, 9 would be 0x39 and so forth. This way you could take what you get from the serial port and go right to the eeprom without any need for conversions.

Ronald
tkidder



Joined: 19 Feb 2005
Posts: 11
Location: new york usa

View user's profile Send private message

storing strins in eeprom
PostPosted: Fri Mar 09, 2007 7:10 am     Reply with quote

I am using, get_string(barcode); to get the data from the scanner.
into char code[20];
are there any examples of how to store this string in eeprom? I assume i would need to store each character in consecutive byte locations.Would i need to convert to hex? I would then need to retrieve the bytes and assemble into a string. There should be no problem with storage since only one code is being saved.
Sorry for my ignorance on this subject.
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Fri Mar 09, 2007 10:17 am     Reply with quote

Code:
store_data()
{
int i;
  for(i = 0; i < 19; i++)
  {
    write_eeprom(i, code[i]);
  }
}

read_data()
{
int i;
  for(i = 0; i < 19; i++)
  {
    read_code[i] = read_eeprom(i);
  }
  read_code[19] = 0;// null terminator
}


This should take your data and store it to and read from the onboard eeprom. It is already in HEX so you don't need to do any converting to it.

Ronald

EDIT: I just realized that your variable code[] only has 20 places defined. The code used the 21st place to store the null character. The code has been edited.
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