ORG 1000H
MAINZ: MOV R2,#04H ;设置步进电动机运行方式四拍
LOOPZ: JB P0.5,LOOPZ ;Z启停按钮是否按下
JB P0.4,POSZ ;是否为正转
AJMP NEGZ ;否则为反转
POSZ:MOV DPTR,#TABLE1 ;正转
LOOP1Z:CLR A
MOVC A,@A+DPTR
MOV P2,A
INC DPTR
JNB P0.3,LOOP2Z ;是否提速
MOV R5,#2
ACALL DELAY
LOOP2Z:MOV R5,#1
ACALL DELAY
DJNZ R2,LOOP1Z
AJMP MAINZ
NEGZ: MOV DPTR,#TABLE2;反转
LOOP3Z:CLR A
MOVC A,@A+DPTR
MOV P2,A
INC DPTR
JNB P0.3,LOOP4Z ;是否提速
MOV R5,#10
ACALL DELAY
LOOP4Z:MOV R5,#1
ACALL DELAY
DJNZ R2,LOOP3Z
AJMP MAINZ
MAINX: MOV R4,#04H ;设置步进电动机运行方式四拍
LOOP: JB P0.2,LOOP ;启停按钮是否按下
JB P0.1,POS ;是否为正转
AJMP NEG ;否则为反转
POS:MOV DPTR,#TABLE1 ;正转
LOOP1:CLR A
MOVC A,@A+DPTR
MOV P1,A
INC DPTR
JNB P0.0,LOOP2 ;是否提速
MOV R5,#2
ACALL DELAY
LOOP2:MOV R5,#1
ACALL DELAY
DJNZ R4,LOOP1
AJMP MAINX
NEG: MOV DPTR,#TABLE2;反转
LOOP3:CLR A
MOVC A,@A+DPTR
MOV P1,A
INC DPTR
JNB P0.0,LOOP4 ;是否提速
MOV R5,#10
ACALL DELAY
LOOP4:MOV R5,#1
ACALL DELAY
DJNZ R4,LOOP3
AJMP MAINX
TABLE1:DB 03H,06H,0CH,09H
TABLE2:DB 03H,09H,0CH,06H
DELAY:MOV R7,#200
NOP
DEL1: MOV R6,#123
DEL2: DJNZ R6,DEL2
DJNZ R7,DEL1
DJNZ R5,DELAY ;延时[1+(1+1+2*123+2*200+2]*R5 um
即0.5s实现30r/min或0.05s实现300r/min
RET
END
|