Loading EEPROM


Closed Thread
Results 1 to 7 of 7

Thread: Loading EEPROM

  1. #1

    Default Loading EEPROM

    How to enter the initial starting value into eeprom for a word
    variable?

    For example, suppose the variable is:

    VITtime var word

    it will be read from eeprom in 2 bytes, say:
    read 0, VITtime.byte0
    read 1, VITtime.byte1

    Suppose I want the initially programmed numerical value in eeprom to be 365 (a word size number)
    I usually use the EEPROM statement to enter initial numbers. Should it be:

    EEPROM [5,36,....... .....]
    or
    EEPROM [65,3,.............]
    or
    EEPROM [365,.............]

    or what?

  2. #2


    Did you find this post helpful? Yes | No

    Default

    To load 365 in an eeprom location at programming time it would be:

    Code:
    data 109, 1
    or

    Code:
    data %1101101,%1
    This comes from breaking down the bits in the bytes of the word variable

    decimal 365 = 0000 0001 0110 1101 binary

    Since there are 8 bits to a byte, we now know that byte0 is 0110 1101b and byte1 is 0000 0001b. Convert these to decimal and you get 109 and 1 respectively. Both commands will accomplish the same thing.

    You can also use:

    Code:
    write address, variable.Byte1
    write address, variable.Byte0
    and
    Code:
    read address, variable.Byte1
    read address, variable.Byte0
    This way can be done anywhere in the program. The DATA command is used to pre-load the eeprom location at time of programming.
    Last edited by CocaColaKid; - 23rd August 2005 at 05:07.

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    OR, if you didn't feel like breaking down every word sized number manualy, you can let the compiler help you out.
    Code:
    Days   CON    365
    Dogs   CON   1024
    Mice   CON  10000
    
    EEPROM [Days&$FF, Days>>8, Dogs&$FF, Dogs>>8, Mice&$FF, Mice>>8]
    Which would load ...

    109, 1, 0, 4, 16, 39

    It may seem a little awkward, but it's easier to make changes later on.

    <br>
    DT

  4. #4


    Did you find this post helpful? Yes | No

    Default

    Thanks guys .... it works.

  5. #5
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    And, I completely forgot about the WORD modifier for the DATA statement.

    DATA WORD 365

    This would also store it as ...

    109, 1

    <br>
    I hope Bruce and Melanie weren't watching
    Last edited by Darrel Taylor; - 24th August 2005 at 07:29.
    DT

  6. #6


    Did you find this post helpful? Yes | No

    Default

    Now that is something I didn't know! Man that really makes things a lot easier. I'll have to try that when I get back in to office.

  7. #7
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor
    I hope Bruce and Melanie weren't watching
    I'm not one of the above but... i saw you

    KISS programming, is the best way. We often forget the base of it.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

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. How to define constants that specify eeprom addresses
    By DwayneR in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 8th December 2009, 05:07
  3. Problem with I2C EEPROM addressing
    By Atom058 in forum General
    Replies: 14
    Last Post: - 3rd November 2009, 04:17
  4. How to write/read strings EEPROM/LCD
    By g-hoot in forum mel PIC BASIC Pro
    Replies: 22
    Last Post: - 11th February 2007, 07:26
  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 : 1

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