51单片机步进电机正反转实验程序
按键控制可以让电机正转或倒转,按键由p0.0-0.3控制
ORG 0000H
AJMP START
ORG 0050H
MAIN: MOV R0,#00H
START: LCALL START0
LCALL DELAY0
JNB P0.0,UPS
JNB P0.1,DWNS
AJMP START
UPS:;LCALL DELAY3
;JNB P0.0,$
;LCALL DELAY3
LCALL START0
LCALL DELAY1
JNB P0.0,UPS
JNB P0.1,START
; AJMP START
AJMP UPS
DWNS:LCALL START0
LCALL DELAY2
JNB P0.0,START
JNB P0.1,DWNS
; AJMP START
AJMP DWNS
START1: MOV R0,#00H
START0: MOV A,R0
MOV DPTR,#TAB
MOVC A,@A+DPTR
JZ START1
MOV P1,A
INC R0
RET
DELAY0: MOV R7,#10
D1: MOV R6,#248
DJNZ R6,$
DJNZ R7,D1
RET
DELAY1: MOV R7,#5
D2: MOV R6,#248
DJNZ R6,$
DJNZ R7,D2
RET
DELAY2: MOV R7,#40
D3: MOV R6,#248
DJNZ R6,$
DJNZ R7,D3
RET
DELAY3: MOV R7,#60
D4: MOV R6,#248
DJNZ R6,$
DJNZ R7,D4
RET
TAB: DB 07H
DB 03H
DB 0BH
DB 09H
DB 0DH
DB 0CH
DB 0EH
DB 06H
DB 00H
END