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

A simple C question....

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



Joined: 02 Dec 2005
Posts: 28
Location: Italy, Milan

View user's profile Send private message Send e-mail

A simple C question....
PostPosted: Thu Feb 09, 2006 3:53 am     Reply with quote

Code:

//--------------------------------------------------------------------------//
// Clear external EEPROM memory
//--------------------------------------------------------------------------//
void clear_MEMORY(void) {
   int32 mem_address;
   for (mem_address = 0; mem_address <= 0xFFFF; mem_address++) {
      write_ext_eeprom(mem_address, 0x00);
   }
}


How can I save RAM memory using an int16 for mem_address counter instead of int32? With int16 the compiler tell me that the condition is always TRUE (that's true). When I increment an int16 variable 0xFFFF I get a rollover to zero?

Thanx
Alex
Roebi



Joined: 12 Jan 2006
Posts: 6

View user's profile Send private message

The Solution-Code
PostPosted: Thu Feb 09, 2006 4:28 am     Reply with quote

What about this:
Code:
void clear_MEMORY(void) {
   int16 mem_address = 0;
   do {
     write_ext_eeprom(mem_address, 0);
     mem_address++;
   } while (mem_address);
} // clear_MEMORY

Best regards
Roebi
jds-pic



Joined: 17 Sep 2003
Posts: 205

View user's profile Send private message

Re: The Solution-Code
PostPosted: Thu Feb 09, 2006 10:57 am     Reply with quote

Roebi wrote:
What about this:
Code:
void clear_MEMORY(void) {
   int16 mem_address = 0;
   do {
     write_ext_eeprom(mem_address, 0);
     mem_address++;
   } while (mem_address);
} // clear_MEMORY



since you are doing bytewise writing to the eeprom, you can save yourself a lot of time clearing the memory by doing a read first, and only writing a zero if the read value is nonzero. for even a small eeprom this will probably cut lots of "long" 10ms writes out of the picture.

Code:
void clear_MEMORY(void) {
   int16 mem_address = 0;
   do {
     if !(read_ext_eeprom(mem_address)) {
       write_ext_eeprom(mem_address, 0);
       mem_address++;
      }
   } while (mem_address);
} // clear_MEMORY
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