MOV20H,#00H;20H單元置初值,電機正轉位置指標
MOV21H,#00H;21H單元置初值,電機反轉位置指標
MOVP1,#0C0H;P1口置初值,防止電機上電短路
MOVTMOD,#60H;T1計數器置初值,開中斷
MOVTL1,#0FFH
MOVTH1,#0FFH
SETBET1
SETBEA
SETBTR1
SJMP$
;***********計數器1中斷程式************
IT1P:JBP3.7,FAN;電機正、反轉指標
;*************電機正轉*****************
JB00H,LOOP0
JB01H,LOOP1
JB02H,LOOP2
JB03H,LOOP3
JB04H,LOOP4
JB05H,LOOP5
JB06H,LOOP6
JB07H,LOOP7
LOOP0:MOVP1,#0D0H
MOV20H,#02H
MOV21H,#40H
AJMPQUIT
LOOP1:MOVP1,#090H
MOV20H,#04H
MOV21H,#20H
LOOP2:MOVP1,#0B0H
MOV20H,#08H
MOV21H,#10H
LOOP3:MOVP1,#030H
MOV20H,#10H
MOV21H,#08H
LOOP4:MOVP1,#070H
MOV20H,#20H
MOV21H,#04H
LOOP5:MOVP1,#060H
MOV20H,#40H
MOV21H,#02H
LOOP6:MOVP1,#0E0H
MOV20H,#80H
MOV21H,#01H
LOOP7:MOVP1,#0C0H
MOV;20H,#01H
MOV21H,#80H
;***************電機反轉*****************
FAN:JB08H,LOOQ0
JB09H,LOOQ1
JB0AH,LOOQ2
JB0BH,LOOQ3
JB0CH,LOOQ4
JB0DH,LOOQ5
JB0EH,LOOQ6
JB0FH,LOOQ7
LOOQ0:MOVP1,#0A0H
LOOQ1:MOVP1,#0E0H
LOOQ2:MOVP1,#0C0H
LOOQ3:MOVP1,#0D0H
LOOQ4:MOVP1,#050H
LOOQ5:MOVP1,#070H
LOOQ6:MOVP1,#030H
MOV20H,#01H
LOOQ7:MOVP1,#0B0H
QUIT:RETI END
MOV20H,#00H;20H單元置初值,電機正轉位置指標
MOV21H,#00H;21H單元置初值,電機反轉位置指標
MOVP1,#0C0H;P1口置初值,防止電機上電短路
MOVTMOD,#60H;T1計數器置初值,開中斷
MOVTL1,#0FFH
MOVTH1,#0FFH
SETBET1
SETBEA
SETBTR1
SJMP$
;***********計數器1中斷程式************
IT1P:JBP3.7,FAN;電機正、反轉指標
;*************電機正轉*****************
JB00H,LOOP0
JB01H,LOOP1
JB02H,LOOP2
JB03H,LOOP3
JB04H,LOOP4
JB05H,LOOP5
JB06H,LOOP6
JB07H,LOOP7
LOOP0:MOVP1,#0D0H
MOV20H,#02H
MOV21H,#40H
AJMPQUIT
LOOP1:MOVP1,#090H
MOV20H,#04H
MOV21H,#20H
AJMPQUIT
LOOP2:MOVP1,#0B0H
MOV20H,#08H
MOV21H,#10H
AJMPQUIT
LOOP3:MOVP1,#030H
MOV20H,#10H
MOV21H,#08H
AJMPQUIT
LOOP4:MOVP1,#070H
MOV20H,#20H
MOV21H,#04H
AJMPQUIT
LOOP5:MOVP1,#060H
MOV20H,#40H
MOV21H,#02H
AJMPQUIT
LOOP6:MOVP1,#0E0H
MOV20H,#80H
MOV21H,#01H
AJMPQUIT
LOOP7:MOVP1,#0C0H
MOV;20H,#01H
MOV21H,#80H
AJMPQUIT
;***************電機反轉*****************
FAN:JB08H,LOOQ0
JB09H,LOOQ1
JB0AH,LOOQ2
JB0BH,LOOQ3
JB0CH,LOOQ4
JB0DH,LOOQ5
JB0EH,LOOQ6
JB0FH,LOOQ7
LOOQ0:MOVP1,#0A0H
MOV21H,#02H
MOV20H,#40H
AJMPQUIT
LOOQ1:MOVP1,#0E0H
MOV21H,#04H
MOV20H,#20H
AJMPQUIT
LOOQ2:MOVP1,#0C0H
MOV21H,#08H
MOV20H,#10H
AJMPQUIT
LOOQ3:MOVP1,#0D0H
MOV21H,#10H
MOV20H,#08H
AJMPQUIT
LOOQ4:MOVP1,#050H
MOV21H,#20H
MOV20H,#04H
AJMPQUIT
LOOQ5:MOVP1,#070H
MOV21H,#40H
MOV20H,#02H
AJMPQUIT
LOOQ6:MOVP1,#030H
MOV21H,#80H
MOV20H,#01H
AJMPQUIT
LOOQ7:MOVP1,#0B0H
MOV21H,#01H
MOV20H,#80H
QUIT:RETI END