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 support@ccsinfo.com

Flash Storage

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



Joined: 10 Apr 2008
Posts: 109
Location: Cape Town, South Africa

View user's profile Send private message

Flash Storage
PostPosted: Thu Aug 28, 2008 5:29 am     Reply with quote

Hi i was wondering how i can store adc values and then printf when the memory is full is that possible. Need to store values from an accelerometer. Values need to be stored as floats. Stored in the flash mem.

Im using a 16f877a which has a flash mem of 368 bytes so that probably equates to 5 samples per channel.

Is it better to create an array to store the values in or how do i go about doing this ?

Regards
_________________
"THE ONLY EASY DAY WAS YESTERDAY"
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Thu Aug 28, 2008 7:22 am     Reply with quote

16F877A has 256 Byte of EEPROM, actually. EEPROM is written in Byte entities, so you have to store your float data bytewise, e. g. from a union or by a type cast. Having a function that stores a single float to choosen EEPROM address would be the most simple solution to my opinion, e. g.:

Code:
void WriteFloatEeprom(int8 bAddress, float fData)
{
  int8 i;
  for(i = 0; i < 4; ++i) write_eeprom(bAddress + i, *(&fData + i));
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Aug 28, 2008 10:57 am     Reply with quote

Quote:
write_eeprom(bAddress + i, *(&fData + i));

This won't work, because the address of the float will increment by 4
bytes when you add 1 to it. You need to cast the float pointer into a byte
pointer before you add a byte index ('i') to it. See the sample code in this FAQ article:
http://www.ccsinfo.com/faq.php?page=write_eeprom_not_byte
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