Blank Variable


Closed Thread
Results 1 to 12 of 12

Thread: Blank Variable

  1. #1
    Join Date
    Jan 2010
    Posts
    24

    Default Blank Variable

    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?

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


    Did you find this post helpful? Yes | No

    Default

    If the EEPROM has not been changed it will read HEX FF, BIN 11111111 or DEC 255.
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,651


    Did you find this post helpful? Yes | No

    Wink

    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
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Default

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

  5. #5
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,651


    Did you find this post helpful? Yes | No

    Default

    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
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Default

    Idea...
    Not sure exactly how to do it...

    Use WRITECODE to over write the DATA line.

    Where is the DATA line???
    Dave
    Always wear safety glasses while programming.

  7. #7
    Join Date
    Jan 2010
    Posts
    24


    Did you find this post helpful? Yes | No

    Default

    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.

  8. #8
    Join Date
    Jan 2010
    Posts
    24


    Did you find this post helpful? Yes | No

    Default

    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.

  9. #9
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    967


    Did you find this post helpful? Yes | No

    Default

    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

  10. #10
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,651


    Did you find this post helpful? Yes | No

    Angry

    Quote Originally Posted by GatorGuy View Post
    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 ...
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by GatorGuy View Post
    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 " " " " " " " " " "
    Dave
    Always wear safety glasses while programming.

  12. #12
    Join Date
    Feb 2009
    Location
    Southern California
    Posts
    86


    Did you find this post helpful? Yes | No

    Default

    I usually add this near the top of my code before any variable declarations

    Code:
    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

    Code:
    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

Similar Threads

  1. EEPROM Variables (EE_Vars.pbp)
    By Darrel Taylor in forum Code Examples
    Replies: 79
    Last Post: - 26th October 2012, 00:06
  2. Variable PWM PIC18F2431
    By trr1985 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 12th June 2009, 06:03
  3. Help with sound command in 2 programs
    By hyperboarder in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th July 2007, 20:36
  4. set flags within a variable?
    By peterdeco1 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 24th October 2006, 11:07
  5. WORD vs BYTE variable lengths
    By bartman in forum General
    Replies: 0
    Last Post: - 28th November 2005, 21:16

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