#include <P16F630.INC>
 __CONFIG (_MCLRE_OFF & _CP_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT)  ;Internal osc.

 c1 equ 20
 c2 equ 21
 sec equ 22
 c3 equ 23
 c4 equ 24

 org 0

Start
 BCF   STATUS,RP0  ; select bank 0
 CLRF  PORTA       ; porta=0
 movlw b'11111111'
 movwf CMCON 
 BSF   STATUS,RP0  ; select bank 1
 movlw b'00001000'
 movwf TRISA
 CLRF  TRISC       ; make PORTC pins all output
 BCF   STATUS,RP0  ; select bank 0
 movlw b'00000001'
 movwf  PORTC       ; set portc pins equal to 1 min
 clrf  sec

loop
 call delay1
 incf sec
 call secout
 movlw b'00011110'
 subwf sec,w
 btfss STATUS,Z
 goto loop
loop1
 call delay1
 decf sec
 call secout
 movlw b'00000000'
 subwf sec,w
 btfss STATUS,Z
 goto loop1
 call cdown
 goto loop

cdown
 decf PORTC  ; decrease portc by 1
 movlw b'00000000'
 subwf PORTC,w
 btfsc STATUS,Z
 call flasher
 return

secout
 btfsc sec,0
 bsf PORTA,RA5
 btfss sec,0
 bcf PORTA,RA5
 btfsc sec,1
 bsf PORTA,RA4
 btfss sec,1
 bcf PORTA,RA4
 btfsc sec,2
 bsf PORTA,RA0
 btfss sec,2
 bcf PORTA,RA0
 btfsc sec,3
 bsf PORTA,RA1
 btfss sec,3
 bcf PORTA,RA1
 btfsc sec,4
 bsf PORTA,RA2
 btfss sec,4
 bcf PORTA,RA2
 return

flasher
loopf
 call delay2
 CLRF PORTC
 call delay2
 movlw b'11111111'
 movwf PORTC
 goto loopf
 return

delay1
 movlw b'00000110'
 bcf STATUS,RP0
 movwf c3
lc7
 movlw b'11111111'
 movwf c2
lc0
 movlw b'11111111'
 movwf c1
lc1
 decfsz c1,1
 goto lc1
 btfss PORTA,RA3
 call set1
 decfsz c2,1
 goto lc0
 decfsz c3,1
 goto lc7

 movlw b'00111110'
 movwf c2
lc8
 movlw b'11111111'
 movwf c1
lc9
 decfsz c1,1
 goto lc9
 decfsz c2,1
 goto lc8
 movlw b'00000001'
 movwf c1
lc10
 decfsz c1,1
 goto lc10
 return

delay2
 movlw b'11111111'
 bcf STATUS,RP0
 movwf c2
lc4
 movlw b'11111111'
 movwf c1
lc5
 decfsz c1,1
 goto lc5
 btfss PORTA,RA3
 goto lc6
 decfsz c2,1
 goto lc4
 return
lc6
 call set1
 goto loop
 return

set1
 incf PORTC
 movlw b'11111111'
 bcf STATUS,RP0
 movwf c1
lc2
 movlw b'11111111'
 movwf c2
lc3
 decfsz c2,1
 goto lc3
 decfsz c1,1
 goto lc2
 CLRF sec
 call secout
 goto loop
 end
