单片机控制步进电机
设计一个步进电机控制器,要求1.:在速度模式下用四个按键控制电机的启动/停止、加速、减速、反转控制;2:在位移模式下,每按一次按键,电机转动90度。注:步进电机为四相电机...
设计一个步进电机控制器,要求
1.:在速度模式下用四个按键控制电机的启动/停止、加速、减速、反转控制;
2:在位移模式下,每按一次按键,电机转动90度。
注:步进电机为四相电机,用ULN2003作驱动芯片。
本人菜鸟,求高手给程序!
有没有给个C的啊? 展开
1.:在速度模式下用四个按键控制电机的启动/停止、加速、减速、反转控制;
2:在位移模式下,每按一次按键,电机转动90度。
注:步进电机为四相电机,用ULN2003作驱动芯片。
本人菜鸟,求高手给程序!
有没有给个C的啊? 展开
4个回答
展开全部
ZHENG EQU 30H
FAN EQU 31H
NO EQU 32H
AS EQU 33H
SS EQU 34H
ORG 00H
AJMP MAIN
ORG 03H
AJMP SUB_INT0
ORG 30H
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
CLR ZHENG
CLR FAN
CLR NO
CLR AS
CLR SS
MOV R1,#20H
MOV A,@R1
MOV R5,A
MOV IE,#10000001B
SETB IT0
MOV R0,#0FH
LOOP: JNB ZHENG,LP
CALL GO
LP: JNB FAN,LOOP
CALL BACK
AJMP LOOP
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(中断)
SUB_INT0:
SCAN: MOV A,P0
CPL A
ANL A,#00011111B
JNZ SCAN1
AJMP SCAN
SCAN1: CALL DELAY1
MOV A,P0
CPL A
ANL A,#00011111B
JZ SCAN
CALL RDKEY
RETI
RDKEY: MOV A,P0
JNB ACC.0,STOP
JNB ACC.2,REV
JNB ACC.1,FOR
JNB ACC.3,ADDSPEED
JNB ACC.4,SUBSPEED
STOP: SETB NO
RET
FOR: SETB ZHENG
RET
REV: SETB FAN
RET
ADDSPEED:SETB AS
RET
SUBSPEED:SETB SS
RET
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(正转)
GO: CLR ZHENG
CLR FAN
CLR NO
CLR AS
CLR SS
INC R0
MOV A,R0
CJNE A,#18H,GO2
MOV R0,#10H
GO2: MOV P2,@R0
MOV A,@R1
MOV R5,A
CALL DELAY
JB NO,RETURN
JB ZHENG,RETURN
JB FAN,RETURN
JNB SS,GO3
CALL JIAN
GO3: JNB AS,GO4
CALL JIA
GO4: AJMP GO
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(反转)
BACK: CLR ZHENG
CLR FAN
CLR NO
CLR AS
CLR SS
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
CALL DELAY
JB NO,RETURN
JB ZHENG,RETURN
JB FAN,RETURN
JNB AS,BACK3
CALL JIA
BACK3: JNB SS,BACK4
CALL JIAN
BACK4: AJMP BACK
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(加速)
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
RETURN: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
FAN EQU 31H
NO EQU 32H
AS EQU 33H
SS EQU 34H
ORG 00H
AJMP MAIN
ORG 03H
AJMP SUB_INT0
ORG 30H
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
CLR ZHENG
CLR FAN
CLR NO
CLR AS
CLR SS
MOV R1,#20H
MOV A,@R1
MOV R5,A
MOV IE,#10000001B
SETB IT0
MOV R0,#0FH
LOOP: JNB ZHENG,LP
CALL GO
LP: JNB FAN,LOOP
CALL BACK
AJMP LOOP
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(中断)
SUB_INT0:
SCAN: MOV A,P0
CPL A
ANL A,#00011111B
JNZ SCAN1
AJMP SCAN
SCAN1: CALL DELAY1
MOV A,P0
CPL A
ANL A,#00011111B
JZ SCAN
CALL RDKEY
RETI
RDKEY: MOV A,P0
JNB ACC.0,STOP
JNB ACC.2,REV
JNB ACC.1,FOR
JNB ACC.3,ADDSPEED
JNB ACC.4,SUBSPEED
STOP: SETB NO
RET
FOR: SETB ZHENG
RET
REV: SETB FAN
RET
ADDSPEED:SETB AS
RET
SUBSPEED:SETB SS
RET
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(正转)
GO: CLR ZHENG
CLR FAN
CLR NO
CLR AS
CLR SS
INC R0
MOV A,R0
CJNE A,#18H,GO2
MOV R0,#10H
GO2: MOV P2,@R0
MOV A,@R1
MOV R5,A
CALL DELAY
JB NO,RETURN
JB ZHENG,RETURN
JB FAN,RETURN
JNB SS,GO3
CALL JIAN
GO3: JNB AS,GO4
CALL JIA
GO4: AJMP GO
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(反转)
BACK: CLR ZHENG
CLR FAN
CLR NO
CLR AS
CLR SS
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
CALL DELAY
JB NO,RETURN
JB ZHENG,RETURN
JB FAN,RETURN
JNB AS,BACK3
CALL JIA
BACK3: JNB SS,BACK4
CALL JIAN
BACK4: AJMP BACK
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(加速)
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
RETURN: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
德晟智能
2024-09-04 广告
2024-09-04 广告
应用优势舵机对比伺服电机,步进电机有哪些应用优势?用场景做示例德晟智能科技有限公司今天就带大家来看看在讲这个问题之前,先简单介绍一下舵机、伺服电机、步进电机是什么以及它们优缺点。伺服电机是一个电机系统,它包含电机、传感器和控制器。直流无刷电...
点击进入详情页
本回答由德晟智能提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询