;
;       
;               
;               soft_ngp629.txt
;
;
;
;------------------------------------------------------------------------------
; OSCCAL RESTORE (not required if internal OSC is not used)
;------------------------------------------------------------------------------
;
START
        errorlevel -302
        BSF     STATUS,RP0    ; set file register bank to 1
        CALL    0x3FF         ; retrieve factory calibration value
        MOVWF   OSCCAL        ; update register with factory cal value
        BCF     STATUS,RP0    ; set file register bank to 0
;    goto hard_init
;
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
; PLACE USER PROGRAM HERE
;------------------------------------------------------------------------------
;
;      
;
hard_init
       clrwdt
       MOVLW 07h ; Set GP<2:0> to
       MOVWF CMCON ; digital IO
       bsf STATUS,RP0 ;Bank 1
       iorwf OPTION_REG,f ;  wdt  1:128
;   ""  (OPTION_REG./GPPU = 1)
       clrwdt
       bcf STATUS,RP0 ;Bank 0
;
     movlw (1<<P_flame | 1<<P_valve_f | 1<<P_valve)
     movwf GPIO
     movlw (0xFF-(1<<P_ignits | 1<<P_valve_f | 1<<P_valve))
     bsf STATUS,RP0 ;Bank 1
     movwf TRISIO
     bcf STATUS,RP0 ;Bank 0
soft
     clrwdt
      tim0 3
      clrwdt
      tim0 3 ; ~1S
      clrwdt
test_zz
  btfss GPIO,P_flame ;   
   goto drav_zz
ignits_on
     bsf GPIO,P_ignits
     tim0 3 ; ~0,5S
      clrwdt
gas_on_forse
     movlw (0xFF-(1<<P_valve_f | 1<<P_valve))
     andwf GPIO,f
     tim0 3 ; ~0,5S
      clrwdt
disforse
     bsf GPIO,P_valve_f
     clrwdt
     movlw .16
     movwf cnt_wfl ;     0,5 
wait_flame
      btfss GPIO,P_flame
      goto wait_stable_flame ;    
     tim0 3 ; ~0,5S
      clrwdt
      decfsz cnt_wfl,f
       goto wait_flame ;   
restart_ignitions
     clrwdt ;    8   
     bsf GPIO,P_valve ;   
      tim0 3
      clrwdt
      tim0 3
      clrwdt
     bcf GPIO,P_ignits ;  
        clrwdt
      tim0 3
      clrwdt
      tim0 3
      clrwdt
      tim0 3
      clrwdt
      tim0 3
      clrwdt ;   `2 
 ; cnt_ignits_error +/-1      (  )
    goto soft
wait_stable_flame
      bcf GPIO,P_ignits ;  
test_works
      btfsc GPIO,P_flame
      goto error_works
       tim0 2
      clrwdt
      goto test_works
error_works     ;      
    bsf GPIO,P_valve ;   
    clrwdt
  ; cnt_works_error +/-1      (  )
   goto restart_ignitions ;   -    
;
drav_zz
  clrwdt
   bsf GPIO,P_ignits
      clrwdt
      tim0 3
      clrwdt
      tim0 3
      clrwdt
   bcf GPIO,P_ignits
   ;     
   ;        
   ;                ;     
stop
  clrwdt
  goto stop ;  
;