单片机控制步进电机正反转以及加速减速的程序
电路图所在位置:
http://hi.baidu.com/tianhj2001/album/item/c0dc7d4fc718aed7d1c86a98.html;文件名:DJ15-4.ASM
;程序功能:开关控制步进电机正反转
K1 EQU P3.2
K2 EQU P3.3
K3 EQU P3.4
STOP: MOV P0, #0FFH
LOOP: JNB K1, Z_M2
JNB K2, F_M2
JNB K3, STOP1
JMP LOOP
;-----------------------------
STOP1: ACALL DELAY
JNB K3, $
ACALL DELAY
JMP STOP
Z_M2: ACALL DELAY
JNB K1, $
ACALL DELAY
JMP Z_M
F_M2: ACALL DELAY
JNB K2, $
ACALL DELAY
JMP F_M
;---------------------------
Z_M: MOV R0,#00H
Z_M1: MOV A, R0
MOV DPTR, #TABLE
MOVC A,@A+DPTR
JZ Z_M
MOV P0,A
JNB K3, STOP1
JNB K2, F_M2
ACALL DELAY
INC R0
JMP Z_M1
RET
;-----------------------------
F_M: MOV R0,#05H
F_M1: MOV A, R0
MOV DPTR, #TABLE
MOVC A,@A+DPTR
JZ F_M
MOV P0,A
JNB K3, STOP1
JNB K1, Z_M2
ACALL DELAY
INC R0
JMP F_M1
RET
;-----------------------------
DELAY: MOV R1,#40
D1: MOV R2,#248
DJNZ R2,$
DJNZ R1,D1
RET
;-----------------------------
TABLE: DB 0FCH, 0F9H, 0F3H, 0F6H
DB 00
DB 0F7H, 0F3H, 0FBH, 0F9H
DB 0FDH, 0FCH, 0FEH, 0F6H
DB 00
;-------------------------------
END
本回答被网友采纳