Fot the project I write this software, it has a 5-pos DIP switch incorporated.
Simply said, DIPswitch 1 ON => program 1 ...... DIPswitch 5 ON => program 5.
That's why I used PROG1
Now, as you suggest I must make some impovements to the code step by step.
First make shorter by removing the delay loops and use Timer0 instead to create a ~1sec delay.
This removes the nesesarry variables for the delay loop.
I changed the prescaler to 1:128 to get a maximum time of ~1sec. when Timer0 overflows.
This mean I first have to change the debounce delay. (128ms for debounce is a 'little' too much)
- Code: Select all
movf TMR0,w ; has ~20ms debounce time elapsed?
xorlw .5 ; ( 20 ms = 5 * 4.096ms)
then removing the delay loops and use Timer0 instead to create a ~1sec delay:
(initially without responding to stwitch input)
- Code: Select all
; delay 1000ms
banksel TMR0
clrf TMR0 ; clear Timer0
w_tmr0
banksel TMR0
movf TMR0,w ; copy the current value of TMR0 to W
xorlw .255 ; Check if approx. 1000ms has elapsed
btfss STATUS,Z ; 244*4.096 = 999,5ms
goto w_tmr0
Now I need the program to respond to the input switch while inside the delay loop:
- Code: Select all
; delay 1000ms
banksel TMR0
clrf TMR0 ; clear Timer0
w_tmr0
banksel PORTB
btfsc PORTB,RB0 ; check if RB0 input is active
goto PROG1
banksel TMR0
movf TMR0,w ; copy the current value of TMR0 to W
xorlw .255 ; Check if approx. 1000ms has elapsed
btfss STATUS,Z ; 244*4.096 = 999,5ms
goto w_tmr0
Still, however, all the code is still inside the MAIN...
So first I will try to do is trying to get the delay loop and debounce routine in a subroutine.
This is what I'm goint to do right now, so when I finish this, I will continue here