User manual
00066_MCP402XEV.ASM Source Code
© 2005 Microchip Technology Inc. DS51546B-page 32
ButtonCheck ; Debounce Buttons
btfss PowerDown ; If pulled low, put uC to SLEEP
goto LowPowerMode
bsf UP_State
bsf DOWN_State ; initialize Button_State to indicate no button pressed
movlw .50 ; debounce the buttosns for 50mS to see if pressed
movwf Exit
movlw .40 ; if pushed for 40 of 50 tests, then valid UP
movwf DebounceUP
movwf DebounceDOWN
DebounceLoop
call GPIO_TestUP ; make GP1/INCR/UD an input (w/pu enabled)
movlw .99
call VAR5TcyDELAY ; 5 + (99*5) = 500us
btfss UP
decfsz DebounceUP,f
goto CheckDOWN
bcf UP_State ; UP Button Pressed
CheckDOWN
call GPIO_TestDOWN ; make GP0/DECR/CS an input (w/pu enabled)
movlw .99
call VAR5TcyDELAY ; 5 + (99*5) = 500us
btfss DOWN
decfsz DebounceDOWN,f
goto DebounceLoopTest
bcf DOWN_State ; DOWN Button Pressed
DebounceLoopTest
decfsz Exit,f
goto DebounceLoop
call InitGPIO ; make GP0/DECR/CS & GP1/INCR/UD outputs, block undesired U/D commands
movf State,w
call DetermineState ; subroutine to determine the next state
movwf State
xorwf OldState,w
btfss STATUS,Z
call PerformState ;State changed, now do something
movlw .5
call VAR1000TcyDELAY ; Make sure EE Write Cycle has finished
movf State,w
movwf OldState
goto ButtonCheck ; Loop for button presses
;***********************************************************************************************
; State Machine Code
;***********************************************************************************************
State0 goto StateMachineReset ; State 0, no action, shouldn’t get here
State1 ; UP button pressed
movlw .200 ; 200x10mS = 2s
movwf Exit
TABLE E-1: 00066_MCP402XEV.ASM SOURCE CODE (CONTINUED)