I would like to write to Eeprom
Moderator: Benj
-
- Posts: 95
- Joined: Sat Jun 11, 2011 4:12 am
- Has thanked: 87 times
- Been thanked: 31 times
- Contact:
I would like to write to Eeprom
Hi Guys, I wanted to play around with eeprom? I would like to be able to store into permanent memory a value when a button is pressed. I did some searching but couldn’t come up with anything. I am using the 16F877A chip. I did find a few things in a great book I have, Microcontroller Systems Engineering by Bert van Dam that Martin turned me onto. Bert talks about writing from PPP and I want to writing from a button press. Any direction would be greatly appreciated!
Have a great day!
Werner
Have a great day!
Werner
Werner
STUDENT OF: Martin - Professor of Flowcode, John, Jan, Fotios and Nicolas "Spanish Dude"
STUDENT OF: Martin - Professor of Flowcode, John, Jan, Fotios and Nicolas "Spanish Dude"
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: I would like to write to Eeprom
Writing and reading to EEPROM is straight forward with Flowcode. But it is only available if you have professional version.
Sorry but Unfortunately EEPROM is not available if you have the student version since it's classed as advanced component
If you have the student version, when you compile you will just get an unable to compile error.
So you can see what components you can and can't use, here is a list (see page 9 ) from the marketing data sheet which can be found here:
http://www.matrixmultimedia.com/datashe ... 4-60-7.pdf If you still want an example posting, If you want to explain how you would like to read the EEPROM e.g via LCD or via programmer I will sort something out for you.
@Matrix Multimedia.
I could not see in the data sheet the new devices added since the FC4.5. E.g. 16F18xx etc.
Martin
Sorry but Unfortunately EEPROM is not available if you have the student version since it's classed as advanced component
If you have the student version, when you compile you will just get an unable to compile error.
So you can see what components you can and can't use, here is a list (see page 9 ) from the marketing data sheet which can be found here:
http://www.matrixmultimedia.com/datashe ... 4-60-7.pdf If you still want an example posting, If you want to explain how you would like to read the EEPROM e.g via LCD or via programmer I will sort something out for you.
@Matrix Multimedia.
I could not see in the data sheet the new devices added since the FC4.5. E.g. 16F18xx etc.
Martin
Martin
-
- Posts: 95
- Joined: Sat Jun 11, 2011 4:12 am
- Has thanked: 87 times
- Been thanked: 31 times
- Contact:
Re: I would like to write to Eeprom
Hi Martin, Thanks for the reply! Yes I work with Flowcode Professional and do have the function available I just can’t figure out how to make it do what I want? What I am looking to do is have a value permanently stored from an existing variable. I am still working on my model railroad turntable program and thanks to you have it working great. The one thing is that some of my inbound tracks leading toward the turntable bridge are not in perfect alignment when the bridge is located at the programmed position. I could pull the track up and relocate it which would be a lot of work or thought that I should be able to save the correct position in my chip? The idea is that I would be able to jog my stepper motor to perfect alignment and than push a button to record that position for that programmed location.
Thanks for the help Buddy!
Werner
PS my chip is listed here:
[img] [/img]
Thanks for the help Buddy!
Werner
PS my chip is listed here:
[img] [/img]
Werner
STUDENT OF: Martin - Professor of Flowcode, John, Jan, Fotios and Nicolas "Spanish Dude"
STUDENT OF: Martin - Professor of Flowcode, John, Jan, Fotios and Nicolas "Spanish Dude"
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: I would like to write to Eeprom
Ah fair enough bud. The reason I assumed you had Flowcode student is because of your signatureWerner wrote: Yes I work with Flowcode Professional and do have the function available
Code: Select all
Werner
EB-006, E-Blocks, Flowcode Student!
Basically to save the number 22 to address 1 of EEPROM, you just enter 1,22 in the EEPROM write component.
Or
To read at address 0 and place value in a variable called index just enter 0 for Address and index in the return value(byte) box
I have modify your flowchart to store value of Index in EEPROM address 0 (Since you have 256 EEPROM addresses available. valid address is 0 to 255 and the number or variable can only be 0 to 255 since EEPROM is only 8 bits) This is done in Codegood Macro.
I have also used an addition number 22 (my birthday lol) to be stored in address 1 of EEPROM.
The reason for this is when you 1st run the turntable program, you want to read value of index variable that's stored in address 0 of EEPROM.
But if you have never used the turntable program, or you have just burned the hex file to chip, then the wrong value will be in address 0, so you do not want that stored in index variable.
So when power s 1st applied, the value of EEPROM address 1 is read. If this value = 22 then index = address 0 of EEPROM
Else index = 0
When you key a new value on the keypad, not only does Index get stored, but also 22 gets stored, so the program know the value in address 0 is a valid number for index variable.
I have also incorporated a jog facility. When you first run the program, if you keep pressing and releasing the Enter switch before the Initialise switch then the value of jog is incremented. The value of jog is stored at EEPROM address 3 after the Initialise switch is activated, so you will be able to use it as you wish.
I guess I can set it up so the Jog value is entered via the keypad instead of as switch, but hats up to you.
Hope I have explained it all ok?
Martin
- Attachments
-
- NewWork12_modifed2.fcf
- (32.3 KiB) Downloaded 521 times
Last edited by medelec35 on Fri Nov 18, 2011 8:10 am, edited 1 time in total.
Martin
-
- Posts: 95
- Joined: Sat Jun 11, 2011 4:12 am
- Has thanked: 87 times
- Been thanked: 31 times
- Contact:
Re: I would like to write to Eeprom
Hi Martin, I have been going over this the last few days and I think I am starting to get it. It seems I am always hunting for more info on this type of thing and never finding it. One question I have is that somehow I lost my Eeprom component graphic on my panel? I looked everywhere and can’t seem to find it. It is still in the program as I can see it in my Component Macro list. I kind of do remember dragging it onto the program work area (off the panel) and I think that’s when it diapered. Do you have any Ideas?
Thank Buddy!
Werner
Thank Buddy!
Werner
Werner
STUDENT OF: Martin - Professor of Flowcode, John, Jan, Fotios and Nicolas "Spanish Dude"
STUDENT OF: Martin - Professor of Flowcode, John, Jan, Fotios and Nicolas "Spanish Dude"
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: I would like to write to Eeprom
Sure.
Here's how to get it back.
1: 2: By the way, I like the name Berry go Round. Very clever play on words with your surname.
I also wanted to thank you for yours and Brandon's continuous kind words.
Martin
Here's how to get it back.
1: 2: By the way, I like the name Berry go Round. Very clever play on words with your surname.
I also wanted to thank you for yours and Brandon's continuous kind words.
Martin
Martin
-
- Posts: 95
- Joined: Sat Jun 11, 2011 4:12 am
- Has thanked: 87 times
- Been thanked: 31 times
- Contact:
Re: I would like to write to Eeprom
Thanks Martin, I knew you would know how to fix this!
Its all true!!
Have a great day Buddy!
Werner
Its all true!!
Have a great day Buddy!
Werner
Werner
STUDENT OF: Martin - Professor of Flowcode, John, Jan, Fotios and Nicolas "Spanish Dude"
STUDENT OF: Martin - Professor of Flowcode, John, Jan, Fotios and Nicolas "Spanish Dude"
-
- Posts: 95
- Joined: Sat Jun 11, 2011 4:12 am
- Has thanked: 87 times
- Been thanked: 31 times
- Contact:
Re: I would like to write to Eeprom
Hi Guy's, where do the values come from that are in the eeprom table when you first pull in the component? They look totally random but I know that can't be the case?
Thanks for the help! Have a great day!
Werner
Thanks for the help! Have a great day!
Werner
Werner
STUDENT OF: Martin - Professor of Flowcode, John, Jan, Fotios and Nicolas "Spanish Dude"
STUDENT OF: Martin - Professor of Flowcode, John, Jan, Fotios and Nicolas "Spanish Dude"
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: I would like to write to Eeprom
I believe in Flowcode they are just random.
On real hardware, all addresses default to FF
Martin
On real hardware, all addresses default to FF
Martin
Martin
-
- Posts: 95
- Joined: Sat Jun 11, 2011 4:12 am
- Has thanked: 87 times
- Been thanked: 31 times
- Contact:
Re: I would like to write to Eeprom
Thanks Martin, I never would have thought random. I am back to working on my turntable project and am struggling with what I am trying to do. By the way thanks to you I have it working perfectly on perfect centers. But in the case it needs to be adjusted +or- a few steps is what I am working on. One full revolution of my table is 6000 steps for my stepper motor. That is divided into my 40 position each one 150 step apart. The eeprom will only take positive numbers and a number no greater than 255. So what I am thinking is that I may have to use 80 eeprom locations to store information. 1-40 would be to store the difference in steps from perfect center. And let’s say 101-140 to store 0 which would mean (-) steps from perfect center or 1 which would mean (+) steps from perfect center. So position 10 is entered which would be 1500 steps +or- the calibration steps. Does this sound like I am on the right track?
Thank Buddy!
Werner
Thank Buddy!
Werner
Last edited by Werner on Wed Nov 23, 2011 4:45 am, edited 1 time in total.
Werner
STUDENT OF: Martin - Professor of Flowcode, John, Jan, Fotios and Nicolas "Spanish Dude"
STUDENT OF: Martin - Professor of Flowcode, John, Jan, Fotios and Nicolas "Spanish Dude"
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: I would like to write to Eeprom
Hi Werner,
There is a better way. For one of my projects I needed to strore a number from 0 to 32767 (10bit int) in the EEPROM. To do that you take the 10bit int and spit it into bytes. Store in EEPROM, Then when to want to retrieve the 0 to 32767 the two bytes are retrieved and converted back into 10 bit int.
See:
http://www.matrixmultimedia.com/mmforum ... =26#p20779
for the formulas.
If you get stuck I can help you further.
Martin
There is a better way. For one of my projects I needed to strore a number from 0 to 32767 (10bit int) in the EEPROM. To do that you take the 10bit int and spit it into bytes. Store in EEPROM, Then when to want to retrieve the 0 to 32767 the two bytes are retrieved and converted back into 10 bit int.
See:
http://www.matrixmultimedia.com/mmforum ... =26#p20779
for the formulas.
If you get stuck I can help you further.
Martin
Last edited by medelec35 on Wed Nov 23, 2011 8:18 am, edited 1 time in total.
Martin
-
- Posts: 95
- Joined: Sat Jun 11, 2011 4:12 am
- Has thanked: 87 times
- Been thanked: 31 times
- Contact:
Re: I would like to write to Eeprom
Hi Martin, Thanks for the help! I am going to digest this in the next few days and see if I can get it.
Thanks again have a great day!
Werner
Thanks again have a great day!
Werner
Werner
STUDENT OF: Martin - Professor of Flowcode, John, Jan, Fotios and Nicolas "Spanish Dude"
STUDENT OF: Martin - Professor of Flowcode, John, Jan, Fotios and Nicolas "Spanish Dude"
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: I would like to write to Eeprom
Your welcome.
I have made a demo flowchart for you.
It shows how to split integer into two bytes, save to EEPROM, retrieve the two bytes from EEPROM & finally convert back to the original integer
This should make it easier for you.
Martin
I have made a demo flowchart for you.
It shows how to split integer into two bytes, save to EEPROM, retrieve the two bytes from EEPROM & finally convert back to the original integer
This should make it easier for you.
Martin
- Attachments
-
- Save Int to EEPROM.fcf
- (6 KiB) Downloaded 451 times
Martin
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: I would like to write to Eeprom
Just re-read your post.Werner wrote:But in the case it needs to be adjusted +or- a few steps is what I am working on. The eeprom will only take positive numbers and a number no greater than 255
Since you are taking the Int and splitting into bytes, this means that you can store numbers on EEPROM the range from -32768 to 32767. So you will be able to store and retrieve negative numbers. Here is the same attachment as above, but with -1234 stored and retrieved on EEPROM.
This will make it a lot eaiser for you
Martin
- Attachments
-
- Save -ve Int to EEPROM.fcf
- (6.5 KiB) Downloaded 425 times
Martin
-
- Posts: 95
- Joined: Sat Jun 11, 2011 4:12 am
- Has thanked: 87 times
- Been thanked: 31 times
- Contact:
Re: I would like to write to Eeprom
Thanks Martin, What is the << Shift actually doing? In my mind I like the second formula because I can visualize what It is doing but it looks as though to get the formulas to work right with (-) numbers you need to use the first example?
IntValue = ByteLow+(ByteHigh << 8)
ByteLow = IntValue & 0xFF
ByteHigh = (IntValue >> 8) & 0xFF
IntValue = ByteLow+(ByteHigh * 256)
ByteHigh = (IntValue/ 256)
ByteLow = IntValue - ByteHigh* 256
Thanks for the help Buddy!
Werner
IntValue = ByteLow+(ByteHigh << 8)
ByteLow = IntValue & 0xFF
ByteHigh = (IntValue >> 8) & 0xFF
IntValue = ByteLow+(ByteHigh * 256)
ByteHigh = (IntValue/ 256)
ByteLow = IntValue - ByteHigh* 256
Thanks for the help Buddy!
Werner
Werner
STUDENT OF: Martin - Professor of Flowcode, John, Jan, Fotios and Nicolas "Spanish Dude"
STUDENT OF: Martin - Professor of Flowcode, John, Jan, Fotios and Nicolas "Spanish Dude"
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: I would like to write to Eeprom
Hi Werner your welcome.Werner wrote:Thanks Martin, What is the << Shift actually doing?
I posted some information on << & >> here:
http://www.matrixmultimedia.com/mmforum ... 188#p26188
I totally agree with you. the lower formula is easy to read but, like you say it wont work with the negative numbers.Werner wrote:In my mind I like the second formula because I can visualize what It is doing but it looks as though to get the formulas to work right with (-) numbers you need to use the first example?
For that you will have to stick with the 1st lot of formulas I'm sorry to say
Martin
Re: I would like to write to Eeprom
Google tells me that usually the default values in a new EEPROM are all FFh (255). But it does depend on the complier options you are using and some can be set to give other values. In Flowcode v5 are they definitely all 255?medelec35 wrote:I believe in Flowcode they are just random.
On real hardware, all addresses default to FF
Martin
Sorry if I should have started a new thread for this.
- Enamul
- Posts: 1772
- Joined: Mon Mar 05, 2012 11:34 pm
- Location: Nottingham, UK
- Has thanked: 271 times
- Been thanked: 814 times
- Contact:
Re: I would like to write to Eeprom
What I would like to do is preload one or two EEPROM locations with set values. Can this be done when loading the hex? Problem with doing it as part of the normal programme is that it rewrites it back to the default value every time you boot and I don't want this as the user may later legitimately change the value through the device's menu system.
In V5 the EEPROM component has some boxes for initial values but not clear if these are the initial values of the EEPROM location or the variable that is used to load that location. If the latter the variable will rewrite EEPROM to the default value upon every boot.
In V5 the EEPROM component has some boxes for initial values but not clear if these are the initial values of the EEPROM location or the variable that is used to load that location. If the latter the variable will rewrite EEPROM to the default value upon every boot.
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: I would like to write to Eeprom
As an extra safe guard:
What I do is when I need to update an address of EEPROM I write a fixed value at a fixed address.
So on power up, this one fixed address is read. If the fixed value is read and is correct, then the other addresses of EEPROM is read and used for data retrieval.
If on power up the Fixed value at a fixed address is wrong, then rest of EEPROM is not read, and default values are used instead.
I have been using this method for some time and does not let me down.
If you want to post your flowchart, (even a cut down version)
I can alter it so it does what I have suggested.
Martin
What I do is when I need to update an address of EEPROM I write a fixed value at a fixed address.
So on power up, this one fixed address is read. If the fixed value is read and is correct, then the other addresses of EEPROM is read and used for data retrieval.
If on power up the Fixed value at a fixed address is wrong, then rest of EEPROM is not read, and default values are used instead.
I have been using this method for some time and does not let me down.
If you want to post your flowchart, (even a cut down version)
I can alter it so it does what I have suggested.
Martin
Martin
Re: I would like to write to Eeprom
Thanks Martin for offer but I can work that out myself. Is corruption of EEPROM that common that your test is needed? My values might get deliberately altered only a couple of times in the whole life of the equipment.
Still would be easier to preload the EEPROM.
Still would be easier to preload the EEPROM.