Store text in eeprom
-
- Posts: 11
- Joined: Thu Sep 16, 2010 12:00 am
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Store text in eeprom
Hello,
You would need to create a macro to read a string from the EEPROM and a macro to write strings to the EEPROM.
Strings are terminated with a 0 so you would have to step through the string writing bytes to the EEPROM until you reach the 0 at the end. If you also save the 0 at the end then your read back macro can count 0's to get to the right string in the EEPROM and then starting reading back the bytes into a string variable until the next 0 in the EEPROM is found.
You would need to create a macro to read a string from the EEPROM and a macro to write strings to the EEPROM.
Strings are terminated with a 0 so you would have to step through the string writing bytes to the EEPROM until you reach the 0 at the end. If you also save the 0 at the end then your read back macro can count 0's to get to the right string in the EEPROM and then starting reading back the bytes into a string variable until the next 0 in the EEPROM is found.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 11
- Joined: Thu Sep 16, 2010 12:00 am
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Store text in eeprom
Hello,
This example writes 3 strings to the EEPROM at the start of the program. You must write the strings into EEPROM at the beginning of the program using increasing index numbers starting from 0. You will not be able to edit the strings during operation unless they remain a fixed length otherwise you will either start overwriting other strings or cause corruption in the index search routine. You can disable the EEPROM being wiped during reprogramming if you are using the EB006 by clicking Chip -> Configure -> Options.
You can store as many strings you like using this method up to the limits of the EEPROM in your device. At the moment you loose a byte of EEPROM memory for every string to store the terminating 0. Another method would be to create an array of byte variables where each element contains the length of a string in EEPROM. This would allow the terminating 0's to be removed from the EEPROM at the expense of more RAM usage.
This example writes 3 strings to the EEPROM at the start of the program. You must write the strings into EEPROM at the beginning of the program using increasing index numbers starting from 0. You will not be able to edit the strings during operation unless they remain a fixed length otherwise you will either start overwriting other strings or cause corruption in the index search routine. You can disable the EEPROM being wiped during reprogramming if you are using the EB006 by clicking Chip -> Configure -> Options.
You can store as many strings you like using this method up to the limits of the EEPROM in your device. At the moment you loose a byte of EEPROM memory for every string to store the terminating 0. Another method would be to create an array of byte variables where each element contains the length of a string in EEPROM. This would allow the terminating 0's to be removed from the EEPROM at the expense of more RAM usage.
- Attachments
-
- EEPROM - strings.fcf
- (10.5 KiB) Downloaded 970 times
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel