Good call with the 'txt' file pseudo code...saves us having to wade though lots of code
And means I can see what you're doing without including the code thats working fine.
Hmm it seems you are not debouncing the button.
In order to debounce a button, it must be checked twice. Once, then a small delay, then again to see if its still pressed or if its a false trigger. In your routine, you are indeed checking the flag, but only checking the button once.
The debounce routine is simply used in place of 'btfsc PORTA,4'. It is just used to 'read' a buttons state twice, with a delay inbetween to make sure its on, or off.
The reason your display is going off when you
hold the button down is because it never gets to the 'Stay' subroutine, which if I'm not mistaken you use to display the digits.
I don't like to complicate what should be a fairly straight forward problem, but, if you tihnk about it, with reading a button (debounced or otherwise) there are only two posibilities. On, or Off. But...when we add our flag, theres
four posibilities:
Flag Button
0 0 - (1) displaying the digits, key isn't pressed
0 1 - (2) new key press (flag =0, wasn't pressed before)
1 0 - (3) key released (flag = 1, WAS pressed, but now its not)
1 1 - (4) key was pressed before, and is STILL pressed.
So, for (1) we go to the 'stay routine' and clear flag.
(2) we go to the 'Countup' routine and set flag.
(3) we go to the 'stay routine', and clear flag
and (4) we go to the 'stay routine', with the flag still set.
So, as you can see, we only go to the 'coutup' routine when the flag is 0 and the button (after debouncing) is 1. Because the flag represents the buttons previous state, last time it was checked, we can say that we only do something other than go to 'stay' if the button has gone from 0 to 1. Not 1 to 0.
I modified your little txt file
Try and work out what I did, and WHY I did it. Thats the problem with loops, its easy to lose track of where the program is going under certain conditions.
GOod Luck
Blueteeth