//变量定义
BMQ_VALUE DS 1
BMQ_VALUE_PRE DS 1
BMQ_VALUE_BUF DS 1
CW_DELAY DS 1
CCW_DELAY DS 1
BMQ_DELAY DS 1
//引脚定义
P_BMQ1 EQU P1.3
P_BMQ2 EQU P1.2
;************************************************
;************************************************
;编码器检测子程序(每125us调用一次)
;************************************************
B0BTS1 F_ONOFF
JMP INT_EXIT
SCAN_BMQ:
CLR BMQ_VALUE
B0BTS0 P_BMQ1
B0BSET BMQ_VALUE.0
B0BTS0 P_BMQ2
B0BSET BMQ_VALUE.1
BMQ_JUD:
B0MOV A, BMQ_VALUE
XOR A, BMQ_VALUE_PRE
B0BTS0 FZ
JMP BMQ_JUD1
B0MOV A, BMQ_VALUE
B0MOV BMQ_VALUE_PRE, A
CLR BMQ_DELAY
BMQ_JUD1:
B0MOV A, BMQ_DELAY
SUB A, #08
B0BTS0 FC
JMP BMQ_JUD2
INCMS BMQ_DELAY
NOP
JMP END_SCAN_BMQ
BMQ_JUD2:
B0MOV A, BMQ_VALUE
XOR A, BMQ_VALUE_BUF
B0BTS0 FZ
JMP END_SCAN_BMQ
B0MOV A, BMQ_VALUE
XOR A, #00H
B0BTS0 FZ
JMP BMQ_STEP0
B0MOV A, BMQ_VALUE
XOR A, #01H
B0BTS0 FZ
JMP BMQ_STEP1
B0MOV A, BMQ_VALUE
XOR A, #02H
B0BTS0 FZ
JMP BMQ_STEP2
B0MOV A, BMQ_VALUE
XOR A, #03H
B0BTS0 FZ
JMP BMQ_STEP3
JMP END_SCAN_BMQ
BMQ_STEP0:
B0MOV A, BMQ_VALUE_BUF
XOR A, #01H
B0BTS0 FZ
JMP BMQ_CCW
B0MOV A, BMQ_VALUE_BUF
XOR A, #02H
B0BTS0 FZ
JMP BMQ_CW
CLR CW_DELAY
CLR CCW_DELAY
JMP END_BMQ_STEP
BMQ_STEP1:
B0MOV A, BMQ_VALUE_BUF
XOR A, #03H
B0BTS0 FZ
JMP BMQ_CCW
B0MOV A, BMQ_VALUE_BUF
XOR A, #00H
B0BTS0 FZ
JMP BMQ_CW
CLR CW_DELAY
CLR CCW_DELAY
JMP END_BMQ_STEP
BMQ_STEP2:
B0MOV A, BMQ_VALUE_BUF
XOR A, #00H
B0BTS0 FZ
JMP BMQ_CCW
B0MOV A, BMQ_VALUE_BUF
XOR A, #03H
B0BTS0 FZ
JMP BMQ_CW
CLR CW_DELAY
CLR CCW_DELAY
JMP END_BMQ_STEP
BMQ_STEP3:
B0MOV A, BMQ_VALUE_BUF
XOR A, #02H
B0BTS0 FZ
JMP BMQ_CCW
B0MOV A, BMQ_VALUE_BUF
XOR A, #01H
B0BTS0 FZ
JMP BMQ_CW
CLR CW_DELAY
CLR CCW_DELAY
JMP END_BMQ_STEP
BMQ_CW:
CLR CCW_DELAY
INCMS CW_DELAY
NOP
B0MOV A, CW_DELAY
SUB A, #04H
B0BTS1 FC
JMP END_BMQ_STEP
CLR CW_DELAY
B0MOV A, SPEED_SETUP ;加
XOR A, #0H
B0BTS0 FZ
JMP END_BMQ_STEP
DECMS SPEED_SETUP
NOP
B0BCLR F_OUTPUT
CLR T_OUTPUT
JMP END_BMQ_STEP
BMQ_CCW:
CLR CW_DELAY
INCMS CCW_DELAY
NOP
B0MOV A, CCW_DELAY
SUB A, #04H
B0BTS1 FC
JMP END_BMQ_STEP
CLR CCW_DELAY
B0MOV A, SPEED_SETUP ;减
XOR A, #4H
B0BTS0 FZ
JMP END_BMQ_STEP
INCMS SPEED_SETUP
NOP
B0BCLR F_OUTPUT
CLR T_OUTPUT
END_BMQ_STEP:
B0MOV A, BMQ_VALUE
B0MOV BMQ_VALUE_BUF, A
END_SCAN_BMQ:
|