《微型计算机控制技术课程设计步进电机.doc》由会员分享,可在线阅读,更多相关《微型计算机控制技术课程设计步进电机.doc(10页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、【精品文档】如有侵权,请联系网站删除,仅供学习与交流微型计算机控制技术课程设计步进电机.精品文档.课 程 设 计课程名称 微型计算机控制技术 题目名称_步进电机角度控制(2) 学生学院_ _ 自动化_专业班级_ 学 号 学生姓名_ _指导教师_ 李传芳 _2013 年 06月 28日一、软件设计流程图如下图所示:开始判断键值设定8255A工作方式,A、B口输出,C口PC4PC7输入,PC0PC3输出,故控制字为88H延时驱动电机动作LED显示返回调用延时扫描键盘否是否有键按下 是判断键值二、心得与体会这次的课程设计主要针对键盘及可编程接口芯片8255A的编程,在上机调试过程中由于自己的疏忽及算
2、法的不完善导致了程序不能实现预期的功能,经过一遍又一遍的检查和思考,终于完成了这次课程设计的任务。虽然上机调试的经历是痛苦的,但是期间的细节错误给了我们应有的教训,使我们在以后的学习及工作中尽量避免,对于汇编语言的编程也有了进一步的了解加深了对步进电机的理解和使用技巧,设计中,需要对步进电机进行角度控制,即需要对步进电机的角度进行计算分析,以得到所需的步数。总之,这次课程设计锻炼了我解决问题的能力,激发了我的思考,相信通过这次课程设计对我以后对微机的继续学习及以后的工作会有很大的帮助。任务1 连接数码管显示电路和键盘电路,实现如下表所示的按键控制,并能够左移显示:360AB72F1.2源程序:
3、STACK SEGMENT STACK DB 64 DUP(?)STACK ENDSDATA SEGMENTORG 0030HVAR1 DB 0FCH,0FCH,0FCH,0FCHVAR5 DB OF7H,0FBH,0FDH,0FEHVAR2 DB 0FCH,0FCH,0FCH,0FCH,0FCH,0FCH,0FCH,0FCHVAR3 DB 00H,00H,00H,00H,00H,00H,00H,00HVAR4 DB 00H,00H,00H,00H,00H,00H,00H,00HTABLE1 DB 0FCH,60H,0DAH,0F2H,66H,0B6H,0BEH,0E0H,0FEH,0F6H,
4、0EEH,3EH,9CH,7AH,9EH,8EHDATA ENDSCODE SEGMENT ASSUME CS:CODE,DS:DATASTART: MOV AX,DATA MOV DS,AX MOV AL,88H ;8255初始化 MOV DX,0606H OUT DX,ALSTT: MOV AL,60H MOV DX,0604H OUT DX,ALNEXT: MOV DX,0604H IN AL, DX AND AL,60H CMP AL,60H JNZ KEYABC CALL DISP JMP STT ;.键盘扫描. KEYABC:CALL TIME MOV DX,0604H IN AL
5、,DX AND AL,60H CMP AL,60H ;PC6 PC5 =0110 0000 JNZ KEY JMP STTKEY: MOV AL,0FEH ;扫描PC0口 PC0=0 MOV DX,0604H OUT DX,AL MOV DX,0604H IN AL,DX TEST AL,20H ;检测PC5 JNZ KEY_F CALL KEYA JMP STTKKEY_F: TEST AL,040H ;检测PC6口 JNZ KEY_0 CALL KEYF JMP STTK KEY_0:MOV AL,0FDH ;扫描PC1口, PC1=0 MOV DX,0604H OUT DX,AL MOV
6、 DX,0604H IN AL,DX TEST AL,20H ;检测PC5 JNZ KEY_2 CALL KEY0 JMP STTKKEY_2:TEST AL,040H ;检测PC6口 JNZ KEY_6 CALL KEYF ;否则是按键2 JMP STTK KEY_6:MOV AL,0FBH ;PC2=0 MOV DX,0604H OUT DX,AL MOV DX,0604H IN AL,DX TEST AL,20H ;检测PC5 JNZ KEY_7 CALL KEY6 JMP STTKKEY_7:TEST AL,040H ;检测PC6口 JNZ KEY_3 CALL KEY7 JMP ST
7、TK KEY_3:MOV AL,0F7H PC3=0 MOV DX,0604H OUT DX,AL MOV DX,0604H IN AL,DX TEST AL,20H ;检测PC5 JNZ KEY_B CALL KEY3 JMP STTKKEY_B:TEST AL,040H ;检测PC6口 JNZ KEY_111 CALL KEYBKEY_111:JMP STTK;.数字XIANSHI.KEYA: CMP BH,00H JZ KEYA_1KEYA_1: CALL LP1 MOV AL,0EEH MOV SI,AL MOV AL,0AH MOV DI,AL CALL DISP RET KEYF:
8、 CMP BH,00H JZ KEYE_1 KEYF_1:CALL LP1 MOV AL,8EH MOV SI,AL MOV AL,0FH MOV DI,AL CALL DISP RETKEY0:CMP BH,00H JZ KEY1_1KEY0_1:CALL LP1 MOV AL,0FCH MOV SI,AL MOV AL,00H MOV DI,AL CALL DISP RETKEY2:CMP BH,00H JZ KEYF_1KEY2_1:CALL LP1 MOV AL,0DH MOV SI,AL MOV AL,02H MOV DI,AL CALL DISP RETKEY6:CMP BH,00
9、H JZ KEY7_1KEY6_1:CALL LP1 MOV AL,0BEH MOV SI,AL MOV AL,06H MOV DI,AL CALL DISP RET KEY7:CMP BH,00H JZ KEYA_1KEY7_1:CALL LP1 MOV AL,0E0H MOV SI,AL MOV AL,07H MOV DI,AL CALL DISP RETKEY3:CMP BH,00H JZ KEY8_1 KEY3_1:CALL LP1 MOV AL,0F2H MOV SI,AL MOV AL,03H MOV DI,AL CALL DISP RETKEYB:CMP BH,00H JZ KE
10、YB_1KEYB_1:CALL LP1 MOV AL,3EH MOV SI,AL MOV AL,0BH MOV DI,AL CALL DISP RET LP1: MOV SI,OFFSET VAR1 PUSH AX MOV AL,SI+2 MOV SI+3,AL MOV AL,SI+1 MOV SI+2,AL MOV AL,SI MOV SI+1,AL POP AX MOV SI,AL RET ;.显示.DISP:PUSH DX PUSH CX MOV SI,OFFSET VAR1 MOV DX,0604H MOV AL,11111110B OUT DX,AL MOV DX,0602H MOV
11、 AL,SI+3 OUT DX,AL DEC SI CALL TIME MOV DX,0604H MOV AL,11111101B OUT DX,AL MOV DX,0602H MOV AL,SI+3 OUT DX,AL DEC SI CALL TIME MOV DX,0604H MOV AL,11111011B OUT DX,AL MOV DX,0602H MOV AL,SI+3 OUT DX,AL DEC SI CALL TIME MOV DX,0604H MOV AL,11110111B OUT DX,AL MOV DX,0602H MOV AL,SI+3 OUT DX,AL DEC S
12、I CALL TIME POP AX POP DX RET ;.延时.TIME: PUSH AX PUSH CX MOV CX,0006HTIME1: MOV AX,0100HTIME2: DEC AX JNZ TIME2 LOOP TIME1 POP CX POP AX RET ;.放键测试.STTK: CALL DISP MOV AL,00H MOV DX,0604H OUT DX,AL MOV DX,0604H IN AL,DX AND AL,60H CMP AL,60H JNZ STTK JMP STTCODE ENDS END START任务2 实现:定义键盘按键:5个为数字键:0、
13、1、3、5、9 ;3个功能键:设置SET、清零 CLR、开始START;按键分布如下表所示:0365SET4STARTCLR2.2源程序:STACK SEGMENT STACK DB 100 DUP(?)STACK ENDSDATA SEGMENTVAR1 DB OF7H,0FBH,0FDH,0FEHVAR2 DB 0FCH,0FCH,0FCH,0FCHVAR5 DB 00H,00H,00H,00H,00H,00HTABL DB 0FCH,60H,0DH,0F2H,66H,0B6H,0BEH,0E0H,0FEH,0F6H,0EEH,3EH,9CH,7AH,9EH,8EHTAB_C DW 00H
14、ORG 0100HVAR3 DB 64 DUP(?)ORG 0200HVAR4 DW 64 DUP(?)COUNT DB 00HTABLE DB 08H,18H,10H,30H,20H,60H,40H,48HD_COUNT DB 00HD_TIMES DB 00HDATA ENDSCODE SEGMENT ASSUME CS:CODE,DS:DATASTART: MOV AX,DATA MOV DS,AX PUSH DX MOV AL,88H ;8255初始化 MOV DX,0606H OUT DX,AL MOV BX,0000H MOV COUNT,00H MOV D_COUNT,00H M
15、OV D_TIMES,00HSTT: MOV AL,00H MOV DX,0604H OUT DX,ALNEXT: MOV DX,0604H IN AL, DX AND AL,60H CMP AL,60H JNZ KEYABC CALL DISP JMP STT POP DX ;.键盘扫描. KEYABC:PUSH DXCALL TIME MOV DX,0604H IN AL,DX AND AL,60H CMP AL,60H ;PC6 PC5 =0110 0000 JNZ KEY_5 JMP STT POP DXKEY_5: MOV AL,0FEH ;扫描PC0口 MOV DX,0604H O
16、UT DX,AL MOV DX,0604H IN AL,DX TEST AL,20H ;检测PC5 JNZ KEY_CLR CALL KEY5 ;否则 是按键5 JMP STTKKEY_CLR: TEST AL,40H ;检测PC6口 JNZ KEY_6 CALL KEYCLR JMP STTK KEY_6:MOV AL,0FDH MOV DX,0604H OUT DX,AL MOV DX,0604H IN AL,DX TEST AL,20H ;检测PC5 JNZ KEY_START CALL KEY6 JMP STTKKEY_START:TEST AL,40H ;检测PC6口 JNZ KEY
17、_3 CALL KEYSTART JMP STTK KEY_3:MOV AL,0FBH MOV DX,0604H OUT DX,AL MOV DX,0604H IN AL,DX TEST AL,20H ;检测PC5 JNZ KEY_4 CALL KEY3 JMP STTKKEY_4:TEST AL,40H ;检测PC6口 JNZ KEY_0 CALL KEY4 JMP STTK KEY_0:MOV AL,0F7H MOV DX,0604H OUT DX,AL MOV DX,0604H IN AL,DX TEST AL,20H ;检测PC5 JNZ KEY_SET CALL KEY0 JMP S
18、TTKKEY_SET:TEST AL,40H ;检测PC6口 JNZ KEY_111 CALL KEYSETKEY_111:JMP STTKKEY0:CALL LP1 MOV AL,00H MOV DI,AL MOV AL,0FCH MOV SI,AL CALL DISP RETKEY3: CALL LP1 MOV AL,03H MOV DI,AL MOV AL,0F2H MOV SI,AL CALL DISP RETKEY4: CALL LP1 MOV AL,04H MOV DI,AL MOV AL,66H MOV SI,AL CALL DISP RET KEY5: CALL LP1 MOV
19、 AL,05H MOV DI,AL MOV AL,0B6H MOV SI,AL CALL DISP RETKEY6: CALL LP1 MOV AL,06H MOV DI,AL MOV AL,0BEH MOV SI,AL CALL DISP RETKEYSTART: CMP COUNT,00H JZ STA1 MOV AL,COUNT CBW PUSH AX MOV SI,OFFSET VAR4 MOV DI,OFFSET TABLE MOV DL,00HSTA4: MOV BX,SI MOV AX,SI+2 MOV DH,0FH DIV DH MOV DH,04H MUL DH INC SI
20、 INC SI INC SI INC SI PUSH AXSTA5: POP AX MOV CX,AX PUSH AXSTA2: PUSH DX MOV AL,DI MOV DX,0600H OUT DX,AL POP DX INC DI INC DL CALL DISP1 CALL DALLY1 CMP DL,08H JNZ STA3 MOV DL,00H MOV DI,OFFSET TABLESTA3: LOOP STA2 CALL DISP1 DEC BX JNZ STA5 INC D_COUNT MOV AL,COUNT POP AX CALL DISP1 DEC COUNT JNZ
21、STA4 POP AX CALL DISP1 DEC COUNT JNZ STA4 POP AX MOV COUNT,AL MOV D_COUNT,00H MOV TAB_C,DI MOV CL,DLSTA1: RETKEYSET: LEA SI,VAR2 LEA DI,VAR3 MOV AL,COUNT CBW ADD DI,AX ADD DI,AX ADD DI,AX ADD DI,AX MOV CX,0004HSET1: MOV AL,SI MOV DI,AL INC DI INC SI LOOP SET1 LEA SI,VAR5 MOV DX,0000H MOV DI,OFFSET V
22、AR4 MOV AL,COUNT CBW ADD DI,AX ADD DI,AX ADD DI,AX ADD DI,AX MOV AL,SI MOV DI,AL MOV AL,SI+1 MOV BL,64H MUL BL ADD DX,AX MOV AL,SI+2 MOV CL,0AH MUL BL ADD DX,AX MOV BL,SI+3 CBW ADD AX,DX MOV DI+2,AX MOV CX,0004H LEA SI,VAR2 LEA DI,VAR5SET2: MOV SI,0FCH MOV DI,00H INC SI INC DI LOOP SET2 CALL DISP IN
23、C COUNT RETKEYCLR: CMP COUNT,00H JZ CLR1 MOV DI,TAB_C MOV SI,OFFSET VAR4 MOV DL,CL TEST DL,DL JNZ CLR6 MOV DL,08H MOV DI,OFFSET TABLE MOV AL,07H CBW ADD DI,AXCLR6: DEC DI DEC DLCLR4: MOV BX,SI MOV AX,SI+2 MOV DH,0FH DIV DH MOV DH,04H MUL DH INC SI INC SI INC SI INC SI PUSH AXCLR5: POP AX MOV CX,AX P
24、USH AXCLR2: PUSH DX MOV AL,DI MOV DX,0600H OUT DX,AL POP DX DEC DI DEC DL CALL DALLY TEST DL,DL JNZ CLR3 MOV DL,08H MOV DI,OFFSET TABLE MOV AL,07H CBW ADD DI,AXCLR3: LOOP CLR2 DEC BX JNZ CLR5 MOV AL,COUNT POP AX DEC COUNT JNZ CLR4 MOV COUNT,00HCLR1: MOV CX,0004H LEA SI,VAR3 LEA DI,VAR4CLR7: MOV SI,0
25、FCH MOV DI,00H INC SI INC DI LOOP CLR7 CALL CLRR CALL DISP RETDISP1: PUSH AX PUSH BX PUSH CX PUSH DX PUSH SI PUSH DI MOV D_TIMES,BL MOV AL,D_COUNT CBW MOV BX,OFFSET TABL MOV SI,OFFSET VAR1 MOV DI,OFFSET VAR3 ADD DI,AX ADD DI,AX ADD DI,AX ADD DI,AX MOV AL,SI MOV DX,0604H OUT DX,AL MOV AL,D_TIMES XLAT
26、 MOV DX,0602H OUT DX,AL CALL TIME INC SI INC DI MOV CX,0003HDIR1: MOV AL,SI MOV DX,0604H OUT DX,AL MOV AL,DI MOV DX,0602H OUT DX,AL CALL TIME INC SI INC DI LOOP DIR1 POP DI POP SI POP DX POP CX POP BX POP AX RETLP1: MOV CX,0003H LEA SI,VAR2 LEA DI,VAR5LP2: MOV AL,SI+1 MOV SI,AL MOV AL,DI+1 MOV DI,AL
27、 INC DI INC SI LOOP LP2 RETDISP: LEA SI,VAR1 LEA DI,VAR2 MOV CX,0004HDIR: MOV AL,SI MOV DX,0604H OUT DX,AL MOV AL,DI MOV DX,0602H OUT DX,AL CALL TIME INC SI INC DI LOOP DIR RETCLRR: MOV CX,0004H LEA SI,VAR2 LEA DI,VAR5CLR8:MOV SI,0FCH INC SI LOOP CLR8 RETTIME: PUSH AXPUSH CXMOV CX,0010HTIME1:MOV AX,
28、00300HTIME2:DEC AXJNZ TIME2LOOP TIME1POP CXPOP AXRETDALLY:PUSH CXPUSH AXMOV CX,1000HA6: MOV AX,0010HA7:DEC AXJNZ A7LOOP A6POP AXPOP CXRET DALLY1:PUSH CXPUSH AXMOV CX,0010HAA6: MOV AX,0500HAA7:DEC AXJNZ AA7LOOP AA6POP AXPOP CXRET ;.放键测试. STTK: CALL DISP MOV AL,00H MOV DX,0604H OUT DX,AL MOV DX,0604H IN AL,DX AND AL,60H CMP AL,60H JNZ STTK JMP STT CODE ENDS END START