; Fire22 ; Adding 10 minute preheat option ; Using port B pullups ; ;Gas Fireplace timer ;Jeff Thorssell Ocean Pines, MD - 2009 INCLUDE P16F84A.INC RADIX DEC FiveMSec equ D'100' ;timer delay for 5 ms OneSecTime equ D'200' ;5 ms cycles to get one second LEDOff equ 4 ;cycles for the ONLED to remain off MainCycles equ D'150' ;150 second cycles PORT_A equ 5 ;individual bits on PORT_A ONLED equ 0 ;pin 17 ACTLED equ 1 ;pin 18 Fireout1 equ 2 ;pin 1 Fireout2 equ 3 ;pin 2 PORT_B equ 6 ;individual bits on PORT_B SW5MIN equ 0 ;pin 6 SW75MIN equ 1 ;pin 7 SW10MIN equ 2 ;pin 8 SW15MIN equ 3 ;pin 9 SWCYCLE equ 4 ;pin 10 ... 0 equ 30 minutes, 1 equ 60 minutes SWCUTOFF equ 5 ;pin 11 ... To set cutoff time at 2 or 4 hours. 1 equ 4 hours (sw off). 0 equ 2 hours (sw on). SWPREHEAT equ 6 ;pin 12 ... Grounded means preheat ;number of 150 second cycles for on and off times _5Min equ 2 _75Min equ 3 _10Min equ 4 _15Min equ 6 HalfHour equ D'12' OneHour equ D'24' ;Registers SecCnt equ 0Ch ;temp for counting seconds OnCycles equ 0Dh OffCycles equ 0Eh TotCycles equ 0Fh CycleCnt equ 10h ;need to xfer OffCycles and OnCycles to this and decrement THIS MyFlags equ 11h ;individual bits FireActive equ 0 CycleTimes equ 1 ;Set this flag to 0 for 30 min cycles, or PreH equ 2 ;To know if preheat has run already ;Set to one in init and then clear after preheat runs LEDCnt equ 12h ;temp reg to decrement until turn LEDs on - was 0Eh Intervcnt equ 13h Temp01 equ 1Ch ;for light blink debugging PreOnCyc equ 1Dh ;Temp03 equ 1Eh ;Temp04 equ 1Fh org 0000h goto Start Start Call Init_1 ;------------------------------------------------------------------- MainLoop bsf STATUS, RP0 ;Set to Bank 1 movlw 00000000b ;double check PORT_A as all outputs movwf TRISA ;OK to get "not in bank" error bcf STATUS, RP0 ;Set back to Bank 0 bsf PORT_A, Fireout1 ;Turn the fire on at the beginning bsf PORT_A, Fireout2 ;2 ports bsf MyFlags, FireActive ;Also set the flag that it's on movf OnCycles, W ;Get the number of on cycles movwf CycleCnt ;and store it for decrementing MainLoop2 ;CHECK PREHEAT SWITCH - grounded means preheat btfsc PORT_B, SWPREHEAT goto No_Preheat ;if switch is set, no preheat ;Yes, do a 10 minute preheat btfss MyFlags, PreH ;check and see if we've already done it goto No_Preheat ;if it's cleared don't preheat bcf MyFlags, PreH ;heading thru so clear the flag movlw _10Min addwf CycleCnt, f No_Preheat movlw MainCycles ;Get the amount of the main cycles (150 sec) movwf Intervcnt ;and store it temporarily (can't decrement W) MainLoop3 Call OneSec ;Delay for a second decfsz Intervcnt, f ;Done 150 yet? goto MainLoop3 ;No, keep going decfsz CycleCnt, f ;150 done. Check and see if the number of on cycles is done goto MainLoop2 ;Nope, go back and do another 150 bsf STATUS, RP0 ;Set to Bank 1 movlw 00000000b ;double check PORT_A as all outputs movwf TRISA ;OK to get "not in bank" error bcf STATUS, RP0 ;Set back to Bank 0 bcf PORT_A, Fireout1 ;We're done, so turn fire out bcf PORT_A, Fireout2 bcf MyFlags, FireActive ;and turn the flag off decfsz TotCycles, f ;Are we done with the total cycles (2 or 4 hours)? goto MainLoop4 ;No, do an off cycle goto EndMain ;Yes, we're done MainLoop4 movf OffCycles, W ;Get the number of off cycles movwf CycleCnt ;and store for decrementing MainLoop5 movlw MainCycles ;Get the amount of the main cycles (150 sec) movwf Intervcnt ;and store it temporarily (can't decrement W) MainLoop6 Call OneSec ;Delay for a second decfsz Intervcnt, f ;Done 150 yet? goto MainLoop6 ;No, keep going decfsz CycleCnt, f ;150 done. Check and see if the number of OFF cycles is done goto MainLoop5 ;Nope, go back and do another 150 goto MainLoop ;Go back and do another on cycle EndMain bsf STATUS, RP0 ;Set to Bank 1 movlw 00000000b ;double check PORT_A as all outputs movwf TRISA ;OK to get "not in bank" error bcf STATUS, RP0 ;Set back to Bank 0 movlw 0 ;End it here movwf PORT_A ;Turn all outputs off sleep ;Beddie Bye time ;End Main Loop ;------------------------------------------------------------------- ;------------------------------------------------------------------- ;One second delay OneSec decfsz LEDCnt, f ;Check and see if LEDs should be blinked. Only blink every X times through here. goto RestOfSec ;No, go ahead and do the time. bsf PORT_A, ONLED ;Yes, Turn the LED on btfsc MyFlags, FireActive ;See if the fire is on. bsf PORT_A, ACTLED ;Yes, so turn the fire active LED on too movlw LEDOff ;Reset the number of passes until turn on again movwf LEDCnt ;And store it in LEDCnt RestOfSec movlw OneSecTime ;Get a second amount movwf SecCnt ;And store it temporarily OneSec1 Movlw FiveMSec ;Get the number for 5 ms movwf TMR0 ;And put in the timer OneSec2 movf TMR0, W ;Start checking timer for going all the way up btfss STATUS, Z ; Status reg, Zero flag. goto OneSec2 ; and go back until it fills decfsz SecCnt, f ;Decrement temp register and keep going until the time is up goto OneSec1 ; bcf PORT_A, ONLED ;Turn both LEDs off bcf PORT_A, ACTLED retlw 0 ;End One second delay ;------------------------------------------------------------------- ;------------------------------------------------------------------- ;Init_1 ;Initial settings of ports etc. Init_1 bsf STATUS, RP0 ;Set to Bank 1 movlw B'00000100' ;set timer prescaler to divide by 32 ; And enable port B pullups movwf OPTION_REG ;OK to get an error message. Goes away if this is 01h bcf INTCON, GIE ;Disable all IRQs by clearing bit bcf STATUS, RP0 ;Set back to Bank 0 movlw 0 ;clear some spaces and registers to start with a clean slate movwf OnCycles movwf OffCycles movwf TotCycles movwf SecCnt bcf MyFlags, FireActive ;Make sure FireActive flag is off movlw LEDOff ;initial time for LED off cycles movwf LEDCnt bsf STATUS, RP0 ;Set to Bank 1 movlw 00000000b ;set PORT_A as all outputs movwf TRISA ;OK to get "not in bank" error movlw B'11111111' ;set PORT_B to all inputs movwf TRISB ;OK to get "not in bank" error bcf STATUS, RP0 ;Set back to Bank 0 bsf MyFlags, PreH ;Set preheat bit initially ;Check and see what ON time is set btfss PORT_B, SW5MIN ;see if 5 min switch on and move amount to W, or skip and check next movlw _5Min btfss PORT_B, SW75MIN ;see if 7.5 min switch on and move amount to W, or skip and check next movlw _75Min btfss PORT_B, SW10MIN ;see if 10 min switch on and move amount to W, or skip and check next movlw _10Min btfss PORT_B, SW15MIN ;see if 15 min switch on and move amount to W, or skip and check next movlw _15Min movwf OnCycles ;Check and see what cycle time is set ChkCycTm btfss PORT_B, SWCYCLE ;Check switch 0 equ 30 minutes, 1 equ 60 minutes Goto _30Min ;If not set it comes here movlw OneHour ;Must be 1 hour, so put that amount in W Goto Init_2 ;Skip the load for 1/2 hour _30Min movlw HalfHour ;Put amount for 1/2 hour in W Init_2 movwf OffCycles ;Temporarily store the total amount in OffCycles movf OnCycles, W ;Get the OnCycles time in W subwf OffCycles, F ;Subtrack it from the total cycle time and it ; gives the OffCycles time CkTotTm btfss PORT_B, SWCUTOFF ;To set cutoff time at 4 or 2 hours. 1 equ 4 hours (sw off). 0 equ 2 hours (sw on). goto _2hours ;It's set so time equ 4 hours btfss PORT_B, SWCYCLE ;Check cycle switch 0 equ 30 minutes, 1 equ 60 minutes goto _30 movlw 4 ;1 hour cycles at 4 hours total on time equ 4 total cycles movwf TotCycles goto EndInit _30 movlw 8 ;30 min cycles at 4 hours total on time equ 8 total cycles movwf TotCycles goto EndInit ;Total time is 2 hours _2hours btfss PORT_B, SWCYCLE ;Check cycle switch 0 equ 30 minutes, 1 equ 60 minutes goto _30_2 movlw 2 ;1 hour cycles at 2 hours total on time equ 2 total cycles movwf TotCycles goto EndInit _30_2 movlw 4 ;30 min cycles at 2 hours total on time equ 4 total cycles movwf TotCycles EndInit Retlw 0 ;End Init_1 ;------------------------------------------------------------------- END