WHEEL_DEBOUNCE_TIMER EQU 3/1 ;3ms
;ClockWise: 11,01,00,10,11... ;AntiClockWise: 11,10,00,01,11... ;-------------------------------------------------------------------------------------- ScanWheelIO: andim PIN_WHEEL_Cfg ,(WHEELA+WHEELB)^0x0f orim PIN_WHEEL ,WHEELA+WHEELB lda PIN_WHEEL ,0 nop sta zWheelTMP ,0 andim zWheelTMP ,WHEELA+WHEELB ;----- Result save in zWheelTMP------- rtni ;====================================================================================== ; ScanWheel ;====================================================================================== ScanWheel: ;whether ever get different Wheel value than the last Wheel state lda zWdebounce ,0 ;yes,check whether maintain stable ba0 ContinueScanWheel ;no,check whether get different Wheel value LookUpWheelState: call ScanWheelIO eor zWheelState ,0 ;if different from the last stable state bnz BeginScanWheel ;if equal to the last state jmp Finish_ScanWheel BeginScanWheel: ;save current state to zWheelState buffer lda zWheelTMP ,0 sta zWheelState ,0 ;----- Reload Debounce counter and clear debounce done flag ----- ldi zWheelPeriod ,WHEEL_DEBOUNCE_TIMER andim zIntFlag ,1101b ;---------------------------------------------------------------- ;mark ever get different Wheel value than the last Wheel state flag orim zWdebounce ,0001b jmp Finish_ScanWheel ;exit ContinueScanWheel: call ScanWheelIO eor zWheelState ,0 ;if different from the last stable state again bnz BeginScanWheel ;if still equal to the last state DebounceScanWheel: ;the Wheel state must be stable here lda zIntFlag ,0 ba1 $+2 jmp Finish_ScanWheel andim zIntFlag ,1101b ;Judge whether finish debouncing work. sbim zWheelPeriod ,01h baz VerifyWheelValue jmp Finish_ScanWheel VerifyWheelValue: andim zWdebounce ,1110b ;whether state chage? lda zWheelTMP ,0 eor zWheelValue ,0 baz Finish_ScanWheel ;judge clockWise or anti-clockWise sbi zWheelTMP ,0100b baz ?mayBeAntiClockWise sbi zWheelTMP ,1000b baz ?mayBeClockWise jmp ?next ?mayBeClockWise: sbi zWheelValue ,1100b bnz ?next call IncreaseIronSetpoint ;refer to Iron.asm jmp ?next ?mayBeAntiClockWise: sbi zWheelValue ,1100b bnz ?next call DecreaseIronSetpoint ;refer to Iron.asm ?next: ;save------------------------------------------------------------------------------------ SaveWheelState: ;curren state as stable state lda zWheelTMP ,0 sta zWheelValue ,0 Finish_ScanWheel: call ReturnToWorkState ;refer to Iron.asm jmp Exit_ScanWheel |