some help/advice with a program with 16F1789
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Hi all,
I have written a small program in assembler which works almost perfect... Almost.....
I want the program to monitor the switch at input RB0.
As soon as the button has pressed AND released, a LED at RE2 must lit for about 800mSec.
After that, the LED turns off and the program repeats.
So far, this is exactly what the program does!
Now, the main 'failure' of this program is that, when the LED is on, if the button is pressed within the 800mSec delay, nothing happends because the program is in the delay routine.
What I want is that if the LED is on, and if the button is pressed before the LED is turned off, the LED is switched off and the program waits unti the button is released again.
I think I know the answer to this and that is to use interrupts, right?
So, I have my switch monitoring in the MAIN_LOOP and the delay function as ISR, right?
Any tips or tricks are welcome!
I have written a small program in assembler which works almost perfect... Almost.....
I want the program to monitor the switch at input RB0.
As soon as the button has pressed AND released, a LED at RE2 must lit for about 800mSec.
After that, the LED turns off and the program repeats.
So far, this is exactly what the program does!
- Code: Select all
;****MAIN PROGRAM
MAIN_LOOP
;wait for button press @ RB0
banksel PORTB
wait_dn btfsc PORTB,RB0 ; skip next instruction if RB0 => LOW
goto wait_dn
;wait for button release
banksel PORTB
wait_up btfss PORTB,RB0 ; skip next instruction if RB0 => HIGH
goto wait_up
;turn on LED @ RE2
banksel LATE
bsf LATE,RE2
;delay 800mSec
movlw .80
pagesel delay10
call delay10
pagesel $
;turn off LED @ RE2
banksel LATE
bcf LATE,RE2
;repeat forever
goto MAIN_LOOP
END
Now, the main 'failure' of this program is that, when the LED is on, if the button is pressed within the 800mSec delay, nothing happends because the program is in the delay routine.
What I want is that if the LED is on, and if the button is pressed before the LED is turned off, the LED is switched off and the program waits unti the button is released again.
I think I know the answer to this and that is to use interrupts, right?
So, I have my switch monitoring in the MAIN_LOOP and the delay function as ISR, right?
Any tips or tricks are welcome!