Writing to non-volatile memory?[stares into space]


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2009
    Posts
    653

    Default Writing to non-volatile memory?[stares into space]

    I have a switch that increments a variable each time it is pressed....let's just call the variable 'temp' for ease here.

    What I'd like to happen is that when the switch is held down for say 1 second, that the PIC either powers off or goes to sleep (gotta look into options for this bit).

    Where I'm heading here is that I'd like the PIC to store away the content of the aformentioned variable 'temp' & then restore it upon power up (or coming out of sleep)

    I've not a clue how to approach this!

    What should I be searching for...is there a good thread/primer that cover the steps needed to write a PIC variable into non-volatile memory & read it when the pic powers up (or comes out of sleep....

    (incidentally, are program variables remembered while a PIC sleeps?)

    Many thanks!

  2. #2
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: Writing to non-volatile memory?[stares into space]

    They say the first sign of madness is talking to yourself....

    ok, seek and you shall find as the saying goes, and it should be no surprise that DT has a hand in the solution...

    http://www.picbasic.co.uk/forum/showthread.php?t=2444

    ok, out the blocks I'm getting an error (this'll be the plea for help bit!)

    Code:
    pattern var byte
    @  EE_var  _pattern, byte, 1  ; Link an EE variable to it.
    (the variable I want to track & store has the name 'pattern')

    gives a compilation error....

    "Symbol not previously defined (byte)" for it seems the following bolded asm line....

    Code:
    EE_assign  macro   Name , Value, Size               
      local Assign_Done
      nolist
        if ((EE_PTR + Size) >= EEPROM_SIZE )      list
            error "EEPROM is Full, Could not Fit", Name
        endif
    Any ideas?

    The PIC I'm using is a PIC16f1824
    Last edited by HankMcSpank; - 28th March 2011 at 00:10.

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


    Did you find this post helpful? Yes | No

    Default

    Woohoo, another EE_vars user.
    That's an old one.

    Use Uppercase for the "Size".
    Code:
    @  EE_var  _pattern, BYTE, 1  ; Link an EE variable to it.
    MPASM is case sensitive.
    DT

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


    Did you find this post helpful? Yes | No

    Default

    I should probably mention that you can do the same thing with ...
    Code:
    pattern  var byte : EE_pattern DATA 1             : READ EE_pattern, pattern
    MyWord   var WORD : EE_MyWord  DATA WORD 12345    : READ EE_MyWord, WORD MyWord
    MyLong   var LONG : EE_MyLong  DATA LONG 123456789: READ EE_MyLong, LONG MyLong
    
    ; to save the variables to EEPROM ...
    WRITE EE_pattern, pattern
    WRITE EE_MyWord, WORD MyWord
    WRITE EE_MyLong, LONG MyLong
    No include needed.
    The only difference is that you can't restore to the original "default" value like EE_vars.

    This stuff wasn't available in 2005
    Last edited by Darrel Taylor; - 28th March 2011 at 04:12. Reason: added LONGs
    DT

  5. #5
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: Writing to non-volatile memory?[stares into space]

    Quote Originally Posted by Darrel Taylor View Post
    I should probably mention that you can do the same thing with ...
    Code:
    pattern  var byte : EE_pattern DATA 1             : READ EE_pattern, pattern
    MyWord   var WORD : EE_MyWord  DATA WORD 12345    : READ EE_MyWord, WORD MyWord
    MyLong   var LONG : EE_MyLong  DATA LONG 123456789: READ EE_MyLong, LONG MyLong
    
    ; to save the variables to EEPROM ...
    WRITE EE_pattern, pattern
    WRITE EE_MyWord, WORD MyWord
    WRITE EE_MyLong, LONG MyLong
    No include needed.
    The only difference is that you can't restore to the original "default" value like EE_vars.

    This stuff wasn't available in 2005
    Many thanks Darrel...I shall try this tonight. As it goes, I don't need to restore the original default so that should be dandy.

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