| ??? 06/12/08 16:57 Modified: 06/12/08 17:14 Read: times |
#155761 - Not just floats, save structures too Responding to: ???'s previous message |
This is code for Keil C. Good to save a structure that you define.
Givens : The structure is called Settings The structure is declared bp is a pointer to a byte NVRwrite is a function to write a byte to the eeprom first param is address, second is the byte to write
// save the settings to EEPROM
void Settings_Put()
{
byte cnt,
*bp;
uint addr=0; // where to save the structure
// point to the settings variable
bp = (byte *)&Settings;
// write the settings
for (cnt = 0; cnt < sizeof(Settings); cnt++)
{
NVRwrite(addr++, *bp++);
}
}
For all you know, Settings could just be a float. For an array, you need to use the strlen function to find the length of the string to save. Again - This code is for Keil C |
| Topic | Author | Date |
| EEPROM ... floating & string read - write | 01/01/70 00:00 | |
| byte by byte... | 01/01/70 00:00 | |
| you know as much as the EEPROM does! | 01/01/70 00:00 | |
| Strings & Things | 01/01/70 00:00 | |
| Not just floats, save structures too | 01/01/70 00:00 | |
| I do it too :) | 01/01/70 00:00 | |
| Array | 01/01/70 00:00 | |
| and, in that case ... | 01/01/70 00:00 | |
| details ... | 01/01/70 00:00 | |
what does it mean "not succeeded"? | 01/01/70 00:00 | |
| float is possible but not STRINGS ... | 01/01/70 00:00 | |
| No magic involved | 01/01/70 00:00 | |
| and where's the terminating null char written? | 01/01/70 00:00 | |
| which EEPROM | 01/01/70 00:00 | |
| No, you don't | 01/01/70 00:00 | |
| does NVRwrite matches your EEPROM | 01/01/70 00:00 |



