Eeprom question


New Member
I'm writing a program that saves some phrases to eeprom, that are then displayed at appropriate times on an LCD. The 'write to eeprom' instructions are at the start of the program, before the main program begins. I'm using an 18A.

It struck me that once the phrases are written to eeprom the first time, at the initial download of the program, that the job is then done and they shouldn't have to be written there again, as they'll be retained in memory at power-down.

As it is, though, they'll be re-written to eeprom every time I run the program. Although I don't think I'll wear out the eeprom, it does seem somewhat pointless.

Is there a simple way to avoid this?

I've thought of setting a flag, perhaps by writing a 1 to eeprom 0 after the phrases are written, at the initial download. The first instruction in the program would then be to read the flag and, if it's set, skip the writing of the phrases.

Have I lost the plot?


Technical Support
Staff member
You're right and you've even seen the right solution. Check to see what's in Eeprom and if it's not what's expected, put the data where it should be, next time the program will run without having to re-write Eeprom. This works for both internal Data Eeprom and external I2C Eeprom.

Rather than have a flag it is often easier ( and overcomes a number of other issues ) to go through the entire process of writing to Eeprom but only do an actual write when the data alreday there does not match what you want it to be.

Using the 18A, I presume you are using internal Data Eeprom; it may be easier to put your phrases directly into EEPROM commands to save having to create them under program control.


Senior Member
I'm a little confused here.

If there's nothing in your program that can change EEPROM data once the chip has been programmed, I don't think you need to ever worry about re-writing the EEPROM. No sense wasting program memory by having the EEPROM fill routine present.

Or is there something specific to the 18A that I don't know?



New Member
Thanks very much, Hippy and Tom2000.

Tom, I am hoping to avoid the eeprom re-write, but I have to have the routine present in the program to write the phrases the first time.

They are stock phrases that get displayed on the LCD depending on what the user does.


EEPROM 1, ("Phrase 1")
EEPROM 9, ("Phrase 2")

if user does oneThing send Phrase 1 to LCD
if user does anotherThing send Phrase 2 to LCD
goto main

End pseudocode.

After the initial download, and the initial writing of the phrases to eeprom, I want subsequent runs of the program to jump straight to the main routine, bypassing the eeprom writes.

So I was proposing to preface the eeprom writes with:

read 0, b0
if b0 = 1 then main

and end the eeprom writes with:

eeprom 0, (1) ;err, not sure that's the right syntax...

Then the intial download will write the phrases, and the 1, to eeprom. Subsequent runs of the program will check eeprom 0 contains a 1 and, if it does, skip straight to main routine.

Of course, it would help if I knew what I was doing!



Senior Member
Ah! Now I understand, Jo.

When you enter either DATA addr,(......) or EEPROM addr,(.....) into your program listing, that is just loaded into EEPROM when you program your chip. It doesn't get written to program memory, nor is it part of your runtime code.

You can actually think of it as two separate operations. (Matter of fact, if you watch the status window while your chip is being programmed, you'll see it writing to EEPROM, then writing to program memory. Or vice versa.)

The bottom line is that you don't have to put any runtime code in your program to verify EEPROM data (unless, of course, there's a chance that something in your runtime code might modify EEPROM.) Just read your pre-programmed strings and be happy.

Good luck!



New Member
So, I've been trying to stop something that wont actually occur! Thanks very much for clearing that up, Tom. I am a dunce. :)

Cheers, mate.


Senior Member
Don't feel bad. I think I stumbled over this very thing when I first started playing with Picaxe chips.

Have fun!