Hi,
I've literally spent the entire night figuring out how to use interrupts. I have finally managed to get it working and to have a counter count while I keep a button pressed.
The problem is, the counter is obviously 8 bits, which can go to 255(256) but I want to limit it to go only to 9(10). How do I achieve that? So basically, count up to ten and then reset to 0 instead of incrementing to 11.
The loop that runs while the button is pressed, looks like this:
I thought there might be a way to 'force' a loop to quit after x amount of runs? but this is a bit impractical, since the button would still be pressed and that could cause problems.
Lastly, and this is the tricky part (I think), I want to change the delay that is being called in the main loop according to the value of delaycnt. ie. when delay count is 10, I call the shortest delay, and when it is one, I call the longest.
Is this possible?
Thanks in advance!
I've literally spent the entire night figuring out how to use interrupts. I have finally managed to get it working and to have a counter count while I keep a button pressed.
The problem is, the counter is obviously 8 bits, which can go to 255(256) but I want to limit it to go only to 9(10). How do I achieve that? So basically, count up to ten and then reset to 0 instead of incrementing to 11.
The loop that runs while the button is pressed, looks like this:
Code:
count_loop
call _4 ;Delay to decrease speed, so that you can see the register increment.
incf delaycnt,f ;increments the counter
movfw delaycnt
movwf PORTA
btfsc PORTB,0 ;Waits for button release
goto count_loop
Lastly, and this is the tricky part (I think), I want to change the delay that is being called in the main loop according to the value of delaycnt. ie. when delay count is 10, I call the shortest delay, and when it is one, I call the longest.
Is this possible?
Thanks in advance!
Last edited: