Hi,
I have almost done the counter, but the codes are too long, I've simplified it as attached so that won't be confusing you guys.
I have defined a constant named "STATUS_timer", which indicates the status of the counter:
bit 0:display counter 1 if set and display counter 2 if clear
bit 1:set if counter 1 is counting down, else it is 0
bit 2:set if counter 2 is counting down, else it is 0
bit 3:set if counter 1 has finished counting
bit 4:set if counter 2 has finished counting
bit 5:clear if content of counter 1 is 0
bit 6:clear if content of counter 2 is 0
bit 7:not used.
bit 0 is to display
bit 1 and 2 is to tell the PIC when the button is pressed in the main routine, count down start in interrupt routine.
bit 3 and 4: when the counter has finish counting in the interrupt routine, tell the main routine.
bit 5 and 6: just to see whether counter 1 or counter 2 is empty or not. for example, if counter 1 is empty and the 'start' button is pressed, it go to receiver1; if it is not empty and the button is pressed, it starts counting down.
I have found a problem here:
When I turned on the power, it is in the counter 1 routine (defined in initialize), i.e. display counter 1. When I press button to increment counter 1 and press start, the counter start counting, and it is displaying counter 1. Then I press to change to counter 2 (counter 1 is still counting, just display counter 2), when I press the same button to change to counter 1, cannot, it is just showing counter 2. But if I increment counter 2 and press start, then I can change back to display counter 1, and I can see both counter are counting down independently.
This happens vice versa. If I start it with counter 2, the same thing happen, I can't display counter 1 when counter 1 is counting and in the counter 2 routine (counter 2 is not counting)
I have tested a few and got these results:
I can change to counter 1 or counter 2 as I like when both of them are not counting down.
I can change to counter 1 or counter 2 as I like when both of them are counting down.
I can't change to counter 1 which is counting down when I change to counter 2 which is not counting and vice versa.
Can anyone help me with this? Maybe I explaination is not very clear.
Thanks