EXPERIMENT #10: A DIGITAL CLOCK
DAVID COOKE
Posts: 42
in BASIC Stamp
page 67 of the Stampworks manual Version 2.1
I wanted a stopwatch rather than a clock and I made a few changes to the code
my 4 digit display is a common anode and I changed (reversed) the code where I though that was required
I made some other changes
e.g.
'secs = secs + 1 // 3600 ' update current time
secs = secs + 1 // 6000 ' update current time changes to this line allows the clock to count to 99.99
the code works quite well but strangely segment 'c' does not illuminate for the numbers "0","1","7" on any of the 4 digits but it does illuminate for the numbers "3","4","5","6","8" and "9"
also segment 'g' does not illuminate for the number "2" on any of the 4 digits but it does illuminate for all of the other relevant numbers
any advice would be gratefully accepted
I attach the full code
I wanted a stopwatch rather than a clock and I made a few changes to the code
my 4 digit display is a common anode and I changed (reversed) the code where I though that was required
I made some other changes
e.g.
'secs = secs + 1 // 3600 ' update current time
secs = secs + 1 // 6000 ' update current time changes to this line allows the clock to count to 99.99
the code works quite well but strangely segment 'c' does not illuminate for the numbers "0","1","7" on any of the 4 digits but it does illuminate for the numbers "3","4","5","6","8" and "9"
also segment 'g' does not illuminate for the number "2" on any of the 4 digits but it does illuminate for all of the other relevant numbers
any advice would be gratefully accepted
I attach the full code
' {$STAMP BS2} ' {$PBASIC 2.5} ' -----[ Program Description ]--------------------------------------------- ' ' This program takes an external 1 Hz signal from a pulse generator 555 and ' synthesizes a simple clock/timer. This code will run, unmodified, on any ' BS2-family module. ' -----[ I/O Definitions ]------------------------------------------------- Segs VAR OUTL ' Segments on P0 - P7 Digs VAR OUTC ' Digit control pins DP PIN 7 Tic PIN 15 ' 1 Hz input ' -----[ Constants ]------------------------------------------------------- Blank CON %11111111 ' all segments off IsHigh CON 0 IsLow CON 1 ' -----[ Variables ]------------------------------------------------------- nTic VAR Bit ' new tic input oTic VAR Bit ' old tic value xTic VAR Bit ' change (1 when 0 -> 1) secs VAR Word ' seconds time VAR Word ' formatted time theDig VAR Nib ' current display digit ' -----[ EEPROM Data ]----------------------------------------------------- ' .GFEDCBA ' -------- Digit0 DATA %11000000 ' digit patterns Digit1 DATA %11111001 Digit2 DATA %10100100 Digit3 DATA %10110000 Digit4 DATA %10011001 Digit5 DATA %10010010 Digit6 DATA %10000010 Digit7 DATA %11111000 Digit8 DATA %10000000 Digit9 DATA %10011000 DigSel DATA %0001 ' digit 0 active DATA %0010 ' digit 1 active DATA %0100 ' digit 2 active DATA %1000 ' digit 3 active ' -----[ Initialization ]-------------------------------------------------- Reset: Digs = %0000 ' all off DIRS = $0FFF ' make segs & digs outputs ' -----[ Program Code ]---------------------------------------------------- Main: DO WHILE (Tic = IsHigh) ' wait during high cycle GOSUB Show_Clock LOOP DO WHILE (Tic = IsLow) ' wait during low cycle GOSUB Show_Clock LOOP secs = secs + 1 // 6000 ' update current time changes to this line allows the clock to count to 99.99 GOTO Main ' -----[ Subroutines ]----------------------------------------------------- Show_Clock: time = (secs / 60) * 100 ' get mins, move to 100s time = time + (secs // 60) ' add seconds in 1s/10s Segs = Blank ' clear display this line stops strobing READ (DigSel + theDig), Digs ' select digit READ (Digit0 + (time DIG theDig)), Segs ' move digit pattern to segs theDig = theDig + 1 // 4 ' update digit pointer IF theDig = 3 THEN LOW DP 'illuminates the DP situated between digits 1 and 2 (stampworks notation) RETURN
Comments