EEPROM Problem & Switch problem (Solved)

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
User avatar
Jordy101091
Posts: 519
Joined: Sat Jan 08, 2011 4:02 pm
Location: The Netherlands
Has thanked: 25 times
Been thanked: 188 times
Contact:

EEPROM Problem & Switch problem (Solved)

Post by Jordy101091 »

Hello everyone,

I've trouble reading and writing to the eeprom of my PIC18F8722.
I wan to write a value of 296 to the eeprom, this is a value of a calibration process.
but when I read the same address the result is different.
Also I have tryed to write to address 1 instead of address 0 but same result.

Can some body look into this, because this setting cannot be lost after power-down.

And then there is a switch problem this is a snap-shot of a macro that i'm using for my calibration menü:

Image

as you can see here that I can use my rotary encoder to select the different sensors when I press the rotary encoder""ROT_SW" then its should enter that sub menu of sensor CO2 bt it never does, When I hold down so ROT_SW remains High end then rotate the encoder to select sensor CO2 then it enters the submenu, I dont know how where this behavior comes from because I used the same system in every menu and there it works perfectly.

Hope somebody has suggestion for this solve,

Regards Jordy
Last edited by Jordy101091 on Sun Aug 05, 2012 12:38 pm, edited 1 time in total.
the will to learn, should not be stopped by any price

Spanish_dude
Posts: 594
Joined: Thu Sep 17, 2009 7:52 am
Location: Belgium
Has thanked: 63 times
Been thanked: 102 times

Re: EEPROM Problem & Switch problem

Post by Spanish_dude »

Hi,
296 is a 9 bit value. EEPROM can save 8 bit values.
That's why when you read the value back, it's different.

What you need to do is split the value in 2 bytes and save those bytes to the EEPROM.
You can then read those 2 bytes back and put them together to make your 2 bytes value.

Code: Select all

byte = (value >> 8) & 0xFF;
write_to_eeprom(address, byte); // write high byte
byte = value & 0xFF;
write_to_eeprom(address+1, byte); // write low byte

--------------------

byte = read_from_eeprom(address); // read high byte
value = byte << 8;
byte = read_from_eeprom(address+1); // read low byte
value = value | byte;
Don't know about your switch problem.

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times

Re: EEPROM Problem & Switch problem

Post by kersing »

Jordy101091 wrote:Hello everyone,

I've trouble reading and writing to the eeprom of my PIC18F8722.
I wan to write a value of 296 to the eeprom, this is a value of a calibration process.
but when I read the same address the result is different.
Also I have tryed to write to address 1 instead of address 0 but same result.
You can only store values 0 to 255 (byte) in a single location. You will have to split 296 over two locations. Store the value / 256 in one and the remainder in the other location.
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times

Re: EEPROM Problem & Switch problem

Post by Enamul »

Hi,
Although Nicolus clearly describes the idea..I thought it would be better to say bit more in FC..
For example, you want to write EE_DATA whose value is more than 255...declare EE_DATA as INT and DATA_H and DATA_L as Byte.
Write:
To write data in EEPROM, in calculation box...

Code: Select all

DATA_H = EE_DATA>>8
DATA_L = EE_DATA AND 0x00FF
1. EEPROM write macro...to write DATA_H
2. EEPROM write macro...to write DATA_L

Read:
1. EEPROM read macro..to read DATA_H
2. EEPROM read macro..to read DATA_L
To combine two 8-bit data into 16-bit data...in calculation box..

Code: Select all

EE_DATA = DATA_H
EE_DATA = (EE_DATA<<8) OR DATA_L
you will get EE_DATA as INT..
To deal with your Switch problem..can you post the program or the modified program with switch portion?
Enamul
Enamul
University of Nottingham
enamul4mm@gmail.com

User avatar
Jordy101091
Posts: 519
Joined: Sat Jan 08, 2011 4:02 pm
Location: The Netherlands
Has thanked: 25 times
Been thanked: 188 times
Contact:

Re: EEPROM Problem & Switch problem

Post by Jordy101091 »

Hi guys,

Sorry for this late response, I'm very bussy with work these days, this weekend I've got my switch problem working properly, I dont know what the cuase of the problem was, but i deleted all and builded it up again and now it works the way it supposed to.

as for the EEPROM this works perfect thanks for that.

Regards Jordy
the will to learn, should not be stopped by any price

Post Reply