View previous topic :: View next topic |
Author |
Message |
[mAnNaRo]
Joined: 02 Dec 2005 Posts: 28 Location: Italy, Milan
|
A simple C question.... |
Posted: Thu Feb 09, 2006 3:53 am |
|
|
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
|
The Solution-Code |
Posted: Thu Feb 09, 2006 4:28 am |
|
|
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
|
Re: The Solution-Code |
Posted: Thu Feb 09, 2006 10:57 am |
|
|
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
|
|
|
|
|