Solutions Cubed Pocket Watch B for BS2 program updating help
Migs
Posts: 95
Friends:
I'm trying to update the following code (written in 1997) to run on a Basic Stamp 2 on the Board of Education breadboard. The code, as is, works, but there are commands within it that need to be modernized. For example: The code contains the "Begin:" construct, and I find no reference to this in the Basic Stamp Syntax and Reference Manual. What things do I change? (exampe: Main: instead of Begin[noparse]:)[/noparse]
Also, I'm having trouble understanding where the main program is and which are the subroutines.
Thanks for your help amigos,-Migs
'PocketWatchB-1
'Based on AN-151 Basic Stamp 2 interface to Pocket Watch B
'by Solutions Cubed
'http://www.solutions-cubed.com/solutions cubed/PWB2003.htm
'07/97
'================================================================================================
'Define Basic Stamp II and Basic type:
'{$STAMP BS2}
'{$PBASIC 2.5}
'================================================================================================
'Set I/O pin directions
input 15 'communication FROM Pocket Watch
output 14 'communication TO Pocket Watch
input 13 'ALARM monitoring pin
'================================================================================================
'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: 'set to 6:30:00AM, June 3, 1997
SEROUT 14,84,[noparse][[/noparse]$55,$00,$00,$1E,$06,$03,$06,$61]
SetAlarmCommand: 'set to 15 seconds after time
SEROUT 14,84,[noparse][[/noparse]$55,$01,$0F,$1E,$06,$03,$06,$61]
ReadAlarmCommand: 'see what time alarm set to go off
SEROUT 14,84,[noparse][[/noparse]$55,$03]
SERIN 15,84,5000,BadAlarm1,[noparse][[/noparse]ss,mm,hh,dd,mo,yl]
DEBUG "Alarm: ",dec2 hh,":",dec2 mm,":",dec2 ss," ",dec2 mo,"/",dec2 dd,"/19",dec2 yl, cr
AlarmOnCommand: 'enable alarm
SEROUT 14,84,[noparse][[/noparse]$55,$04]
Loop1:
PAUSE 2000 'wait 2 seconds between reads
ReadTimeCommand: 'see what time it is presently
SEROUT 14,188,[noparse][[/noparse]$55,$02]
SERIN 15,188,5000,BadLoop1,[noparse][[/noparse]ss,mm,hh,dd,mo,yl]
DEBUG "Time: ",dec2 hh,":",dec2 mm,":",dec2 ss," ",dec2 mo,"/",dec2 dd,"/19",dec2 yl, cr
CheckALARM: 'see if ALARM is high
IF IN13=1 THEN AlarmOff1 'if ALARM not high read time
GOTO LOOP1
AlarmOff1:
DEBUG "Regular Alarm On",CR
PAUSE 5000 'allow alarm to stay of for 5 sec
AlarmOffCommand: 'turn off alarm
SEROUT 14,188,[noparse][[/noparse]$55,$05]
DEBUG "Regular Alarm Off",CR,CR
SetTimeExtended: 'set time to 9:45:00PM, November 16, 2001
SEROUT 14,396,[noparse][[/noparse]$55,$10,$00,$2D,$15,$10,$0B,$01,$14]
SetAlarmExtended: 'set alarm for 15 seconds later
SEROUT 14,396,[noparse][[/noparse]$55,$11,$0F,$2D,$15,$10,$0B,$01,$14]
ReadAlarmExtended: 'see what time alarm is on
SEROUT 14,396,[noparse][[/noparse]$55,$13]
SERIN 15,396,5000,BadAlarm2,[noparse][[/noparse]ss,mm,hh,dd,mo,yl,yh]
DEBUG "Alarm: ",dec2 hh,":",dec2 mm,":",dec2 ss," ",dec2 mo,"/",dec2 dd,"/",dec2 yh,dec2 yl, cr
SetSingleShot: 'set singleshot --> 10 seconds
SEROUT 14,84,[noparse][[/noparse]$55,$16,$00,$09]
AlarmOnExtended1: 'enable alarm
SEROUT 14,84,[noparse][[/noparse]$55,$14]
ReadAlChar1: 'get alarm characteristics
SEROUT 14,84,[noparse][[/noparse]$55,$19]
SERIN 15,84,5000,BadAlarm3,[noparse][[/noparse]b10,b11,b12,ss,mm,hh,dd,mo,yl,yh]
DEBUG "Alarm type: ",dec2 b10,cr,"Byte 1: ",dec2 b11,cr,"Byte 2: ",dec2 b12,cr
DEBUG "Alarm: ",dec2 hh,":",dec2 mm,":",dec2 ss," ",dec2 mo,"/",dec2 dd,"/",dec2 yh,dec2 yl, cr
Loop2:
PAUSE 2000 'wait 2 seconds between reads
ReadTimeEx1: 'read extendted time
SEROUT 14,396,[noparse][[/noparse]$55,$12]
SERIN 15,396,5000,BadReadex1,[noparse][[/noparse]ss,mm,hh,dd,mo,yl,yh]
DEBUG "Time: ",dec2 hh,":",dec2 mm,":",dec2 ss," ",dec2 mo,"/",dec2 dd,"/",dec2 yh,dec2 yl, cr
CheckSingleShot1: 'see if single shot started
IF IN13=1 THEN CheckSingleShot2 'if single shot not started read time
GOTO LOOP2
CheckSingleShot2:
DEBUG "Single Shot Started",CR
Loop3:
IF IN13=0 THEN CheckSingleShot3 'see if single shot over
GOTO Loop3
CheckSingleShot3:
DEBUG "Single Shot Done",CR,CR
SetShortAsable: '15 seconds every 1 minute
SEROUT 14,84,[noparse][[/noparse]$55,$17,$00,$0E]
SetAlarmEx2:
SEROUT 14,84,[noparse][[/noparse]$55,$11,$00,$2E,$15,$0B,$10,$01,$14]
AlarmOnEx2: 'turn on short astable
SEROUT 14,188,[noparse][[/noparse]$55,$14]
ReadAlChar2: 'get alarm characteristics
SEROUT 14,84,[noparse][[/noparse]$55,$19]
SERIN 15,84,5000,BadAlarm3,[noparse][[/noparse]b10,b11,b12,ss,mm,hh,dd,mo,yl,yh]
DEBUG "Alarm type: ",dec2 b10,cr,"Byte 1: ",dec2 b11,cr,"Byte 2: ",dec2 b12,cr
DEBUG "Alarm: ",dec2 hh,":",dec2 mm,":",dec2 ss," ",dec2 mo,"/",dec2 dd,"/",dec2 yh,dec2 yl, cr
ReadTimeEx2: 'read extendted time
PAUSE 10000 'wait 10 seconds between reads
SEROUT 14,396,[noparse][[/noparse]$55,$12]
SERIN 15,396,5000,BadReadex2,[noparse][[/noparse]ss,mm,hh,dd,mo,yl,yh]
DEBUG "Time: ",dec2 hh,":",dec2 mm,":",dec2 ss," ",dec2 mo,"/",dec2 dd,"/",dec2 yh,dec2 yl, cr
CheckAstable1: 'see if astable started
IF IN13=1 THEN CheckAstable2 'if single shot not started read time
GOTO ReadTimeEx2
CheckAstable2:
DEBUG CR,"Short Astable Started -- Waiting 5 minutes",CR
PAUSE 60000 'wait 5 minutes
PAUSE 60000 'wait 5 minutes
PAUSE 60000 'wait 5 minutes
PAUSE 60000 'wait 5 minutes
PAUSE 60000 'wait 5 minutes
AlarmOffEx:
SEROUT 14,396,[noparse][[/noparse]$55,$15]
Done:
DEBUG CR,CR,"Done with AN-501"
DoneLoop:
GOTO DoneLoop
'================================================================================================
'Bad Communication Vectors
BadAlarm1:
DEBUG "Alarm read 1 bad",CR
GOTO ReadAlarmCommand
BadAlarm2:
DEBUG "Alarm read 2 bad",CR
GOTO ReadAlarmExtended
BadAlarm3:
DEBUG "Alarm read 3 bad",CR
GOTO ReadAlChar1
BadLoop1:
DEBUG "Loop1 error", CR
GOTO Loop1
BadReadEx1:
DEBUG "Read extended 1 bad",CR
GOTO ReadTimeEx1
BadReadEx2:
DEBUG "Read extended 2 bad",CR
GOTO ReadTimeEx2
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"Sometimes we forget that the world itself is paradise." Douglas Coupland, 'Microserfs'
"If the doors of perception were cleansed every thing would appear to man as it is, infinite" - William Blake
"We either make ourselves miserable, or we make ourselves strong. The amount of work is the same." Carlos Castaneda
"One single grateful thought raised to heaven is the most perfect prayer. " G. E. Lessing
“How much of human life is lost in waiting.” Ralph Waldo Emerson
"Men often mistake notoriety for fame, and would rather be remembered for their vices and follies than not be noticed at all.” Harry Truman
My website: www.intoku.net my e-mail:mreznicek@pretensa.com me:Miguel Reznicek
I'm trying to update the following code (written in 1997) to run on a Basic Stamp 2 on the Board of Education breadboard. The code, as is, works, but there are commands within it that need to be modernized. For example: The code contains the "Begin:" construct, and I find no reference to this in the Basic Stamp Syntax and Reference Manual. What things do I change? (exampe: Main: instead of Begin[noparse]:)[/noparse]
Also, I'm having trouble understanding where the main program is and which are the subroutines.
Thanks for your help amigos,-Migs
'PocketWatchB-1
'Based on AN-151 Basic Stamp 2 interface to Pocket Watch B
'by Solutions Cubed
'http://www.solutions-cubed.com/solutions cubed/PWB2003.htm
'07/97
'================================================================================================
'Define Basic Stamp II and Basic type:
'{$STAMP BS2}
'{$PBASIC 2.5}
'================================================================================================
'Set I/O pin directions
input 15 'communication FROM Pocket Watch
output 14 'communication TO Pocket Watch
input 13 'ALARM monitoring pin
'================================================================================================
'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: 'set to 6:30:00AM, June 3, 1997
SEROUT 14,84,[noparse][[/noparse]$55,$00,$00,$1E,$06,$03,$06,$61]
SetAlarmCommand: 'set to 15 seconds after time
SEROUT 14,84,[noparse][[/noparse]$55,$01,$0F,$1E,$06,$03,$06,$61]
ReadAlarmCommand: 'see what time alarm set to go off
SEROUT 14,84,[noparse][[/noparse]$55,$03]
SERIN 15,84,5000,BadAlarm1,[noparse][[/noparse]ss,mm,hh,dd,mo,yl]
DEBUG "Alarm: ",dec2 hh,":",dec2 mm,":",dec2 ss," ",dec2 mo,"/",dec2 dd,"/19",dec2 yl, cr
AlarmOnCommand: 'enable alarm
SEROUT 14,84,[noparse][[/noparse]$55,$04]
Loop1:
PAUSE 2000 'wait 2 seconds between reads
ReadTimeCommand: 'see what time it is presently
SEROUT 14,188,[noparse][[/noparse]$55,$02]
SERIN 15,188,5000,BadLoop1,[noparse][[/noparse]ss,mm,hh,dd,mo,yl]
DEBUG "Time: ",dec2 hh,":",dec2 mm,":",dec2 ss," ",dec2 mo,"/",dec2 dd,"/19",dec2 yl, cr
CheckALARM: 'see if ALARM is high
IF IN13=1 THEN AlarmOff1 'if ALARM not high read time
GOTO LOOP1
AlarmOff1:
DEBUG "Regular Alarm On",CR
PAUSE 5000 'allow alarm to stay of for 5 sec
AlarmOffCommand: 'turn off alarm
SEROUT 14,188,[noparse][[/noparse]$55,$05]
DEBUG "Regular Alarm Off",CR,CR
SetTimeExtended: 'set time to 9:45:00PM, November 16, 2001
SEROUT 14,396,[noparse][[/noparse]$55,$10,$00,$2D,$15,$10,$0B,$01,$14]
SetAlarmExtended: 'set alarm for 15 seconds later
SEROUT 14,396,[noparse][[/noparse]$55,$11,$0F,$2D,$15,$10,$0B,$01,$14]
ReadAlarmExtended: 'see what time alarm is on
SEROUT 14,396,[noparse][[/noparse]$55,$13]
SERIN 15,396,5000,BadAlarm2,[noparse][[/noparse]ss,mm,hh,dd,mo,yl,yh]
DEBUG "Alarm: ",dec2 hh,":",dec2 mm,":",dec2 ss," ",dec2 mo,"/",dec2 dd,"/",dec2 yh,dec2 yl, cr
SetSingleShot: 'set singleshot --> 10 seconds
SEROUT 14,84,[noparse][[/noparse]$55,$16,$00,$09]
AlarmOnExtended1: 'enable alarm
SEROUT 14,84,[noparse][[/noparse]$55,$14]
ReadAlChar1: 'get alarm characteristics
SEROUT 14,84,[noparse][[/noparse]$55,$19]
SERIN 15,84,5000,BadAlarm3,[noparse][[/noparse]b10,b11,b12,ss,mm,hh,dd,mo,yl,yh]
DEBUG "Alarm type: ",dec2 b10,cr,"Byte 1: ",dec2 b11,cr,"Byte 2: ",dec2 b12,cr
DEBUG "Alarm: ",dec2 hh,":",dec2 mm,":",dec2 ss," ",dec2 mo,"/",dec2 dd,"/",dec2 yh,dec2 yl, cr
Loop2:
PAUSE 2000 'wait 2 seconds between reads
ReadTimeEx1: 'read extendted time
SEROUT 14,396,[noparse][[/noparse]$55,$12]
SERIN 15,396,5000,BadReadex1,[noparse][[/noparse]ss,mm,hh,dd,mo,yl,yh]
DEBUG "Time: ",dec2 hh,":",dec2 mm,":",dec2 ss," ",dec2 mo,"/",dec2 dd,"/",dec2 yh,dec2 yl, cr
CheckSingleShot1: 'see if single shot started
IF IN13=1 THEN CheckSingleShot2 'if single shot not started read time
GOTO LOOP2
CheckSingleShot2:
DEBUG "Single Shot Started",CR
Loop3:
IF IN13=0 THEN CheckSingleShot3 'see if single shot over
GOTO Loop3
CheckSingleShot3:
DEBUG "Single Shot Done",CR,CR
SetShortAsable: '15 seconds every 1 minute
SEROUT 14,84,[noparse][[/noparse]$55,$17,$00,$0E]
SetAlarmEx2:
SEROUT 14,84,[noparse][[/noparse]$55,$11,$00,$2E,$15,$0B,$10,$01,$14]
AlarmOnEx2: 'turn on short astable
SEROUT 14,188,[noparse][[/noparse]$55,$14]
ReadAlChar2: 'get alarm characteristics
SEROUT 14,84,[noparse][[/noparse]$55,$19]
SERIN 15,84,5000,BadAlarm3,[noparse][[/noparse]b10,b11,b12,ss,mm,hh,dd,mo,yl,yh]
DEBUG "Alarm type: ",dec2 b10,cr,"Byte 1: ",dec2 b11,cr,"Byte 2: ",dec2 b12,cr
DEBUG "Alarm: ",dec2 hh,":",dec2 mm,":",dec2 ss," ",dec2 mo,"/",dec2 dd,"/",dec2 yh,dec2 yl, cr
ReadTimeEx2: 'read extendted time
PAUSE 10000 'wait 10 seconds between reads
SEROUT 14,396,[noparse][[/noparse]$55,$12]
SERIN 15,396,5000,BadReadex2,[noparse][[/noparse]ss,mm,hh,dd,mo,yl,yh]
DEBUG "Time: ",dec2 hh,":",dec2 mm,":",dec2 ss," ",dec2 mo,"/",dec2 dd,"/",dec2 yh,dec2 yl, cr
CheckAstable1: 'see if astable started
IF IN13=1 THEN CheckAstable2 'if single shot not started read time
GOTO ReadTimeEx2
CheckAstable2:
DEBUG CR,"Short Astable Started -- Waiting 5 minutes",CR
PAUSE 60000 'wait 5 minutes
PAUSE 60000 'wait 5 minutes
PAUSE 60000 'wait 5 minutes
PAUSE 60000 'wait 5 minutes
PAUSE 60000 'wait 5 minutes
AlarmOffEx:
SEROUT 14,396,[noparse][[/noparse]$55,$15]
Done:
DEBUG CR,CR,"Done with AN-501"
DoneLoop:
GOTO DoneLoop
'================================================================================================
'Bad Communication Vectors
BadAlarm1:
DEBUG "Alarm read 1 bad",CR
GOTO ReadAlarmCommand
BadAlarm2:
DEBUG "Alarm read 2 bad",CR
GOTO ReadAlarmExtended
BadAlarm3:
DEBUG "Alarm read 3 bad",CR
GOTO ReadAlChar1
BadLoop1:
DEBUG "Loop1 error", CR
GOTO Loop1
BadReadEx1:
DEBUG "Read extended 1 bad",CR
GOTO ReadTimeEx1
BadReadEx2:
DEBUG "Read extended 2 bad",CR
GOTO ReadTimeEx2
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"Sometimes we forget that the world itself is paradise." Douglas Coupland, 'Microserfs'
"If the doors of perception were cleansed every thing would appear to man as it is, infinite" - William Blake
"We either make ourselves miserable, or we make ourselves strong. The amount of work is the same." Carlos Castaneda
"One single grateful thought raised to heaven is the most perfect prayer. " G. E. Lessing
“How much of human life is lost in waiting.” Ralph Waldo Emerson
"Men often mistake notoriety for fame, and would rather be remembered for their vices and follies than not be noticed at all.” Harry Truman
My website: www.intoku.net my e-mail:mreznicek@pretensa.com me:Miguel Reznicek
Comments
Begin: is simply a label. As such it could say, “Main:” or “Start:” or anything. There’s no way to update a label as it really never gets obsolete unless labels are not supported altogether. Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
What may be confusing is that some "syntactic sugar" was added to PBASIC in the form of DO / LOOP, CASE, and IF / THEN / ELSE statements (and others). This is enabled by using the { $PBasic 2.5 } directive. The program you've shown doesn't use these forms and the older "IF <expression> THEN <label>" format may look odd. There's a writeup showing the changes from version 2.0 to version 2.5 here: www.parallax.com/dl/sw/bs/win/PBASICCompiler2_0Beta2.pdf.
The changes document will help a bit. I have been tinkering this morning and (think I) understand the program well enough now to rewrite it.
Thanks for your comments amigos! -Migs
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"Sometimes we forget that the world itself is paradise." Douglas Coupland, 'Microserfs'
"If the doors of perception were cleansed every thing would appear to man as it is, infinite" - William Blake
"We either make ourselves miserable, or we make ourselves strong. The amount of work is the same." Carlos Castaneda
"One single grateful thought raised to heaven is the most perfect prayer. " G. E. Lessing
“How much of human life is lost in waiting.” Ralph Waldo Emerson
"Men often mistake notoriety for fame, and would rather be remembered for their vices and follies than not be noticed at all.” Harry Truman
My website: www.intoku.net my e-mail:mreznicek@pretensa.com me:Miguel Reznicek