stampworks question
I Have put together experiment #10, LED Clock Display. I need to modify the experiment to a stopwatch using pushbutton D0 and port 12 to begin the watch, and D7 and port 13 to stop watch.·What changes do I make to the program? I appreciate any help with this.
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
'·{$STAMP BS2}
' =========================================================================
' File:Experiment 10.BS2
' ' =========================================================================
' { I/O Pins }
segs··· VAR· OUTL······· ' segments
digSel·· VAR· OUTC········ ' digit select
tic······ VAR· IN15········· ' 1 Hz Pulse Generator input
'
' { constants }
DPoint······ CON· %10000000······· ' decimal point bit
'
' { variables }
secs···· VAR· Word······· ' seconds
time······ VAR· Word······· ' formatted time
digit······· VAR· Nib······· ' current display digit
'
' { DATA statements }
'············· .abcdefg
'·············
DecDig· DATA· %01111110····· ' 0
······· DATA· %00110000····· ' 1
······· DATA· %01101101····· ' 2
······· DATA· %01111001····· ' 3
······· DATA· %00110011····· ' 4
······· DATA· %01011011····· ' 5
······· DATA· %01011111····· ' 6
······· DATA· %01110000····· ' 7
······· DATA· %01111111····· ' 8
······· DATA· %01111011····· ' 9
'
' { initialization }
Initialize:
· DIRL = %11111111······· ' make segments outputs
· DIRC = %1111··········· ' make digit selects outputs
· digSel = %1111········· ' all digits off
'
Main:
· GOSUB ShowTime··········· ' show current digit
·· IF tic = 1 THEN IncSec····· ' new second?
· GOTO Main··················· ' do it again
IncSec:
· secs = (secs + 1) // 3600··· ' update seconds counter
Waiting:
· GOSUB ShowTime············· ' show current digit
·· IF tic = 0 THEN Main········ ' if last tic gone, go back
· ' additional code could go here
· GOTO Waiting········· ' do tic check again
· END
'
' { subroutines }
ShowTime:
· time = (secs / 60) * 100····· ' get minutes, put in hundreds
· time = time + (secs // 60)····· ' get seconds, put in 10s & 1s
· segs = %00000000················· ' blank display
· ' enable digit
· LOOKUP digit,[noparse][[/noparse]%1110,%1101,%1011,%0111],digSel
· READ (DecDig + (time DIG digit)),segs· ' put segment pattern in digit
· IF (digit <> 2) THEN SkipDP
· segs = segs + DPoint······· ' illuminate decimal point
SkipDP:
· PAUSE 1···················· ' show it
· digit = (digit + 1) // 4··· ' get next digit
· RETURN
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
Before Main, add this to start the clock:
RunCheck:
· IF (IN12 = 1) THEN RunCheck
Add a line at the top of Main to stop the clock:
Main:
· IF (IN13 = 0) THEN RunCheck
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
Thanks for the help!
running··· VAR··· Bit
...
RunCheck:
· IF (IN12 = 1) THEN RunCheck
· running = 1
Main:
· IF (IN13 = 0) THEN
··· running = 0
· ENDIF
· IF (running·= 0) THEN Waiting
After you stop the clock you will need to press reset before you can start it again.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
·Here is how the code is entered:
' {$STAMP BS2}
' =========================================================================
' File:Experiment 10.BS2
' Simulate a digital stopwatch using four, 7-segment LED displays
' =========================================================================
' { I/O Pins }
segs··· VAR· OUTL······· ' segments
digSel·· VAR· OUTC········ ' digit select
tic······ VAR· IN15········· ' 1 Hz Pulse Generator input
'
' { constants }
DPoint······ CON· %10000000······· ' decimal point bit
'
' { variables }
secs···· VAR· Word······· ' seconds
time······ VAR· Word······· ' formatted time
digit······· VAR· Nib······· ' current display digit
running······ VAR· Bit······· ' clock is running
'
' { DATA statements }
'················ ······· .abcdefg
'······················ ·
DecDig· DATA· %01111110····· ' 0
··········· DATA· %00110000····· ' 1
·········· ·DATA· %01101101····· ' 2
·········· ·DATA· %01111001····· ' 3
·········· ·DATA· %00110011····· ' 4
··········· DATA· %01011011····· ' 5
··········· DATA· %01011111····· ' 6
·········· ·DATA· %01110000····· ' 7
········ ·· DATA· %01111111····· ' 8
········· · DATA· %01111011····· ' 9
'
' { initialization }
Initialize:
· DIRL = %11111111······· ' make segments outputs
· DIRC = %1111··········· ' make digit selects outputs
· digSel = %1111········· ' all digits off
'
RunCheck:
· IF (IN12 = 1) THEN RunCheck···· ' start clock with D0
· running = 1···················· ' clock is running
Main:
· IF (IN13 = 0) THEN RunCheck····· ' stop clock with D7
· running = 0····················· ' clock is stopped
·ENDIF
· IF (running = 0) THEN waiting···· ' display elapsed time
· GOSUB ShowTime··········· ' show current digit
·· IF tic = 1 THEN IncSec····· ' new second?
· GOTO Main··················· ' do it again
IncSec:
· secs = (secs + 1) // 3600··· ' update seconds counter
Waiting:
· GOSUB ShowTime············· ' show current digit
·· IF tic = 0 THEN Main········ ' if last tic gone, go back
· ' additional code could go here
· GOTO Waiting········· ' do tic check again
· END
'
' { subroutines }
ShowTime:
· time = (secs / 60) * 100····· ' get minutes, put in hundreds
· time = time + (secs // 60)····· ' get seconds, put in 10s & 1s
· segs = %00000000················· ' blank display
· ' enable digit
· LOOKUP digit,[noparse][[/noparse]%1110,%1101,%1011,%0111],digSel
· READ (DecDig + (time DIG digit)),segs· ' put segment pattern in digit
· IF (digit <> 2) THEN SkipDP
· segs = segs + DPoint······· ' illuminate decimal point
SkipDP:
· PAUSE 1···················· ' show it
· digit = (digit + 1) // 4··· ' get next digit
· RETURN
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office