Specifications

mikroElektronika | Free Online Book | PIC Microcontrollers | Appendix B: Examples
btfsc STATUS, Z
goto End
call Delay1ms
decf HIcnt, f
decf LOcnt, f
goto Loop1
Delay1ms: ; Delay1ms provides delay of
movlw .100 ; 100*10us=1ms
movwf LOOPcnt ; LOOPcnt<-100
Loop2:
nop
nop
nop
nop
nop
nop
nop
decfsz LOOPcnt, f
goto Loop2 ; Execution time of Loop2
return ; is 10 us
End
ENDM
;**********************************************************************
Macro "button"
;****************************************************
button MACRO port,pin,hilo,label
local Pressed1 ; All labels are local
local Pressed2
local Exit1
local Exit2
IFNDEF debouncedelay ; Enables debounce time to be defined
; in main program
#define debouncedelay .10
ENDIF
IF (hilo == 0) ; If pull-up used
btfsc port, pin ; If "1", push-button is pressed
goto Exit1
pausems debouncedelay ; Wait for 10ms debounce
Pressed1
btfss port, pin
goto Pressed1
pausems debouncedelay ; Wait until released and
goto label ; jump to specified address
Exit1
ELSE ; If pull-down used
btfss port, pin
goto Exit2 ; If "0", push-button is released
pausems debouncedelay ; Wait for 10ms debounce
Pressed2
btfsc port, pin
goto Pressed2
pausems debouncedelay ; Wait until released and
goto label ; jump to specified address
Exit2
ENDIF
ENDM
;**********************************************************************
EXAMPLE 8
Using timer TMR1 and using interrupt
http://www.mikroe.com/en/books/picmcubook/appb/ (32 of 54)5/3/2009 11:36:02 AM