Go Down

Topic: How can i write/read an integer to eeprom? (Read 1 time) previous topic - next topic

acmiilangr

int temp;

how can i write to eeprom the content of temp? what if it has more than 1 digit? for example "123"
does the code need to split to 1,2,3 and write to 3 adresses?

AWOL

123 is less than 255 which is the largest value you can store in a byte.
However "123" is a string and takes up four bytes.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

acmiilangr

#2
May 15, 2010, 08:56 pm Last Edit: May 15, 2010, 08:59 pm by acmilangr Reason: 1
yeah mistake i mean 123 not "123"

but what about 654?
and what is the syntax to do that?
do i need to split it and write 6,5,4 in 3 addresses? and how can i join them?(on reading)

AWOL

Code: [Select]
int x = 645;
byte hix = highByte (x);
byte lox = lowByte (x);
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

acmiilangr

#4
May 15, 2010, 09:04 pm Last Edit: May 15, 2010, 09:35 pm by acmilangr Reason: 1
Code: [Select]
int x = 645;
byte hix = highByte (x);
byte lox = lowByte (x);


thanks for that, a little explain? :-? what value will have the hix and what the lox on this example?


mmm is the split of 645 in 2 bytes?

searching on the internet i saw this
elocity = -200 = hex FF38 = [hex FF] [hex 38] = [255] [56]
Radius = 500 = hex 01F4 = [hex 01] [hex F4] = [1] [244]

so i think i undestand now..

and another question. do i need to check a demical if it is >than 256 to use high/low fuction before i save it to eeprom? and how do i know when i read from eeprom if the value have 1 or 2 addreesses? if i read always 2 adresses then if the number i saved was less than 256 i'll get wrong result


and how i merge them? ;)

AWOL

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

retrolefty

#6
May 15, 2010, 09:55 pm Last Edit: May 15, 2010, 09:59 pm by retrolefty Reason: 1
and another question. do i need to check a demical if it is >than 256 to use high/low fuction before i save it to eeprom?

Integers have no decimal point.

and how do i know when i read from eeprom if the value have 1 or 2 addresses?

eeproms only directly write or read to byte addresses, so you always have to write or read two bytes to save or retrieve a integer number no matter what it's value is.

if i read always 2 addresses then if the number i saved was less than 256 i'll get wrong result

No you will get correct results (even if <256) if you use AWOL's formula,  x= (hix * 256) + lox;

Lefty

mowcius


Go Up