error in code
Dr. Vetter
Posts: 34
hello all
I'm building a digital clock and can not find anything on someone elses project that could give me a sence of direction so I'm going solo again.
My problem is in my code I have written it gives me an error of variable MIN already defined but I can not see where. From what I read MIN is made to be a variable that will be assigned 0 at first and after the first count it will have 1 added to it and sent to my digital clock. Is the problem with the way I have my lookup table in the SELECTBCD subroutine? I have gone over the code several times and it looks correct to me but another pair of eyes will help my flaws.
' {$STAMP BS2}
' {$PBASIC 2.5}
'DECLARE VARIABLES
X VAR Nib
IDX VAR Byte
EN VAR Nib
EN1 CON 12
EN2 CON 13
EN3 CON 14
EN4 CON 15
LT CON 4
MIN VAR Nib
MIN1 VAR Nib
HR VAR Nib
HR1 VAR Nib
'INITALIZE
OUTH = %0000· 'Turn on 8 - 11
DIRH = %1111· 'Make 8 - 11 OUTPUTS
'LAMP TEST
Startup:
HIGH LT
PAUSE 2000
LOW LT
MAIN:
DO
DO
PAUSE 1000
X = (X + 1)
LOOP UNTIL X = 60
X = 0
MIN = (MIN + 1)
GOSUB RULES
GOSUB SELECTENABLE
GOSUB SELECTBCD
GOSUB SENDBCD
LOOP
RULES:
IF MIN = 10 THEN
MIN = 0
MIN1 = (MIN1 + 1)
IF MIN1 = 6 THEN
MIN1 = 0
HR = (HR + 1)
IF HR = 10 THEN
HR = 0
HR1 = (HR + 1)
IF HR1 = 3 THEN
HR1 = 0
RETURN
SELECTBCD:
FOR IDX = 0 TO 3
LOOKUP IDX, [noparse][[/noparse]MIN, MIN1, HR, HR1], DIG
NEXT
RETURN
SELECTENABLE:
FOR IDX = 0 TO 3
LOOKUP IDX, [noparse][[/noparse]EN1, EN2, EN3, EN4], EN
NEXT
RETURN
SENDBCD:
HIGH EN
OUTH = DIG
PAUSE 100
LOW EN
IDX = (IDX + 1 // 4) 'ADD 1 TO INDEX BUT ONLY TO 4
RETURN
I'm building a digital clock and can not find anything on someone elses project that could give me a sence of direction so I'm going solo again.
My problem is in my code I have written it gives me an error of variable MIN already defined but I can not see where. From what I read MIN is made to be a variable that will be assigned 0 at first and after the first count it will have 1 added to it and sent to my digital clock. Is the problem with the way I have my lookup table in the SELECTBCD subroutine? I have gone over the code several times and it looks correct to me but another pair of eyes will help my flaws.
' {$STAMP BS2}
' {$PBASIC 2.5}
'DECLARE VARIABLES
X VAR Nib
IDX VAR Byte
EN VAR Nib
EN1 CON 12
EN2 CON 13
EN3 CON 14
EN4 CON 15
LT CON 4
MIN VAR Nib
MIN1 VAR Nib
HR VAR Nib
HR1 VAR Nib
'INITALIZE
OUTH = %0000· 'Turn on 8 - 11
DIRH = %1111· 'Make 8 - 11 OUTPUTS
'LAMP TEST
Startup:
HIGH LT
PAUSE 2000
LOW LT
MAIN:
DO
DO
PAUSE 1000
X = (X + 1)
LOOP UNTIL X = 60
X = 0
MIN = (MIN + 1)
GOSUB RULES
GOSUB SELECTENABLE
GOSUB SELECTBCD
GOSUB SENDBCD
LOOP
RULES:
IF MIN = 10 THEN
MIN = 0
MIN1 = (MIN1 + 1)
IF MIN1 = 6 THEN
MIN1 = 0
HR = (HR + 1)
IF HR = 10 THEN
HR = 0
HR1 = (HR + 1)
IF HR1 = 3 THEN
HR1 = 0
RETURN
SELECTBCD:
FOR IDX = 0 TO 3
LOOKUP IDX, [noparse][[/noparse]MIN, MIN1, HR, HR1], DIG
NEXT
RETURN
SELECTENABLE:
FOR IDX = 0 TO 3
LOOKUP IDX, [noparse][[/noparse]EN1, EN2, EN3, EN4], EN
NEXT
RETURN
SENDBCD:
HIGH EN
OUTH = DIG
PAUSE 100
LOW EN
IDX = (IDX + 1 // 4) 'ADD 1 TO INDEX BUT ONLY TO 4
RETURN
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
· -- Carl, nn5i@arrl.net
Thank you So Much
Craig