PDA

View Full Version : Writing to non-volatile memory?[stares into space]



HankMcSpank
- 27th March 2011, 20:43
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!

HankMcSpank
- 28th March 2011, 00:07
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!)



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




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

Darrel Taylor
- 28th March 2011, 02:32
Woohoo, another EE_vars user. :)
That's an old one.

Use Uppercase for the "Size".

@ EE_var _pattern, BYTE, 1 ; Link an EE variable to it.
MPASM is case sensitive.

Darrel Taylor
- 28th March 2011, 04:00
I should probably mention that you can do the same thing with ...


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

HankMcSpank
- 28th March 2011, 11:25
I should probably mention that you can do the same thing with ...


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

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.