PDA

View Full Version : Write to eeprom



mradde
- 30th January 2009, 02:16
How do i do so the PIC don't write to same address every time? So each time the PIC write to eeprom it write to a new address.

mackrackit
- 30th January 2009, 04:31
PBP has a way of looking at the EEPROM addresses as simple numbers.
So you can
WRITE 0
WRITE 1
WRITE 2
all are different places in the EEPROM.

Want to automatically increment?

X = X + 1
WRITE X

Charles Linquis
- 30th January 2009, 04:38
I think you may be asking how you write to a different address - even across power cycles.

If that is the case, write to the EEPROM, and then write the last-used address + 1 to the two highest EEPROM addresses (1022 and 1023 on many devices)

Before you write to EEPROM, read those two addresses to get the next address to write to, and when you are done, write the last address + 1 to 1022 and 1023 again.

mradde
- 31st January 2009, 20:00
Want to automatically increment?

X = X + 1
WRITE X
This works for sure, but if the PIC shuts down it will overwrite the EEPROM from the beginning.



I think you may be asking how you write to a different address - even across power cycles.

If that is the case, write to the EEPROM, and then write the last-used address + 1 to the two highest EEPROM addresses (1022 and 1023 on many devices)

Before you write to EEPROM, read those two addresses to get the next address to write to, and when you are done, write the last address + 1 to 1022 and 1023 again.
Could you please tell me more about this?

Charles Linquis
- 31st January 2009, 22:29
I don't know what I didn't already explain.

But..

When you program your device, make certain that you erase the EEPROM to all '0's'.

Now if you want to write to the EEPROM

READ 1023,WriteStart.LowByte
READ 1024,WriteStart.HighByte

Now write your data -

WRITE WriteStart,(your data goes here)
WriteStart = WriteStart + 1

Now write back the value of WriteStart so it can be the starting address
the next time you WRITE. Every time you issue a WRITE, you need to
increment WriteStart. When you are done writing (or even after every WRITE
if you really want to protect against power failure).

WRITE 1023,WriteStart.LowByte
WRITE 1024,WriteStart.HighByte

mradde
- 1st February 2009, 15:38
Charles: I do understand now, thanks!!

Charles Linquis
- 1st February 2009, 18:27
Just don't make the mistake I just did. The highest address on a 1024 byte EEPROM is 1023!