we are still in a covid lockdown [no 5 i think ] hence i'm bored shitless and will do anything that takes my interest
yes the forum has the ability to eat % symbols
60 seconds is too long to wait while testingIf the switch is in the 60 second run position it runs for about 10 seconds - which I saw you had runtime = 10 so I changed that.
not on the simulator , works ok at all settingsIn the 120 second position it ends almost instantly. I noticed this would happen sometimes in my code too. 100 and less and it works each time. I don't know what this phenomena is.
if you want to be able to run code repeatedly then seconds and comp need to be reset to zero before a rerun
like this
Code:#CONFIG CONFIG OSC=INTIO1, FSCM=ON, IESO=ON, PWRT=OFF, BOR=ON, BORV=27, WDT=ON CONFIG WDTPS=512, MCLRE=ON, STVR=ON, LVP=OFF, DEBUG=OFF, CP0=OFF, CP1=OFF CONFIG CPB=OFF, CPD=OFF, WRT0=OFF, WRT1=OFF, WRTC=OFF, WRTB=OFF, WRTD=OFF CONFIG EBTR0=OFF, EBTR1=OFF, EBTRB=OFF #ENDCONFIG OSCCON = % 01110011 DEFINE OSC 8 DEFINE DEBUG_REG PORTA DEFINE DEBUG_BIT 0 DEFINE DEBUG_BAUD 9600 DEFINE DEBUG_MODE 0 pause 2000 Debug "Start",13 ,10 SSW var PortA.7 redport var PortB.5 blueport var PortB.7 greenport var PortB.6 enable1 var PortB.2 enable2 var PortB.3 runtime var word RunningFlag var BIT Startswitch var PortA.3 ended var bit Thousandths var word Seconds var word comp var bit adcon1=$7f TRISA = % 11111000 TRISB = % 00010011 PortB.5 = 0 PortB.2 = 0 T1CON=0 TMR1H=$B1 ;10mS TMR1L=$e7 lata.0=0 ;debug pause 1000 Debug 13 ,10 ,"ready",13 ,10 comp = 0 redport = 0 greenport = 0 blueport = 0 enable1 = 0 enable2 = 0 runningflag = 0 thousandths = 0 Seconds = 0 blueport = 1 'testing outputs pause 200 blueport = 0 greenport = 1 pause 200 greenport = 0 T1CON.0=0 On Interrupt goto Starttimer PIE1.0=1 ' Enable TMR1 Interrupts INTCON.6=1 ' Enable all unmasked Interrupts main: if (PortB&19) == 18 then runtime = 10 elseif (PortB&19) == 19 then runtime = 90 elseif (PortB&19) == 1 then runtime = 120 endif if SSW = 1 then redport = 1 pause 200 redport = 0 pause 200 goto main endif if SSW = 0 then redport = 1 comp=0 goto main1 endif goto main 'main code loop Enable main1: ' Debug "main1 loop ",dec runtime,13 ,10 if ssw = 1 then 'checks to see if lid is closed, if not, goto main 'go back to first loop and wait endif 'if lid is closed, continue on to next requirement if (SSW = 0 )and (startswitch = 1) then 'starts the first run of the timer if lid ' Debug "start",dec runtime,13 ,10 runningflag = 1 'and sets a flag to show timer is running T1CON.0=1 enable1 = 1 enable2 = 1 blueport = 1 comp = 0 while runningflag: wend enable1 = 0 enable2 = 0 greenport = 1 blueport = 0 comp = 1 redport = 0 endif if comp==1 then Debug "DUNN",dec runtime,13 ,10 WHILE SSW = 0 : wend greenport = 0 ENDIF goto main goto main1 end disable Starttimer: lata.1=1 T1CON.0=0 TMR1H=$B1+TMR1H ;10mS TMR1L=$e7 +TMR1L if STATUS.0 THEN TMR1H =TMR1H +1 PIR1.0=0 ' Reset TMR1's Interupt Flag T1CON.0=1 thousandths=thousandths+10 if thousandths>999 then thousandths=0 Seconds=Seconds+1 endif if (seconds = runtime) || (ssw = 1) then seconds = 0 runningflag = 0 T1CON.0=0 endif lata.1=0 Resume enable End




Bookmarks