Page 1 of 1

Saving signed integers in EEPROM?

Posted: Wed Apr 17, 2019 8:21 am
by jadiflow
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

Re: Saving signed integers in EEPROM?

Posted: Wed Apr 17, 2019 8:34 am
by medelec35
Hi Jan,
This post might help?

Re: Saving signed integers in EEPROM?

Posted: Wed Apr 17, 2019 9:31 am
by jadiflow
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

Re: Saving signed integers in EEPROM?

Posted: Wed Apr 17, 2019 9:59 am
by Benj
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.

Re: Saving signed integers in EEPROM?

Posted: Wed Apr 17, 2019 10:24 am
by jadiflow
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

Re: Saving signed integers in EEPROM?

Posted: Wed Apr 17, 2019 11:47 am
by Benj
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.

Re: Saving signed integers in EEPROM?

Posted: Wed Apr 17, 2019 11:48 am
by jadiflow
Got it, thanks!

Jan