PDA

View Full Version : Blank Variable



GatorGuy
- 5th February 2010, 09:00
I need to read the first bit of the EEPROM and store that value into a variable. That part is easy, however, I need the program to do something if the EEPROM is empty such as the first time the pic is turned on. I cant set it each time the pic is turned on because I want it to store what was last used.

eg.

s1 var byte

READ 0, s1
if s1 = "" then s1 = "1" <---- This is where I get errors
.
.
.
'rest of the program

How can I change this?

mackrackit
- 5th February 2010, 09:12
If the EEPROM has not been changed it will read HEX FF, BIN 11111111 or DEC 255.

Acetronics2
- 5th February 2010, 09:40
Hi, Dave

Gator must be told the numbers to compare to do no use " " ( quotes ) and the "BLANK" value does not exist.

Suppose it' as a re-used chip ... everything ( 0 -255 ! ) possible as a value.

Also Note I have received brand new chips which EEPROM had been tested ( value of the location written for the 0, 8, 16, 24, .... th locations , and Zeroes everywhere )...

Alain

mackrackit
- 5th February 2010, 09:46
Good points.

So maybe the solution for Gator is to write a program to run that will write a known value to the EEPROM then re-program the PIC with the working code.

Might not be so good for production though.

Acetronics2
- 5th February 2010, 09:56
Gator just wants the values not to be overwritten @ further power ups ...

so, it only needs to write a SURE default value @ first programming ( DATA ...)

I do agree the DATA line must be commented or modified ,if some minor ( ? ) prog mods are done AND he doesn't want to loose previous values.

But this never happens in real life ... does it ???

Alain

mackrackit
- 5th February 2010, 10:12
Idea...
Not sure exactly how to do it...

Use WRITECODE to over write the DATA line.

Where is the DATA line???

GatorGuy
- 5th February 2010, 10:56
Thanks for the ideas. I found an easy way now:

This isnt the code but gives the idea.

READ 0, blah
startup:
if blah = "1" then goto 1
if blah = "2" then goto 2

WRITE 0, "1" 'if it wasnt 1 or 2 then it reaches here
goto startup

1:
2:

This way if it doesnt have a needed value, it writes it then restarts. The second time it runs it will have one of the right values.

GatorGuy
- 5th February 2010, 10:58
Quick EEPROM question while I'm at it. How reliable is the EEPROM memory? I want that value to stay there once the user selects it no matter how many shutdowns/powerups there are.

Jerson
- 5th February 2010, 11:05
A typical way that I use in my codings

At power on
if EEPROM_Magic <> $1234 then
' store initial defaults to EEPROM (as many as you need)
EEPROM_Magic = $1234 ' indicate I have valid readings here
' and save all these values to the eeprom
endif

' Now load the EEPROM values and continue with program

EEPROM_Magic is a word sized variable that is saved in EEPROM and contains a magic number that you choose(1234 Hex here)

Regards

Acetronics2
- 5th February 2010, 13:21
Thanks for the ideas. I found an easy way now:

This isnt the code but gives the idea.

READ 0, blah
startup:
if blah = "1" then goto 1
if blah = "2" then goto 2

WRITE 0, "1" 'if it wasnt 1 or 2 then it reaches here
goto startup

1:
2:

This way if it doesnt have a needed value, it writes it then restarts. The second time it runs it will have one of the right values.


NO QUOTES AROUND VALUES !!!! ...
Grrrrr ...

mackrackit
- 5th February 2010, 14:05
Quick EEPROM question while I'm at it. How reliable is the EEPROM memory? I want that value to stay there once the user selects it no matter how many shutdowns/powerups there are.
They have something like 1,000,000 erase/write cycles.
Just make sure a write is not happening during power down.

And no " " " " " " " " " "

Luckyborg
- 5th February 2010, 17:05
I usually add this near the top of my code before any variable declarations


data @0, 0(256) 'set all EEPROM data to 0 on initial programming
Just be mindful of how much EEPROM your chip has, and you might want to write 255 instead of 0. You might only use 10 locations and that would look like


data @0, 255(10) 'set 10 EEPROM data to 255 on initial programming

Then early in the loop read and check for the default value

David