BS2p40 as a Time Stamp Recorder
danilo
Posts: 7
Im using·a BS2p40 along with·the POCKET WATCH B. I currently have it displaying the time a date to an LCD. I plan to use it to create a time stamp when a ceratin sensor is trigger.
I want to
A] store the date and time info in the eeprom and
B] be able to recall it with the push of a button later and display back to the LCD.
My priority is the storage to the eeprom at this point.
Can help with either A] or B]?
Thanks in advance.
·
I want to
A] store the date and time info in the eeprom and
B] be able to recall it with the push of a button later and display back to the LCD.
My priority is the storage to the eeprom at this point.
Can help with either A] or B]?
Thanks in advance.
·
Comments
·
·· What specifically do you need help with?· How many variables are you storing for each write?· Are you storing any other information, such as sensor information?· If so, how is that data formatted?· How many bytes is it?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
I do not need any other information stored and recalled just the time and date.
Pocket Watch B code:
' {$STAMP BS2p}
' {$PBASIC 2.5}
'AN-151 BSII interface to Pocket Watch B
'by Solutions Cubed
'07/97
'Set I/O pin directions
INPUT 15 'communication FROM Pocket Watch B
OUTPUT 14 'communication TO Pocket Watch B
'Declare variables
ss VAR Byte 'seconds
mm VAR Byte 'minutes
hh VAR Byte 'hours
dd VAR Byte 'days
mo VAR Byte 'months
yl VAR Byte 'years low
yh VAR Byte 'years high
Begin:
HIGH 14 'ensure no spurious start bit
PAUSE 1000
SetTimeCommand:
SEROUT 14,240,[noparse][[/noparse]$55,$00,$32,$3b,$d,$d,$A,$06]
ReadTimeCommand: 'see what time it is presently
SEROUT 14,240,[noparse][[/noparse]$55,$12]
SERIN 15,240, [noparse][[/noparse]ss,mm,hh,dd,mo,yl,yh]
SEROUT 15,240, [noparse][[/noparse]$12,$16,$0c, "Time: ",DEC2 hh,":",DEC2 mm,":",DEC2 ss,13,"Date:",DEC2 mo,"/",DEC2 dd,"/20",DEC2 yl, CR]
PAUSE 1000
GOTO ReadTimeCommand
·
·· I would suggest deciding what information you need to store before you get too far into it.· You posted the code, but you didn’t say which information you wanted to store.· From your code you could store years, months, days, hours, minutes, seconds, etc.· Often only two or three of these are needed, but without knowing which information you need, you can’t really plan your code accordingly.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
·
·
·· Okay, so you don’t need to store anything else, such as sensor data/states.· Okay, well then you simply set an index variable to the start of EEPROM (typically 0 if you have no DATA statements or other information there), then you use WRITE to store each variable, incrementing the index variable by 1 each time you do a WRITE.· When the next event happens you will be at the next location.· If you start at zero, and you know how many bytes are written each time (in this case it looks like 6 bytes) then when you read the data back you will grab six bytes into those variables by doing things in reverse order using READ.· I hope this helps.· Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
Thank you. I've quickly tinkered with some code and it is storing the values to the specific location on the EEPROM that i want. Right now its storing and displaying on the debug every second.
POCKET 2
' {$STAMP BS2p}
' {$PBASIC 2.5}
'Pocket watch will displayed the LCD and the
'YEAR (yl), MONTH(mo), DAY(dd), HOUR(hh), MIN(mm), and SEC(ss)
'values will be stored in the EEPROM in locations
'0 to 5
'07/97
'Set I/O pin directions
INPUT 15······················· 'communication FROM Pocket Watch B Tm pin on pocket
OUTPUT 14······················ 'communication TO Pocket Watch B Fm pin on pocket
'Declare variables
ss VAR Byte···················· 'seconds
mm VAR Byte···················· 'minutes
hh VAR Byte···················· 'hours
dd VAR Byte···················· 'days
mo VAR Byte···················· 'months
yl VAR Byte···················· 'years low
yh VAR Byte···················· 'years high
idx············ VAR···· Byte··········· ' loop control
value·········· VAR···· Byte········ ' value(s)
Begin:
HIGH 14························ 'ensure no spurious start bit
PAUSE 1000
SetTimeCommand:················ 'set TO 6:30:00AM, June 3, 1997
SEROUT 14,240,[noparse][[/noparse]$55,$00,$32,$3b,$d,$d,$A,$06]
ReadTimeCommand: 'see what time it is presently
SEROUT 14,240,[noparse][[/noparse]$55,$12]
SERIN 15,240, [noparse][[/noparse]ss,mm,hh,dd,mo,yl,yh]
SEROUT 15,240, [noparse][[/noparse]$12,$16,$0c, "Time: ",DEC2 hh,":",DEC2 mm,":",DEC2 ss,13,"Date:",DEC2 mo,"/",DEC2 dd,"/20",DEC2 yl, CR]
PAUSE 1000
GOSUB eeprom
eeprom:
· WRITE 0,yl·' single byte for year low
· WRITE 1,mo·' single byte for month
· WRITE 2,dd··· ' single byte for day
· WRITE 3,hh·' single byte for hour
· WRITE 4,mm·' single byte for minutes
· WRITE 5,ss·' single byte for seconds
Read_EE:
· FOR idx = 0 TO 5····················· ' show raw bytes in EE
··· READ idx, value
··· DEBUG DEC1 idx, " : ", DEC value, CR·'diplay location and pocket
· NEXT······'watch values
· DEBUG CR
GOTO ReadTimeCommand
· ' read values as stored
·
·· You’ve got the right idea.· Currently you’re hard-coding the values.· This is okay for testing, but in the end you’ll want to do things a bit different…You’re writing to the same locations now, but presumably you’ll want to store multiple samples later.· One way to do this might be:
You would call the subroutine when you wanted to write the data and each time it would write the 6 bytes at the current location and then increment the index by 6.· I noticed in your example you are using GOSUB to call a routine for which there is no RETURN.· You didn't need the GOSUB since your code would fall right through anyway.· I hope this helps.· Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support