Hi,
I have a need to save/recall signed integers in EEPROM. Numbers are small, say between -50 and +50. The standard way to write to EEPROM is byte-based, and I add a number to each value at write, and subtract at read, to make sure they are always positive. But it is awkward and error-prone.
Is there an other more straightforward way to save/recall signed integers in EEPROM?
Edit: FC7, PIC16F886
Jan Didden
Linear Audio
Saving signed integers in EEPROM?
Moderator: Benj
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
-
- Flowcode v5 User
- Posts: 273
- Joined: Thu Apr 17, 2008 9:59 am
- Has thanked: 19 times
- Been thanked: 16 times
- Contact:
Re: Saving signed integers in EEPROM?
Hi Martin, yes that surely does help, thanks. Looking at it again though, the EEPROM macro in FC7 seems to expect an INT for both the EEPROM address and the argument. Does that mean that it basically reads/writes 2-byte chunks (words) at the time, rather than bytes?
The component properties says the bit depth is 8 bit, and I can not change that afaics. So now I am confused. Do I use bytes to preset the values, and INT to read/write?
Jan
The component properties says the bit depth is 8 bit, and I can not change that afaics. So now I am confused. Do I use bytes to preset the values, and INT to read/write?
Jan
- 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: Saving signed integers in EEPROM?
Hi Jan,
No each write for an 8-bit device will only write the lower 8-bits of the value at the selected address. The value is a 16-bit variable to allow 16-bit writes on 16-bit devices.
No each write for an 8-bit device will only write the lower 8-bits of the value at the selected address. The value is a 16-bit variable to allow 16-bit writes on 16-bit devices.
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
-
- Flowcode v5 User
- Posts: 273
- Joined: Thu Apr 17, 2008 9:59 am
- Has thanked: 19 times
- Been thanked: 16 times
- Contact:
Re: Saving signed integers in EEPROM?
Aha! So any INT higher than 255 I have to manipulate if I want to write it to EEPROM (on an 8 bit device). And although the macro asks for an INT address, it really can only address 256 locations then? Or does that not have that limitation?
That's OK though, that will work for me.
Jan
That's OK though, that will work for me.
Jan
- 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: Saving signed integers in EEPROM?
Hi Jan,
It's just the data that has the 8-bit limitation on an 8-bit device. The address can be 16-bit as there are 8-bit devices with EEPROM addresses over 255.
It's just the data that has the 8-bit limitation on an 8-bit device. The address can be 16-bit as there are 8-bit devices with EEPROM addresses over 255.
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