关于单片机控制步进电机$NOMOD51P0 DATA 80HP1 DATA 90H K1 EQU P0.0K2 EQU P0.1K3 EQU P0.2ORG 0000HLJMP MAINMAIN:MOV SP,50HSTOP:MOV P1,#0FFH LOOP:JNB K1,MZZ2 JNB K2,MFZ2 JNB K3,STOP1 JMP LOOP STOP1:ACALL DELAY JNB K3,$ACALL DELAYJMP STOPMZZ2:A
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/28 19:15:36
关于单片机控制步进电机$NOMOD51P0 DATA 80HP1 DATA 90H K1 EQU P0.0K2 EQU P0.1K3 EQU P0.2ORG 0000HLJMP MAINMAIN:MOV SP,50HSTOP:MOV P1,#0FFH LOOP:JNB K1,MZZ2 JNB K2,MFZ2 JNB K3,STOP1 JMP LOOP STOP1:ACALL DELAY JNB K3,$ACALL DELAYJMP STOPMZZ2:A
关于单片机控制步进电机
$NOMOD51
P0 DATA 80H
P1 DATA 90H
K1 EQU P0.0
K2 EQU P0.1
K3 EQU P0.2
ORG 0000H
LJMP MAIN
MAIN:MOV SP,50H
STOP:MOV P1,#0FFH
LOOP:JNB K1,MZZ2
JNB K2,MFZ2
JNB K3,STOP1
JMP LOOP
STOP1:ACALL DELAY
JNB K3,$
ACALL DELAY
JMP STOP
MZZ2:ACALL DELAY
JNB K1,$
ACALL DELAY
JMP MZZ
MFZ2:ACALL DELAY
JNB K2,$
ACALL DELAY
JMP MFZ
MZZ:MOV R0,#00H
MZZ1:MOV A,R0
MOV DPTR,#TABLE
MOVC A,@A+DPTR
JZ MZZ2
MOV P1,A
JNB K3,STOP1
JNB K2,MFZ2
ACALL DELAY
INC R0
JMP MZZ1
RET
MFZ:MOV R0,#05
MFZ1:MOV A,R0
MOV DPTR,#TABLE
MOVC A,@A+DPTR
JZ MFZ
MOV P1,A
JNB K3,STOP1
JNB K1,MZZ2
ACALL DELAY
INC R0
JMP MFZ1
RET
DELAY:MOV R5,#40
DEL1:MOV R6,#248
DJNZ R6,$
DJNZ R5,DEL1
RET
TABLE:DB 0FCH,0F9H,0F3H,0F6H
DB 00H
DB 0F7H,0F3H,0FBH,09H
DB 0FDH,0FCH,0FEH,0F6H
DB 00H
END
有这样一段程序,请教高手帮改一些指令,程序可以运行就行.
这段程序是可以运行,老师要求我们在这个程序的基础上改动一下指令,使程序一样可以运行的就行,问题就是一定要改动一些指令!
关于单片机控制步进电机$NOMOD51P0 DATA 80HP1 DATA 90H K1 EQU P0.0K2 EQU P0.1K3 EQU P0.2ORG 0000HLJMP MAINMAIN:MOV SP,50HSTOP:MOV P1,#0FFH LOOP:JNB K1,MZZ2 JNB K2,MFZ2 JNB K3,STOP1 JMP LOOP STOP1:ACALL DELAY JNB K3,$ACALL DELAYJMP STOPMZZ2:A
编译了一下,这个程序可以运行.
楼主发现什么错误了?
----------------------------
按照楼主提示,进行了简单的修改.
调整了两小段程序的位置,这样就可以删除两个"JMP"指令;
原程序中,有两个"RET",是没有用的,也可以删除;
这四行可删的指令,我在前面加上了“;”作了标记.
另外,原程序中,少了个井号#.
程序如下:
; P0 DATA 80H
; P1 DATA 90H
K1 EQU P0.0
K2 EQU P0.1
K3 EQU P0.2
ORG 0000H
LJMP MAIN
MAIN:MOV SP,#50H ;原文在这里中少了个井号"#"
STOP:MOV P1,#0FFH
LOOP:JNB K1,MZZ2
JNB K2,MFZ2
JNB K3,STOP1
JMP LOOP
;------------------------------------
STOP1:ACALL DELAY
JNB K3,$
ACALL DELAY
JMP STOP
;------------------------------------
MZZ2:ACALL DELAY
JNB K1,$
ACALL DELAY
; JMP MZZ
MZZ:MOV R0,#00H
MZZ1:MOV A,R0
MOV DPTR,#TABLE
MOVC A,@A+DPTR
JZ MZZ2
MOV P1,A
JNB K3,STOP1
JNB K2,MFZ2
ACALL DELAY
INC R0
JMP MZZ1
; RET
;------------------------------------
MFZ2:ACALL DELAY
JNB K2,$
ACALL DELAY
; JMP MFZ
MFZ:MOV R0,#05
MFZ1:MOV A,R0
MOV DPTR,#TABLE
MOVC A,@A+DPTR
JZ MFZ
MOV P1,A
JNB K3,STOP1
JNB K1,MZZ2
ACALL DELAY
INC R0
JMP MFZ1
; RET
;------------------------------------
DELAY:MOV R5,#40
DEL1:MOV R6,#248
DJNZ R6,$
DJNZ R5,DEL1
RET
;------------------------------------
TABLE:DB 0FCH,0F9H,0F3H,0F6H
DB 00H
DB 0F7H,0F3H,0FBH,09H
DB 0FDH,0FCH,0FEH,0F6H
DB 00H
END
请问一下你的$ 标号在哪里,是第一个符号吗?我想你先改一下,留出一个空格来,在调试一下,看看
ZHENG EQU 28H.0
FAN EQU 28H.1
NO EQU 28H.2
AS EQU 28H.3
SS EQU 28H.4
LED_STOP BIT P1.0
LED_FWD BIT P1.1
LED_REV BIT P1.2
ORG 0000H
AJMP MAIN...
全部展开
ZHENG EQU 28H.0
FAN EQU 28H.1
NO EQU 28H.2
AS EQU 28H.3
SS EQU 28H.4
LED_STOP BIT P1.0
LED_FWD BIT P1.1
LED_REV BIT P1.2
ORG 0000H
AJMP MAIN
ORG 0003H
AJMP INTX0
ORG 0030H
MAIN:MOV 10H,#01H
MOV 11H,#03H
MOV 12H,#02H
MOV 13H,#06H
MOV 14H,#04H
MOV 15H,#0CH
MOV 16H,#08H
MOV 17H,#09H
MOV 20H,#50
MOV 21H,#25
MOV 22H,#10
MOV 23H,#05
MOV 28H,#0
MOV R1,#20H
MOV P1,#0F0H
SETB LED_STOP
MOV A,@R1
MOV R5,A
MOV IE,#10000001B
SETB IT0
MOV R0,#0FH
LOOP: JNB ZHENG,LP
CLR LED_STOP
ACALL GO
LP: JNB FAN,LOOP
CLR LED_STOP
ACALL BACK
AJMP LOOP
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(中断)
INTX0:
SCAN: MOV A,P0
CPL A
ANL A,#00011111B
JNZ SCAN1
AJMP SCAN
SCAN1: ACALL DELAY1
MOV A,P0
CPL A
ANL A,#00011111B
JZ SCAN
ACALL RDKEY
RETI
RDKEY:MOV A,P0
CJNE A,#0FEH,STOP
SETB NO
STOP:CJNE A,#0FDH,FOR
SETB ZHENG
FOR:CJNE A,#0FBH,REV
SETB FAN
REV:CJNE A,#0F7H,ADDSPEED
SETB AS
ADDSPEED:CJNE A,#0EFH,SUBSPEED
SETB SS
SUBSPEED:RET
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(正转)
GO: SETB LED_FWD
CLR LED_REV
MOV 28H,#0
INC R0
MOV A,R0
CJNE A,#18H,GO2
MOV R0,#10H
GO2: MOV P2,@R0
MOV A,@R1
MOV R5,A
ACALL DELAY
JB NO,RETURN1
JB ZHENG,RETURN
JB FAN,RETURN
JNB SS,GO3
ACALL JIAN
GO3: JNB AS,GO4
ACALL JIA
GO4: AJMP GO
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(反转)
BACK:
SETB LED_REV
CLR LED_FWD
MOV 28H,#0
DEC R0
MOV A,R0
CJNE A,#0EH,TT
MOV R0,#17H
SJMP BACK2
TT: CJNE A,#0FH,BACK2
MOV R0,#17H
BACK2: MOV P2,@R0
MOV A,@R1
MOV R5,A
ACALL DELAY
JB NO,RETURN1
JB ZHENG,RETURN
JB FAN,RETURN
JNB AS,BACK3
ACALL JIA
BACK3: JNB SS,BACK4
ACALL JIAN
BACK4: AJMP BACK
RETURN1:SETB LED_STOP
CLR LED_FWD
CLR LED_REV
RETURN:
RET
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(加速)
JIA: MOV A,R1
CJNE A,#23H,JIA1
RET
JIA1: INC R1
RET
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(减速)
JIAN: MOV A,R1
CJNE A,#20H,JIAN1
RET
JIAN1: DEC R1
RET
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(延时)
DELAY:
D1: MOV R6,#50
D2: MOV R7,#150
D3: DJNZ R7,$
DJNZ R6,D2
DJNZ R5,D1
RET
DELAY1: MOV R6,#60
D4: MOV R7,#100
DJNZ R7,$
DJNZ R6,D4
RET
END
收起