PDA

View Full Version : question about eeprom



zerox
08-14-2008, 06:05 AM
Hi, can i save a value of a var in execution time?, but i need the value remain in memory after a lost off energy, i mean, when the battery is off, i want the value still to be in the memory rom, so when i turn the battery on, the value will be the same then before, is this posible?, thanks for everything.

Jack.-


Jack said...
I just take a look to this post, http://forums.parallax.com/forums/default.aspx?f=5&m=276495&g=276577#m276577 and i understand some of the code, but i still have some questions about the using the write command, when i give him the memory sector to write into the EPROM, i have to give a HEX value? or a simple DEC willl be enough?, like this:

WRITE 0, stuff

OR

WRITE 4B0, stuff

and other, the 0 or 4B0, are like pointers to memory?, thanks for all.-

Jack

Post Edited (zerox) : 8/13/2008 11:44:28 PM GMT

erco
08-14-2008, 06:14 AM
Yes, the WRITE command stores a value in EEPROM and the READ command gets it back. It is stored forever until you overwrite it again.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"If you build it, they will come."

zerox
08-14-2008, 06:32 AM
I just take a look to this post, http://forums.parallax.com/forums/default.aspx?f=5&m=276495&g=276577#m276577 and i understand some of the code, but i still have some questions about the using the write command, when i give him the memory sector to write into the EPROM, i have to give a HEX value? or a simple DEC willl be enough?, like this:

WRITE 0, stuff

OR

WRITE 4B0, stuff

and other, the 0 or 4B0, are like pointers to memory?, thanks for all.-

Jack

Mike Green
08-14-2008, 07:08 AM
The format of the WRITE statement is WRITE <address>,<data>
The <address> is the address in EEPROM of the byte (or first byte) to be written. It can be any numeric expression.
In PBasic, you write hexadecimal numbers with "$" in front, so you'd write $4B0 or the same in decimal (1200).

SRLM
08-14-2008, 07:14 AM
If you have a question about syntax or code abilities, take a look at the Basic Stamp Syntax and Reference manual. It can answer most any question that you have. Just open up the help file in the Basic Stamp Editor or look at the print version, available here:

http://www.parallax.com/tabid/440/Default.aspx

The big yellow book is a useful tool to have on hand (in print) when programming. Mine has the spot of honor just to the left of the monitor...

zerox
08-14-2008, 07:15 AM
okok, but when i read the memory after i shutdown the bs2, well be sometingh like this?, i am writing and reading a string of 8 long, example: "12345678"

FOR EE_PTR=0 TO 8
WRITE EE_PTR, memory(i)
i = i + 1
NEXT

i = 1

FOR EE_PTR=0 TO 8
READ EE_PTR, memory2(i)
i = i + 1
NEXT

the value of the eeprom, will be saved in the memory2 VAR or i am wrong?, thanks

Jack.-

metron9
08-14-2008, 07:46 AM
This should help you out. Use the debug command to test your code.
I used the same array buffer for both reading and writing.



' {$STAMP BS2}
' {$PBASIC 2.5}
' {$PORT COM1}
ee_ptr VAR Byte
memory VAR Byte(8)
ee_ptr=0

'store some data in an array
FOR ee_ptr = 0 TO 8
memory(ee_ptr)=ee_ptr*2
NEXT


'write the array to eeprom
FOR ee_ptr=0 TO 8
WRITE EE_PTR, memory(EE_ptr)
NEXT

'read and display the eeprom memory locations
FOR EE_PTR=0 TO 8
READ EE_PTR, memory(ee_ptr)
DEBUG "Reading ",DEC ee_ptr," = ", DEC memory(ee_ptr), CR
NEXT


▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Think Inside the box first and if that doesn't work..
Re-arrange what's inside the box then...
Think outside the BOX!

Zoot
08-14-2008, 08:14 AM
zerox -- basically, yes it will work that way. The important thing to remember is to *reserve your data space* in any Stamp program that is downloaded to a Stamp that needs to preserve that data after subsequent downloads. Data always start at address 0.

Reserving space means that the Stamp editor will not "accidentally" overwrite existing data (or try to fill that space with code) when a program is downloaded.

For example, I might download a program that just writes my data (I run this app one time):




Preserved DATA @$000, (16) ' this will "reserve" 16 bytes at address $000

WRITE $000, "A"
WRITE $001, "B"
WRITE $002, "C"
'... etc

' or just load the data....

Preserved DATA @$000, "ABCDEFGHIJKLMNOP"





Now, if I download this program, the 16 "reserved" bytes will NOT be overwritten, and the new program can read back the data




i VAR Nib
ioByte VAR Byte

Preserved DATA @$000, (16) ' this will "reserve" 16 bytes at address $000

FOR i = 0 TO 15
READ Preserved + i, ioByte
DEBUG ioByte, CR
NEXT




You can also used read/write for a startup toggle (each time you reset the Stamp, it knows it's been reset...




Reset:
READ 0, ioByte ' read byte at addr 0
ioByte.BIT0 = ~ioByte.BIT0 ' toggle the bit
WRITE 0, ioByte ' save it

Main:
IF ioByte.BIT0 = 0 THEN
FREQOUT Speaker, 1000, 2000
ELSE
FREQOUT Speaker, 1000, 3000
ENDIF
PAUSE 1000
GOTO Main




Each time you hit reset, you'll switch back and forth between the two frequencies of beeps.

Last but not least, addresses on the Stamp go from $000 to $7FF (2k). Multislot Stamps have more memory, but the STORE command is used to choose the slot, then memory is addressed from $000 to $7FF within that slot.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST

1uffakind.com/robots/povBitMapBuilder.php (http://1uffakind.com/robots/povBitMapBuilder.php)
1uffakind.com/robots/resistorLadder.php (http://1uffakind.com/robots/resistorLadder.php)

Post Edited (Zoot) : 8/14/2008 1:23:36 AM GMT