Project:
4 digit access code (random numbers)
Correct guess produces 7 segment display of required digits for mechanical digilock
After solving a random number problem (previous post) my program is working fine apart from a problem with a GOSUB stack error if I make too many incorrect button presses.
QUESTION: Is there a way of reducing or resetting the GOSUB stack?
4 digit access code (random numbers)
Correct guess produces 7 segment display of required digits for mechanical digilock
After solving a random number problem (previous post) my program is working fine apart from a problem with a GOSUB stack error if I make too many incorrect button presses.
QUESTION: Is there a way of reducing or resetting the GOSUB stack?
Code:
;REVISION 3
;18M2+
table 0,(1,2,3,4) ;DIGITS TO RANDOMIZE
pause 500
random b0
b2=b0//4
readtable b2,b10;SET 1ST DIGIT
do random b0
b3=b0//4
loop while b3=b2
readtable b3,b11;SET 2ND DIGIT
do random b0
b4=b0//4
loop while b4=b3 or b4=b2
readtable b4,b12;SET 3RD DIGIT
do random b0
b5=b0//4
loop while b5=b4 or b5=b3 or b5=b2
readtable b5,b13;SET 4TH DIGIT
let b16=0 ;WHEN B16=4 GOTO WINNER ROUTINE
main:
pulsout b.6,10;SET 7 SEGMENT DISPLAY TO 00
if b10=1 then goSUB sw1: if b10=2 then goSUB sw2: if b10=3 then gOSUB sw3: if b10=4 then goSUB sw4
HIGH B.0
if b11=1 then goSUB sw1: if b11=2 then goSUB sw2: if b11=3 then goSUB sw3: if b11=4 then goSUB sw4
HIGH B.1
if b12=1 then goSUB sw1: if b12=2 then goSUB sw2: if b12=3 then goSUB sw3: if b12=4 then goSUB sw4
HIGH B.2
if b13=1 then goSUB sw1: if b13=2 then goSUB sw2: if b13=3 then goSUB sw3: if b13=4 then goSUB sw4
sw1:
if pinC.1 =1 then goto sound1
if pinC.0 =1 then goto fail
if pinC.7 =1 then goto fail
if pinC.6 =1 then goto fail
if pinC.2 =1 then goto fail
goto sw1
sw2:
if pinC.1 =1 then goto fail
if pinC.0 =1 then goto sound2
if pinC.7 =1 then goto fail
if pinC.6 =1 then goto fail
if pinC.2 =1 then goto fail
goto sw2
sw3:
if pinC.1 =1 then goto fail
if pinC.0 =1 then goto fail
if pinC.7 =1 then goto sound3
if pinC.6 =1 then goto fail
if pinC.2 =1 then goto fail
goto sw3
sw4:
if pinC.1 =1 then goto fail
if pinC.0 =1 then goto fail
if pinC.7 =1 then goto fail
if pinC.6 =1 then goto sound4
if pinC.2 =1 then goto fail
goto sw4
sound1:
sound B.4,(120,40)
let b16=b16+1
if b16=4 then goto winner
RETURN
sound2:
sound B.4,(120,40)
let b16=b16+1
if b16=4 then goto winner
RETURN
sound3:
sound B.4,(120,40)
let b16=b16+1
if b16=4 then goto winner
RETURN
sound4:
sound B.4,(120,40)
let b16=b16+1
if b16=4 then goto winner
RETURN
fail:
let b16=0 ; RESET WINNER COUNT
low B.0 ;
low B.1 ;LED's OFF
low B.2 ;
low B.3 ;
high B.7 ;RED FAIL LED ON
sound B.4,(75,20,50,40)
pause 300
low B.7 ;RED FAIL LED OFF
goto MAIN
winner:
low B.0 ;
low B.1 ;
low B.2 ;LED's OFF
low B.3 ;
low B.7 ;
for b2 = 1 to 5 ;
high B.0 ;
pause 50 ;
low B.0 ;
high B.1 ;
pause 50 ;
low B.1 ;
high B.2 ;
pause 50 ;
low B.2 ;
high B.3 ;LED's FLASH SEQUENCE
pause 50 ;
low B.3 ;
pause 50 ;
high B.2 ;
pause 50 ;
low B.2 ;
pause 50 ;
high B.1 ;
pause 50 ;
low B.1 ;
pause 50 ;
next b2 ;
pulsout B.6,10 ;SET 7 SEGMENT DISPLAY TO 00
for b3 = 1 to 76 ;SET NUMBER TO REQUIRED OUTPUT FOR 7 SEGMENT DISPLAYS
pulsout B.5,10 ;SEND NUMBER TO DISPLAY
RANDOM W0 ;
B9=W0//85+50 ;SET RANDOM SOUND AS 7 SEGMENT DISPLAY ADVANCES
sound B.4,(B9,7) ;
next b3
pause 500
GOTO MAIN ;TEST PURPOSES ONLY - REMOVE BEFORE FINALISING IC