B
Bill Bowden
Guest
On Nov 17, 7:33 am, Allen Bong <allenbsf6...@gmail.com> wrote:
value in the variable TOTAL which represents the time the button was
pressed (16 seconds max). Then you can test the bits in the variable
TOTAL to see how long the button was pressed. Or subtract some
threshold value from TOTAL and then check the status bits to determine
if it's greater or less than the threshold. Just an idea.
Test_Button
clrf TOTAL ; clear the variable TOTAL
btfsc GPIO,0 ; look to see if pin is low (clear = low if button
pressed)
return ; exit, button not pressed
call Delay ; get 65 millisecond delay
incf TOTAL ; Accumulate time in 65mS segments
goto $ - 4 ; Jump back 4 lines
return
Delay
movlw d'255'
movwf TEMP ; load 255 or hex FF into TEMP
goto $ +4 ; Jump 4 lines down
decfsz TEMP,f ; decrement TEMP, skip if zero
goto $ +2 ; Jump 2 lines down
return
movlw d'255'
movwf COUNTER
decfsz COUNTER,f
goto $ -1
goto $ -7
-Bill
Might try this idea to get the button press time.The example returns aOn Nov 17, 1:27 pm, Randy Day <randy....@sasktel.netx> wrote:
In article <863dfac8-adbb-4ad5-89ff-
32ea6f859...@j9g2000vbr.googlegroups.com>,
allenbsf6...@gmail.com says...
[snip]
The long and short duration technique is nice and I wonder if you have
some codes for me to try out?
Just air code. I'm using timer SFR names
from micros I use, so they may not apply
to the '675:
Button_Loop
btfsc GPIO, 0
goto Button_Loop
; enable 1 second timer here
Short_Loop
btfsc GPIO, 0
goto Short_Press
; loop until timer expires
btfss PIR1, TMR1IF
goto Short_Loop
; if timer manages to expire, the
; button is still pressed,
; and is considered a 'long' (>1sec)
; press.
; turn off timer here
Long_Press ; keep looping until button is released
btfss GPIO, 0
goto Long_Press
; run your 'long press' code
goto Main_Program
Short_Press
; if gpio<0> went high before 1sec,
; the button was released as a 'short'
; (<1sec) press.
; turn off timer here
; run your 'short press' code
goto Main_Program
Let me see if I understand it right.
For a short press: It enters Botton_Loop, pass the first btfsc test.
Then enable 1 sec timer, past second btfsc test. Timer 1 not yet
expired, Loop back into the Short_Loop. Release button before timer 1
expires and exit into Short_Press.
For a long press: Enters at Button_Loop, pass the first btfsc test,
set up timer 1 for 1 sec, Goes through second btfsc test and on 3rd
btfss test, also dropped into the Short_Loop until > 1 second, timer1
expires, will drop onto Long_Press loop and exit btfss when the button
is released.
Very nice, but at first glance, a bit tough to understand how it
works.
Thank you Randy for teaching me this new trick!! I'll put it into my
macro library file and include it on my next program.
Cheers,
Allen
value in the variable TOTAL which represents the time the button was
pressed (16 seconds max). Then you can test the bits in the variable
TOTAL to see how long the button was pressed. Or subtract some
threshold value from TOTAL and then check the status bits to determine
if it's greater or less than the threshold. Just an idea.
Test_Button
clrf TOTAL ; clear the variable TOTAL
btfsc GPIO,0 ; look to see if pin is low (clear = low if button
pressed)
return ; exit, button not pressed
call Delay ; get 65 millisecond delay
incf TOTAL ; Accumulate time in 65mS segments
goto $ - 4 ; Jump back 4 lines
return
Delay
movlw d'255'
movwf TEMP ; load 255 or hex FF into TEMP
goto $ +4 ; Jump 4 lines down
decfsz TEMP,f ; decrement TEMP, skip if zero
goto $ +2 ; Jump 2 lines down
return
movlw d'255'
movwf COUNTER
decfsz COUNTER,f
goto $ -1
goto $ -7
-Bill