Write to eeprom


Closed Thread
Results 1 to 7 of 7

Thread: Write to eeprom

  1. #1
    Join Date
    Jan 2009
    Posts
    16

    Default Write to eeprom

    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.

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    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
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    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.
    Charles Linquist

  4. #4
    Join Date
    Jan 2009
    Posts
    16


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    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.


    Quote Originally Posted by Charles Linquis View Post
    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?

  5. #5
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    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
    Charles Linquist

  6. #6
    Join Date
    Jan 2009
    Posts
    16


    Did you find this post helpful? Yes | No

    Default

    Charles: I do understand now, thanks!!

  7. #7
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    Just don't make the mistake I just did. The highest address on a 1024 byte EEPROM is 1023!
    Charles Linquist

Similar Threads

  1. Can't read sequential addresses in external EEPROM
    By tjkelly in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 18th February 2010, 15:46
  2. Problem with I2C EEPROM addressing
    By Atom058 in forum General
    Replies: 14
    Last Post: - 3rd November 2009, 04:17
  3. PIC16F684 + LCD to use the 256bytes of EEPROM - HELP
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 7th March 2008, 15:19
  4. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 18:27
  5. word variable to 25lc640
    By TONIGALEA in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 6th July 2004, 20:59

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts