完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
步进电机控制系统
设计一个开环步进电机控制系统。使得步进电机能够正常运转。并能实现启停、正反转、调速控制。以及显示速度。 2.设计要求如下: ①硬件测试通过。接线完成。三个芯片分别测试通过。步进电机能够正常运转。 ②中断方式的转动。 ③启停。按KK1+键控制步进电机的启动。按KK2+键控制步进电机的停止。 ④正反转。开关K7控制步进电机的正反转。当K7向下拨时,电机正转(顺时针);向上拨时,电机反转(逆时针)。 ⑤在LED数码管上显示速度编号。K0对应1挡、K1对应2挡,其余类推。 ⑥调速。开关K6~K0分别控制电机的转速:K0向上拨时,得到最低转速,…… K6向上拨时,得到最高转速。步进电机转速分为7级,依次是30 、60、90、120、150、180、210 (r/min)。 1.步进电机工作原理 注意:步进电机不使用时请断开连接器,以免误操作使电机过热损坏。 2.硬件接线图 ①8255与系统总线的接线图 ②8254与系统总线的接线图 ③8259的接线图 上述步骤完成后按以下步骤改线,完成步进电机控制系统的接线。 PA口接8个开关。 PB口接步进电机。 PC口接数码管。数码管的COM端接地。 OUT1接L0的连线,改到MIR6上。 3.端口地址说明 五、软件设计 1.R变量和M变量说明 定义SWITCH,通过判断k0-k7的输入调用相对应的功能 定义DELAY实现延迟 定义CLKWISE,REVROT实现正反转通过判断语句执行相应代码 2.程序说明 MIR6模块实现中断转动 MIR7模块实现步进电机启动 SIR1模块实现步进电机停止 六、源程序清单 1.参考程序 P8255A EQU 0600H P8255B EQU 0602H P8255C EQU 0604H P8255M EQU 0606H DATA SEGMENT TABLE1 DB 01H,03H,02H,06H,04H,0CH,08H,09H TABLE2 DB 01H,03H,02H,06H,04H,0CH,08H,09H LEDCODE DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H ;0--7的显示代码 DB 7FH,6FH,77H,7CH,39H,5EH,79H,71H ;8--F的显示代码 TIMEP DW 03E8H ;延时子程序时间参数 DCODE DB 3FH ;数码管显示代码 DATA ENDS SSTACK SEGMENT STACK DW 256 DUP(?) SSTACK ENDS CODE SEGMENT ASSUME CS:CODE, SS:SSTACK, DS:DATA START: MOV AX, DATA MOV DS, AX MAIN: MOV AL, 90H ; 控制B口工作于方式0,输出 MOV DX, P8255M OUT DX, AL A1: MOV BX, OFFSET TABLE1 MOV CX, 0008H A2: MOV AL,[BX] MOV DX, P8255B ; 写B口 OUT DX, AL CALL DALLY ; 控制步进电机的转速 INC BX LOOP A2 JMP A1 DALLY: PUSH CX MOV CX,8000H A3: PUSH AX POP AX LOOP A3 POP CX RET CODE ENDS END START 2.最终程序清单 TIMER0 EQU 06C0H ;IOY3 TIMER1 EQU 06C2H TIMER2 EQU 06C4H TIMERM EQU 06C6H P8255A EQU 0600H ;IOY0 P8255B EQU 0602H P8255C EQU 0604H P8255M EQU 0606H ;--------------------------------------------------------------- DATA SEGMENT DISCODE DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H ;0--7的显示代码 DB 7FH,6FH,77H,7CH,39H,5EH,79H,71H ;8--F的显示代码 DECIMAL DB 00H,00H,00H,00H,00H,00H,0CCH,0CCH ;十进制数,查表用下标 VRAM DB 00H,00H,00H,00H,00H,00H,00H,00H ;动态显示代码缓冲 LOCATN DB 00H,00H,00H,00H,00H,00H,00H,00H ;动态显示位置控制 TIMEP DW 03E8H ;延时子程序时间参数 DCODE DB 3FH ;数码管显示代码 HOUR DB 12 ;小时 MINUTE DB 34 ;分钟 SECOND DB 50 ;秒 COUNT DB 100 CLKSTA DB 00000001B ;步进电机节拍状态 DATA ENDS SSTACK SEGMENT PARA STACK 'STACK' DW 32 DUP(?) SSTACK ENDS CODE SEGMENT ASSUME CS:CODE, DS:DATA,SS: SSTACK START: MOV AX,DATA MOV DS,AX ;--------------------- ;8255初始化 ;--------------------- INITA: MOV DX, P8255M MOV AL, 90H OUT DX, AL MOV DX, P8255B MOV AL, 0FFH ;防止步进电机过热 OUT DX, AL ;--------------------- ;中断芯片 ;--------------------- INITB: PUSH DS MOV AX,0000H MOV DS,AX MOV AX,OFFSET MIR7 MOV SI,003CH MOV [SI],AX MOV AX,CS MOV SI,003EH MOV [SI],AX MOV AX,OFFSET MIR6 MOV SI,0038H MOV [SI],AX MOV AX,CS MOV SI,003AH MOV [SI],AX MOV AX, OFFSET SIR1 MOV SI, 00C4H MOV [SI], AX MOV AX, CS MOV SI, 00C6H MOV [SI], AX CLI POP DS ;--------------------- ;主片 ;--------------------- MOV AL,11H OUT 20H,AL ;ICW1 MOV AL,08H OUT 21H,AL ;ICW2 MOV AL,04H OUT 21H,AL ;ICW3 MOV AL,01H OUT 21H,AL ;ICW4 ;--------------------- ;初始化从片8259 ;--------------------- MOV AL, 11H OUT 0A0H, AL ;ICW1 MOV AL, 30H OUT 0A1H, AL ;ICW2 MOV AL, 02H OUT 0A1H, AL ;ICW3 MOV AL, 01H OUT 0A1H, AL ;ICW4 ;--------------------------------------------------------------- MOV AL, 0FDH ;OCW1 = 1111 1101B OUT 0A1H,AL MOV AL,2BH ;OCW1 = 00101011B OUT 21H,AL STI ;--------------------- ;定时器芯片 ;--------------------- INITC: MOV DX, TIMERM ;8254控制字 MOV AL, 36H ;计数器0,方式3 OUT DX, AL MOV DX, TIMER0 MOV AX, 500 OUT DX, AL MOV AL, AH OUT DX, AL MOV AL, 76H ;计数器1,方式3 OUT DX, AL MOV DX, TIMER1 MOV AX, 500 OUT DX, AL MOV AL, AH OUT DX, AL ;--------------------- ; 8255初始化 ;--------------------- INITD: NOP ;--------------------------------------------------------------- BEGIN: NOP AA2: CALL SWITCH CALL TIMEP1 CALL DISPLY JMP AA2 ;--------------------------------------------------------------- MIR7 PROC NEAR PUSH AX PUSH DX MOV AX,0137H INT 10H ;显示字符7 MOV AX,0120H INT 10H MOV AL, 2BH ;OCW1 = 00101011B OUT 21H,AL MOV AL,20H OUT 20H,AL POP DX POP AX IRET MIR7 ENDP ;--------------------------------------------------------------- MIR6 PROC NEAR PUSH AX PUSH DX MOV AX,0136H INT 10H ;显示字符6 MOV AX,0120H INT 10H MOV DX, 0600H ;PA IN AL, DX TEST AL,80H JZ ABCD CALL FCLKWISE JMP FINE ABCD: CALL CLKWISE FINE: MOV AL,20H MOV AL,20H OUT 20H,AL POP DX POP AX IRET MIR6 ENDP SIR1 PROC NEAR PUSH AX PUSH DX MOV AX,0131H INT 10H ;显示字符1 MOV AX,0120H INT 10H MOV AL,6BH ;OCW1 = 01101011B OUT 21H,AL MOV AL, 20H OUT 0A0H, AL OUT 20H, AL POP DX POP AX IRET SIR1 ENDP ;--------------------- ;子程序 ;--------------------- DELAY: PUSH SI PUSH CX MOV SI, 00FFH D11: MOV CX, 00FFH D22: LOOP D22 DEC SI JNZ D11 ;延时结束 POP CX POP SI RET DISPLY0 PROC NEAR ; PUSH AX PUSH DX MOV DX,P8255B MOV AL,01H OUT DX,AL POP DX POP AX RET DISPLY0 ENDP DISPLY1 PROC NEAR ; PUSH AX PUSH DX MOV DX,P8255B MOV AL,03H OUT DX,AL POP DX POP AX RET DISPLY1 ENDP DISPLY2 PROC NEAR ; PUSH AX PUSH DX MOV DX,P8255B MOV AL,02H OUT DX,AL POP DX POP AX RET DISPLY2 ENDP DISPLY3 PROC NEAR ; PUSH AX PUSH DX MOV DX,P8255B MOV AL,06H OUT DX,AL POP DX POP AX RET DISPLY3 ENDP DISPLY4 PROC NEAR ; PUSH AX PUSH DX MOV DX,P8255B MOV AL,04H OUT DX,AL POP DX POP AX RET DISPLY4 ENDP DISPLY5 PROC NEAR ; PUSH AX PUSH DX MOV DX,P8255B MOV AL,0CH OUT DX,AL POP DX POP AX RET DISPLY5 ENDP DISPLY6 PROC NEAR ; PUSH AX PUSH DX MOV DX,P8255B MOV AL,08H OUT DX,AL POP DX POP AX RET DISPLY6 ENDP DISPLY7 PROC NEAR ; PUSH AX PUSH DX MOV DX,P8255B MOV AL,09H OUT DX,AL POP DX POP AX RET DISPLY7 ENDP SWITCH PROC NEAR ;开关控制档位 PUSH AX PUSH DX PUSH CX MOV DX,P8255A IN AL,DX TEST AL,00000001B JNZ K1 TEST AL,00000010B JNZ K2 TEST AL,00000100B JNZ K3 TEST AL,00001000B JNZ K4 TEST AL,00010001B JNZ K5 TEST AL,00100001B JNZ K6 TEST AL,01000001B JNZ K7 K1: MOV AX,00E0H MOV CX,06H JMP DONE2 K2: MOV AX,0070H MOV CX,5BH JMP DONE2 K3: MOV AX,003AH MOV CX,4FH JMP DONE2 K4: MOV AX,001DH MOV CX,66H JMP DONE2 K5: MOV AX,000EH MOV CX,6DH JMP DONE2 K6: MOV AX,0006H MOV CX,7DH JMP DONE2 K7: MOV AX,0002H MOV CX,07H JMP DONE2 DONE2: MOV TIMEP,AX MOV DCODE,CL POP CX POP DX POP AX RET SWITCH ENDP TIMEP1 PROC NEAR PUSH AX PUSH DX MOV AX,TIMEP MOV DX,TIMER0 OUT DX,AL MOV AL,AH OUT DX,AL POP DX POP AX RET TIMEP1 ENDP DISPLY PROC NEAR ;数码管显示 PUSH AX PUSH DX MOV AL,DCODE MOV DX,P8255C OUT DX,AL POP DX POP AX RET DISPLY ENDP ;--------------------- ;正转 ;--------------------- CLKWISE PROC NEAR PUSH AX PUSH DX MOV AL,CLKSTA TEST AL,01H JNZ CK0 TEST AL,02H JNZ CK1 TEST AL,04H JNZ CK2 TEST AL,08H JNZ CK3 TEST AL,10H JNZ CK4 TEST AL,20H JNZ CK5 TEST AL,40H JNZ CK6 TEST AL,80H JNZ CK7 MOV AL,01H JMP CLKDONE CK0: CALL DISPLY0 JMP CLKDONE CK1: CALL DISPLY1 JMP CLKDONE CK2: CALL DISPLY2 JMP CLKDONE CK3: CALL DISPLY3 JMP CLKDONE CK4: CALL DISPLY4 JMP CLKDONE CK5: CALL DISPLY5 JMP CLKDONE CK6: CALL DISPLY6 JMP CLKDONE CK7: CALL DISPLY7 JMP CLKDONE CLKDONE: NOP NOP ROL CLKSTA,1 POP DX POP AX RET CLKWISE ENDP ;--------------------- ;反转 ;--------------------- FCLKWISE PROC NEAR PUSH AX PUSH DX MOV AL,CLKSTA TEST AL,01H JNZ FCK7 TEST AL,02H JNZ FCK6 TEST AL,04H JNZ FCK5 TEST AL,08H JNZ FCK4 TEST AL,10H JNZ FCK3 TEST AL,20H JNZ FCK2 TEST AL,40H JNZ FCK1 TEST AL,80H JNZ FCK0 MOV AL,01H JMP FCLKDONE FCK0: CALL DISPLY0 JMP FCLKDONE FCK1: CALL DISPLY1 JMP FCLKDONE FCK2: CALL DISPLY2 JMP FCLKDONE FCK3: CALL DISPLY3 JMP FCLKDONE FCK4: CALL DISPLY4 JMP FCLKDONE FCK5: CALL DISPLY5 JMP FCLKDONE FCK6: CALL DISPLY6 JMP FCLKDONE FCK7: CALL DISPLY7 JMP FCLKDONE FCLKDONE: NOP NOP ROL CLKSTA,1 POP DX POP AX RET FCLKWISE ENDP |
|
|
|
只有小组成员才能发言,加入小组>>
2355 浏览 0 评论
8610 浏览 4 评论
36329 浏览 18 评论
4959 浏览 0 评论
24035 浏览 34 评论
1299浏览 2评论
1528浏览 1评论
1906浏览 1评论
1360浏览 0评论
1793浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-10-31 20:18 , Processed in 1.178730 second(s), Total 79, Slave 62 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号