;FLAG2,1 - flag bit which helps to turn ON the counter
;2 segments multpiplex stuff
MULTIPLEX bcf PORTA,1
movf SEGMANT1,0 ;display the number in segmant 1
call TABLE
movwf PORTB
bsf PORTA,0 ;display digit1
call DELAY
bcf PORTA,0
movf SEGMANT2,0 ;display the number in segmant 2
call TABLE
movwf PORTB
bsf PORTA,1 ;display digit2
call DELAY
;make 1s and check iS it 5s
btfss FLAG2,1 ;is couter running?
goto MAIN ;no,go & check the button
decfsz LoopCount,1 ;count 50 times round loop
goto MULTIPLEX ;50*20mS = 1 second
movlw 32H
movwf LoopCount
incf Seconds,1 ;count seconds
movlw 05H ;has it reached 5 seconds?
xorwf Seconds,0
btfss STATUS,2
goto MULTIPLEX ;no, loop around
bcf FLAG2,1 ;yes, stop counter
[B]bcf PORTB,7 [/B] ;turn OFF the output after 5S
goto BEGIN
;check the button is pressed
MAIN btfsc PORTA,2 ;test the button (RA2)
goto MULTIPLEX ;no then goto MULTIPLEX
bsf FLAG2,1 ;yes then start the counter & display the MULTIPLEX
goto SETOUTPUT
;making the RB7 as an output
SETOUTPUT call TABLEP
btfsc PORTB,7
iorlw b'10000000'
movwf PORTB
[B]bsf PORTB,7 [/B] ;turn ON the output
goto MULTIPLEX