Hi, For some reason the following code will fall out of the startsc loop. When I remove
then all is good. I replace the 20M2 and still the same. I put a 20x2 in its place and all is good and the program will keep looping. I change pinB.1 to pinB.2 and all is good. There is no high on this pin.
Thanks
Code:
pinB.1 = 1
Thanks
Code:
'====================================================================================================================
'==========================================START OF PROGRAM 2========================================================
start:
' PICAXE-20M2
' Shotclk.bas
' Count down a given number to zero on a two digit 7-segment display
' using a 74HC595 Shift Register.
' pin 11 SH_CP Shift register clock input
' pin 12 ST_CP Storage register clock input
' pin 14 DS Serial data input
'
' pin 11 - C.2 SH-CP (20M2 pin 8)
' pin 12 - C.1 ST_CP (20M2 pin 9)
' pin 14 - C.0 DS (20M2 pin 10)
'
;DS = C.0 pin 10 Picaxe / Serial data input pin 14 595
;STCP = C.1 pin 9 Picaxe / Storage register pin 12 595
;SHCP = C.2 pin 8 Picaxe / Shift register pin 11 595
;General Purpose Bytes Used
;b0, b1, b3, b4, b5, b6, b20
'Pin 18 - B.0 - resetgc
'Pin 17 - B.1 - startsc
'Pin 6 - C.4 - siren
'Pin 5 - C.5 - startsc
'Pin 4 - C.6 - pausesc
'Pin 3 - C.7 - resetsc
#picaxe 20M2
symbol dataout = C.0
symbol clk = C.2
symbol latchout = C.1
symbol out = b7
symbol loop1 = b8
symbol loop2 = b9
symbol outbyte2 = b3
symbol status = b10
'pullup on
'pullup %00011111 'pull up on B.0 B.1 B.2 B.3
'let pinsB = %11111111 ; switch on outputs 0 and 1
startsc:
outbyte2 = %00111111 'Send 0 to units Segment
gosub out595 'send this b5 value to register, DS
outbyte2 = %01001111 'Send 3 to Tens Segment
gosub out595
pulsout latchout,1 'Display 2 new digits once both are loaded into their 595s
if pinC.5 = 1 or pinB.1 = 1then 'if startsc or startgc button then goto to countdown
goto main
endif
goto startsc 'loop until it is.
debug
main:
'------------------------------------------------ count down from 29 to 20 ------------------------------------------------
for b8 = 0 to 9
gosub loop_1sec 'call up 1 second delay with button watch loop
lookup b8,(%01100111, %01111111, %00000111, %01111100, %01101101, %01100110, %01001111, %01011011, %00000110, %00111111),outbyte2 'tens segment turn on 9
gosub out595
outbyte2 = %01011011 'Send 2 to tens segment
gosub out595
pulsout latchout,1
next b8
'------------------------------------------------ count down from 19 to 10 ------------------------------------------------
for b4 = 0 to 9
gosub loop_1sec 'call up 1 second delay with button watch loop
lookup b4,(%01100111, %01111111, %00000111, %01111100, %01101101, %01100110, %01001111, %01011011, %00000110, %00111111),outbyte2 'tens segment turn on 9
gosub out595
outbyte2 = %00000110 'Send 1 to tens segment
gosub out595
pulsout latchout,1
next b4
'------------------------------------------------ count down from 9 to 00 ------------------------------------------------
for b5 = 0 to 9
gosub loop_1sec 'call up 1 second delay with button watch loop
lookup b5,(%01100111, %01111111, %00000111, %01111100, %01101101, %01100110, %01001111, %01011011, %00000110, %00111111),outbyte2 'tens segment turn on 9
gosub out595
outbyte2 = %00000000 'blank tens segment
gosub out595
pulsout latchout,1
next b5
'--------------------------------------------- Flash digits and Siren ---------------------------------------------
for b6 = 1 to 2 '2 cycle loop for buzzer
outbyte2 = %00111111 'Send 0 to units Segment
gosub out595 'send this b5 value to register, DS
outbyte2 = %00111111 'Send 0 to Tens Segment
gosub out595
pulsout latchout,1 'Display 2 new digits once both are loaded into their 595s
High C.3 'high to buzzer and light
pause 300 'slight pause between siren
outbyte2 = %00000000 'blank units Segment
gosub out595 'send this b5 value to register, DS
outbyte2 = %00000000 'blank Tens Segment
gosub out595
pulsout latchout,1 'Display "00" once both are loaded into their 595s
low C.3
pause 300
next b6
goto startsc 'go back to start of count
'--------------------------------------------- THE END -----------------------------------------------------
'
' **** Subroutines ****
'
out595:
b0 = %10000000 'We want to look at the left most bit(MSB) first
for b1 = 0 to 7 'loop 8 times to get all bits
b2 = outbyte2 & b0 'Look at the MSB
if b2 = b0 then 'if the MSB is high output high
high dataout
else
low dataout 'else if the MSB is low output low
endif
pulsout clk, 1 'pulse the clock line to move the output bit into the register
b0 = b0 /2 'clock the next bit out
next b1
return
loop_1sec:
for w1 = 1 to 112 ' 112 seems to take 1 second
gosub buttonck
next w1
return
buttonck:
if pinC.6 = 1 then 'if pausesc button then goto to pause
goto pausesc
endif
if pinC.7 = 1 OR pinB.0 = 1 then 'if resetsc button pressed restart countdown
goto startsc
endif
return
pausesc:
pause 10
if pinC.5 = 1 then 'if pausesc button then resume to countdown
return
endif
if pinC.7 = 1 OR pinB.0 = 1 then 'if resetsc button pressed then go back to start
goto startsc
endif
goto pausesc
end