;FLAG2,0= button press flag bit
;FLAG2,1= counter ON flag bit
;LoopCount=50
;COUNTER = 5 (COUNTER has set to 5 seconds)
;DISPLAY THE TWO DIGITS
CLFLAG2 bcf FLAG2,0 ;clear the button press flag bit
MULTIPLEX bcf PORTA,1
movf SEGMANT1,0
call TABLEP
movwf PORTB
bsf PORTA,0 ;display digit1
call DEL10ms
bcf PORTA,0
movf SEGMANT2,0
call TABLEP
movwf PORTB
bsf PORTA,1 ;display digit2
call DEL10ms
;COUNTER PART
btfss FLAG2,1 ;is counter running?
goto CHECKBUTTON1 ;no, do other stuff
bsf PORTA,4 ;yes, turn ON the output
decfsz LoopCount,1 ;count 50 times round loop
goto MULTIPLEX ;50*20mS = 1 second(total delay 20ms in multiplex mode)
movlw .50
movwf LoopCount
decfsz COUNTER,1
goto MULTIPLEX
bcf FLAG2,1 ;stop counter
bcf PORTA,4 ;turn OFF the output after 5 seconds
goto BEGIN
;check the button is pressed
CHECKBUTTON1 btfsc PORTA,3 ;test the set button(RA3)
goto CHECKBUTTON2
call DEL0.9ms ;debounce delay
bsf FLAG2,1 ;enable the counter
CHECKBUTTON2 btfsc PORTA,2 ;test the count up button (RA2)
goto CLFLAG2
countupstuff