完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
这是一个步进电机的程序 想要添加光电开关控制步进电机转和停 应该怎么办 求助
EXTRN Display8:NEAR, SCAN_KEY:NEAR IO8259_0 EQU 0F000H ; IO8259_1 EQU 0F001H ; Con_8253 EQU 0E003H ;8353控制字端口地址 T0_8253 EQU 0E000H ;8253计数器0的端口地址 IO8255_Con EQU 0D003H ;8255控制字端口地址 IO8255_PC EQU 0D002H ;8255PC端口地址 .STACK 100 .DATA StepControl DB 0 ;下一次送给步进电机的值 buffer DB 8 DUP(0) ;显示缓冲区,8个字节 buffer1 DB 8 DUP(0) ;显示缓冲区,8个字节 SpeedNo DB 0 ;选择哪一级速度 StepDelay DB 0 ;转动一步后,延时常数 StartStepDelay DB 0;若选择速度过快,延时由长到短,最终使用对应延时常数 StartStepDelay1 DB 0 ;StartStepDelay bFirst DB 0 ;有没有转动过步进电机 bClockwise DB 0 ; =1 顺时针方向 =0 逆时针方向转动 bNeedDisplay DB 0 ;已转动一步,需要显示新步数 StepCount DW 0 ;需要转动的步数 StepDelayTab: DB 250,125,83,62,50,42,36,32,28,25,22,21 .CODE START: MOV AX,@DATA MOV DS,AX MOV ES,AX NOP MOV bFirst,1 ;有没有转动过步进电机 MOV bClockwise,1 ;顺时针方向 MOV StepControl,33H ;下一次送给步进电机的值 MOV SpeedNo,5 ;第五级速度 CALL Init8255 ;初始化8255 CALL Init8253 ;初始化8253 CALL Init8259 ;初始化8259 CALL WriIntver MOV buffer,0 ;显示缓冲器初始化 MOV buffer+1,0 MOV buffer+2,0 MOV buffer+3,0 MOV buffer+4,10H MOV AL,SpeedNo MOV buffer+5,AL MOV buffer+6,10H MOV buffer+7,0 STAR2: LEA SI,buffer LEA DI,buffer1 MOV CX,8 REP MOVSB LEA SI,buffer1 CALL Display8 STAR3: CALL Scan_Key JB STAR5 CMP bNeedDisplay,0 JZ STAR3 MOV bNeedDisplay,0 CALL Step_SUB_1 JMP STAR2 STAR5: CLI ;终止步进电机转动 CMP AL,10 JNB STAR1 MOV AH,buffer+2 MOV buffer+3,AH MOV AH,buffer+1 MOV buffer+2,AH MOV AH,buffer MOV buffer+1,AH MOV buffer,AL JMP STAR2 STAR1: CMP AL,14 JNB STAR3 LEA SI,DriverTab SUB AL,10 SHL AL,1 XOR AH,AH MOV BX,AX JMP CS:[SI+BX] DriverTab: DW Direction ;转动方向 DW Speed_up ;提高转速 DW Speed_Down ;降低转速 DW Exec ;步进电机根据方向、转速、步数开始转动 Direction: CMP bClockwise,0 JZ Clockwise MOV bClockwise,0 MOV buffer+7,1 AntiClockwise: CMP bFirst,0 JZ AntiClockwise1 MOV StepControl,91H JMP Direction1 AntiClockwise1: MOV AL,StepControl ROR AL,2 MOV StepControl,AL JMP Direction1 Clockwise: MOV bClockwise,1 MOV buffer+7,0 CMP bFirst,0 JZ Clockwise1 MOV StepControl,33H JMP Direction1 Clockwise1: MOV AL,StepControl ROL AL,2 MOV StepControl,AL Direction1: JMP STAR2 Speed_up: MOV AL,SpeedNo CMP AL,11 JZ Speed_up2 Speed_up1: INC AL MOV SpeedNo,AL MOV buffer+5,AL Speed_up2: JMP STAR2 Speed_Down: MOV AL,SpeedNo CMP AL,0 JZ Speed_Down1 DEC AL MOV SpeedNo,AL MOV buffer+5,AL Speed_Down1: JMP STAR2 Exec: MOV bFirst,0 CALL TakeStepCount LEA BX,StepDelayTab MOV AL,SpeedNo XLAT MOV StepDelay,AL CMP AL,50 JNB Exec1 MOV AL,50 Exec1: MOV StartStepDelay,AL MOV StartStepDelay1,AL STI JMP STAR2 TIMER0: PUSH AX PUSH DX DEC StartStepDelay JNZ TIMER0_1 MOV AL,StartStepDelay1 CMP AL,StepDelay JZ TIMER0_2 DEC AL MOV StartStepDelay1,AL TIMER0_2: MOV StartStepDelay,AL MOV AL,StepControl MOV DX,IO8255_PC OUT DX,AL CMP bClockwise,0 JNZ TIMER0_3 ROR AL,1 JMP TIMER0_4 TIMER0_3: ROL AL,1 TIMER0_4: MOV StepControl,AL CMP StepCount,0 JZ TIMER0_1 MOV bNeedDisplay,1 DEC StepCount JNZ TIMER0_1 add sp,8 ;小写部分不允许使用单步、单步进入命令 popf cli pushf sub sp,8 nop TIMER0_1: MOV DX,IO8259_0 MOV AL,20H OUT DX,AL POP DX POP AX IRET Step_SUB_1 PROC NEAR MOV CX,4 LEA BX,buffer Step_SUB_1_1: DEC BYTE PTR [BX] CMP BYTE PTR [BX],0FFH JNZ Step_SUB_1_2 MOV BYTE PTR [BX],9 INC BX LOOP Step_SUB_1_1 Step_SUB_1_2: RET Step_SUB_1 ENDP TakeStepCount PROC NEAR MOV AL,buffer+3 ;转动步数送入StepCount MOV BX,10 MUL BL ADD AL,buffer+2 MUL BL ADD AL,buffer+1 ADC AH,0 MUL BX ADD AL,buffer ADC AH,0 MOV StepCount,AX RET TakeStepCount ENDP Init8255 PROC NEAR ;初始化8255 MOV DX,IO8255_Con MOV AL,80H OUT DX,AL ;8255 PC输出 DEC DX DEC DX MOV AL,0FFH OUT DX,AL ;0FFH->8255 PC RET Init8255 ENDP Init8253 PROC NEAR ;初始化8253 MOV DX,Con_8253 MOV AL,35H OUT DX,AL ;计数器T0设置在模式2状态,BCD码计数 MOV DX,T0_8253 MOV AL,10H OUT DX,AL MOV AL,02H OUT DX,AL ;CLK0/210 RET Init8253 ENDP Init8259 PROC NEAR ;初始化8259 MOV DX,IO8259_0 MOV AL,13H OUT DX,AL MOV DX,IO8259_1 MOV AL,08H OUT DX,AL MOV AL,09H OUT DX,AL MOV AL,0FEH OUT DX,AL RET Init8259 ENDP WriIntver PROC NEAR PUSH ES MOV AX,0 MOV ES,AX MOV DI,20H LEA AX,TIMER0 STOSW MOV AX,CS STOSW POP ES RET WriIntver ENDP END START |
|
相关推荐
1 个讨论
|
|
《DNESP32S3使用指南-IDF版_V1.6》第三十五章 摄像头实验
787 浏览 0 评论
《DNESP32S3使用指南-IDF版_V1.6》第三十章 DHT11数字温湿度传感器
755 浏览 0 评论
850 浏览 0 评论
【敏矽微ME32G070开发板免费体验】之原厂2812测试例程解析
1534 浏览 0 评论
1239 浏览 2 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
12060 浏览 31 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-29 13:17 , Processed in 0.526353 second(s), Total 40, Slave 32 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号