storing data to eeprom then recalling at a later time
mike_1234
Posts: 21
Hello,
i hope someone has some ideas for me.
Im trying to get my bs2pe to do some data logging for me.· For the moment i just want the inputs to store decimal numbers to simplify things example.... input 0 = decimal number 1.
I want to beable to store the number in eeprom then increment to the next memory location and store another number.·
Also i want to extract the data that was stored in eeprom, the unit will be operating with out a serial cable attached so when i plug it back in i need to download its contents.
Here is the code i have so far, its not much but hopefully someone can help me fill in the blanks... i'm kinda new to programming at higher level languages so be easy on·me.
' {$STAMP BS2pe}
' {$PBASIC 2.5}
n1·· PIN 0
n2·· PIN 1
n3·· PIN 2
n4·· PIN 3
idx·· VAR· Byte
value· VAR· Byte
Main:
IF n1=1 THEN SUB1
GOTO main
SUB1:
WRITE 0, 1
GOTO main
Thanks,
Mike
i hope someone has some ideas for me.
Im trying to get my bs2pe to do some data logging for me.· For the moment i just want the inputs to store decimal numbers to simplify things example.... input 0 = decimal number 1.
I want to beable to store the number in eeprom then increment to the next memory location and store another number.·
Also i want to extract the data that was stored in eeprom, the unit will be operating with out a serial cable attached so when i plug it back in i need to download its contents.
Here is the code i have so far, its not much but hopefully someone can help me fill in the blanks... i'm kinda new to programming at higher level languages so be easy on·me.
' {$STAMP BS2pe}
' {$PBASIC 2.5}
n1·· PIN 0
n2·· PIN 1
n3·· PIN 2
n4·· PIN 3
idx·· VAR· Byte
value· VAR· Byte
Main:
IF n1=1 THEN SUB1
GOTO main
SUB1:
WRITE 0, 1
GOTO main
Thanks,
Mike
Comments
If you want to keep the data permanently then you should write:
SUB1:
store 8········· '8 is a bank for EEPROM only
WRITE 0, 1
return
Then to read the data you would write:
store 8
read 0, variable
return
You will have to have a variable for every byte you store.· However, you can reuse the same variable if you "debug variable", because once you have debugged it you have the data.
Does this help?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Do you have a Stamp Tester yet?
http://hometown.aol.com/newzed/index.html
·
store 8
write dog, 1··· 'writes to address 0
write cat, 2··· 'writes to address 1
return
store 8
read cat, variable1··· 'reads address 1
read dog, variable2···'reads address 0
return
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Do you have a Stamp Tester yet?
http://hometown.aol.com/newzed/index.html
·
I'll complete as much of the code as i can and repost it for people to review if i still cant get it going.
Thanks again for the help, and if anyone else has suggestions please post them!!
Thanks,
Mike
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
here is my latest attempt to get this thing going.. obviously its not complete but im stuck.
Everytime this thing stores a number to memory the memory location has to increment.· How do i do that?· Can you provide me an example?·
And also to extract the information after, how do i do this as well?· I think there is a need for some kind of a loop to go through all the memory locations and print it out on the screen of the PC.
' {$STAMP BS2pe}
' {$PBASIC 2.5}
n1·· PIN 0
n2·· PIN 1
n3·· PIN 2
n4·· PIN 3
idx·· VAR· Byte
value· VAR· Byte
Main:
IF n1=1 THEN SUB1
IF n2=1 THEN SUB2
IF n3=1 THEN SUB3
If n4=1 THEN SUB4
STORE 8
READ 0, value
GOTO main
SUB1:
STORE 8
WRITE 0, 1
RETURN
SUB2
STORE 8
WRITE 1, 2
RETURN
SUB3
STORE 8
WRITE 2, 3
return
SUB4
STORE 8
WRITE 3, 4
return
' {$PBASIC 2.5}
n1 PIN 0
n2 PIN 1
n3 PIN 2
n4 PIN 3
idx VAR Byte
value VAR Byte
loc VAR word
Main:
debug "current location =",dec loc,cr
IF n1=1 THEN SUB1
IF n2=1 THEN SUB2
IF n3=1 THEN SUB3
If n4=1 THEN SUB4
STORE 8
READ 0, value
GOTO main
SUB1:
STORE 8
loc = loc +1
WRITE loc, 1
RETURN
SUB2
STORE 8
loc = loc+1
WRITE loc, 2
RETURN
SUB3
STORE 8
loc = loc+1
WRITE loc, 3
return
SUB4
STORE 8
loc = loc + 1
WRITE loc, 4
return
Keep in mind you will have to limit how far you write in the eeprom, eventually you will run out and have to switch banks.
Post Edited (Orion) : 11/22/2005 1:49:36 AM GMT
but the program seems to keep running... when i downloaded it the debug terminal just shows current location and keeps scrolling this down the page, and when i push a push button it starts counting.
Anymore suggestions from anyone.. as to how to slow it down, and store the numbers.
Keep the info coming, we've almost got this one nailed!
and thanks again for all the info!
change
debug "current location =",dec loc,cr
to
debug cls,"curent location =",dec loc
that will stop the scrolling.
·
2. but the program seems to keep running...
·
YEP, that’s what “GOTO main” will do
·
3. ….store the numbers
·
It is with the write command you just don’t have any code to read it back
·
4. we've almost got this one nailed
·
You have few more lines to go I’m thinking…
·
·
·
Post Edited (Orion) : 11/22/2005 2:32:14 AM GMT
as you can see in my if statement· IF n1= 1
The scrolling has stopped, but when i push any of the buttons it starts to count up
at an uncontrolled rate... just a quick bounce on the switch and you go from 1 to 5 instantly.
How can I slow that down and store one digit at a time.·
Then to read it back, I dont fully understand the READ command.
Forgive me i'm new with high level language and dont fully understand some of the concepts.· If this
was a 68HC11, and i could use assembler i'd have this done in no time.
I appriciate all the help, and I need alot more.· Please keep the suggestions coming.
Thanks
As far as debounce, i thought the software compensated for the bounce
Also, the RD_E2PROM subroutine uses a FOR... NEXT loop to read out the first four locations of the E2PROM
To debounce the switches, I would connect the positive side of a 1 microfarad electrolitic capacitor to the output of the switch and the negative side of the capacitor to ground. This should be done for all four switches.
Switch debouncing can be done by using the BUTTON command, but, for now, try to get the main idea of your program working first, then experiment with the BUTTON command.
Hope this helps,
Alan Balich
'{$STAMP BS2pe}
'{$PBASIC 2.5}
n1 PIN 0
n2 PIN 1
n3 PIN 2
n4 PIN 3
idx VAR Byte
value VAR Byte
loc VAR Byte
DO
GOSUB Chk_Inputs 'Check Inputs to see if any are high
DEBUG "E2PROM CONTENTS", CR
GOSUB Rd_E2PROM ' Reads the first 4 locations in the E2PROM
LOOP
Chk_Inputs:
IF (n1=1) THEN GOSUB SUB1
IF (n2=1) THEN GOSUB SUB2
IF (n3=1) THEN GOSUB SUB3
IF (n4=1) THEN GOSUB SUB4
RETURN
SUB1:
STORE 8
loc = loc +1
WRITE loc, 1
RETURN
SUB2:
STORE 8
loc = loc+1
WRITE loc, 2
RETURN
SUB3:
STORE 8
loc = loc+1
WRITE loc, 3
RETURN
SUB4:
STORE 8
loc = loc + 1
WRITE loc, 4
RETURN
Send_To_Display:
DEBUG "Location ", DEC idx, " = ", DEC value, CR
RETURN
Rd_E2PROM:
STORE 8
FOR idx = 0 TO 3
READ idx, value
GOSUB Send_To_Display
NEXT
RETURN
Post Edited (alinious) : 11/22/2005 5:13:04 PM GMT
There is a ton of examples of how to do this in the forums, its getting late for me
http://search.parallax.com
Here is a quick helper for reading
for idx = 0 to loc
read idx, value
debug "location ",dec idx, " = ",dec value,cr
next
You of course will have to figure out how your going to stop checking the inputs and switch over to downloading the data. I would recommend reading the "What is a microcontroller" text which is free to download from the parallax website. It will make your life much easier.
I was wondering how the RETURN without GOSUB was compiling??·
the code is working better now, except whenever i download it and go to the debug screen it prints out
E2PROM CONTENTS
LOCATION 0 = 1
LOCATION 1 = 1
LOCATION 2 = 1
LOCATION 3 = 1
Even though i disconnected the first pushbutton and tied it to grnd so it should·not read 1 at all.
Im going to start reading through that material you suggested, in the mean time if someone has anymore suggestions feel free to pass them my way.
Thanks again for the help,·I really appriciate it!
·'{$STAMP BS2pe}
'{$PBASIC 2.5}
n1 PIN 0
n2 PIN 1
n3 PIN 2
n4 PIN 3
idx·· VAR Byte
value VAR Byte
loc·· VAR Byte
DO
· GOSUB Chk_Inputs····· 'Check Inputs to see if any are high
· DEBUG HOME, "E2PROM CONTENTS", CR
· GOSUB Rd_E2PROM······ ' Reads the first 4 locations in the E2PROM
LOOP
Chk_Inputs:
· IF (n1=1) THEN GOSUB SUB1
· IF (n2=1) THEN GOSUB SUB2
· IF (n3=1) THEN GOSUB SUB3
· IF (n4=1) THEN GOSUB SUB4
RETURN
SUB1:
· STORE 8
· loc = loc +1
· WRITE loc, 1
RETURN
SUB2:
· STORE 8
· loc = loc+1
· WRITE loc, 2
RETURN
SUB3:
· STORE 8
· loc = loc+1
· WRITE loc, 3
RETURN
SUB4:
· STORE 8
· loc = loc + 1
· WRITE loc, 4
RETURN
Send_To_Display:
· DEBUG "Location ",DEC idx, " = ", DEC value, CR
RETURN
Rd_E2PROM:
· STORE 8
· FOR idx = 0 TO 3
··· READ idx, value
··· GOSUB Send_To_Display
· NEXT
RETURN
Instead of incrementing the address of the E2PROM address pointer, the addresses are set by the value stored in the LOC variable. Thus, in SUB1 the value 1 will be stored in address 0 of the E2PROM if N1 = 1. By using loc = loc + 1, the program is incrementing LOC based on the original valued stored in LOC. When the stamp is first turned on, LOC contains 0, therfore if n3 = 1, then LOC = 1 (based off of loc = loc + 1) which will be address 1 of the E2PROM. This is probably not where you wanted to store the value at in the E2PROM, but actually in address 3 of the E2PROM. This is why I changed the subroutines LOC variable to equal the exact address so that everytime each subroutine is executed, the E2PROM address corresponds correctly.
I have also updated the attachment to reflect the changes I noted below.
If you have any more questions or need any more explanations, I will gladly do so as soon as possible.
Alan Balich
SUB1:
STORE 8
loc = 0
WRITE loc, 1
RETURN
SUB2:
STORE 8
loc = 1
WRITE loc, 2
RETURN
SUB3:
STORE 8
loc = 2
WRITE loc, 3
RETURN
SUB4:
STORE 8
loc = 3
WRITE loc, 4
RETURN
Post Edited (alinious) : 11/22/2005 5:20:22 PM GMT