微型计算机控制技术课程设计步进电机讲解学习.doc
Good is good, but better carries it.精益求精,善益求善。微型计算机控制技术课程设计步进电机-课程设计课程名称微型计算机控制技术题目名称_步进电机角度控制(2)学生学院_自动化_专业班级_学号学生姓名_指导教师_李传芳_2013年06月28日-一、软件设计流程图如下图所示:开始判断键值设定8255A工作方式,A、B口输出,C口PC4PC7输入,PC0PC3输出,故控制字为88H延时驱动电机动作LED显示返回调用延时扫描键盘否是否有键按下是判断键值二、心得与体会这次的课程设计主要针对键盘及可编程接口芯片8255A的编程,在上机调试过程中由于自己的疏忽及算法的不完善导致了程序不能实现预期的功能,经过一遍又一遍的检查和思考,终于完成了这次课程设计的任务。虽然上机调试的经历是痛苦的,但是期间的细节错误给了我们应有的教训,使我们在以后的学习及工作中尽量避免,对于汇编语言的编程也有了进一步的了解加深了对步进电机的理解和使用技巧,设计中,需要对步进电机进行角度控制,即需要对步进电机的角度进行计算分析,以得到所需的步数。总之,这次课程设计锻炼了我解决问题的能力,激发了我的思考,相信通过这次课程设计对我以后对微机的继续学习及以后的工作会有很大的帮助。任务1连接数码管显示电路和键盘电路,实现如下表所示的按键控制,并能够左移显示:360AB72F1.2源程序:STACKSEGMENTSTACKDB64DUP(?)STACKENDSDATASEGMENTORG0030HVAR1DB0FCH,0FCH,0FCH,0FCHVAR5DBOF7H,0FBH,0FDH,0FEHVAR2DB0FCH,0FCH,0FCH,0FCH,0FCH,0FCH,0FCH,0FCHVAR3DB00H,00H,00H,00H,00H,00H,00H,00HVAR4DB00H,00H,00H,00H,00H,00H,00H,00HTABLE1DB0FCH,60H,0DAH,0F2H,66H,0B6H,0BEH,0E0H,0FEH,0F6H,0EEH,3EH,9CH,7AH,9EH,8EHDATAENDSCODESEGMENTASSUMECS:CODE,DS:DATASTART:MOVAX,DATAMOVDS,AXMOVAL,88H;8255初始化MOVDX,0606HOUTDX,ALSTT:MOVAL,60HMOVDX,0604HOUTDX,ALNEXT:MOVDX,0604HINAL,DXANDAL,60HCMPAL,60HJNZKEYABCCALLDISPJMPSTT;.键盘扫描.KEYABC:CALLTIMEMOVDX,0604HINAL,DXANDAL,60HCMPAL,60H;PC6PC5=01100000JNZKEYJMPSTTKEY:MOVAL,0FEH;扫描PC0口PC0=0MOVDX,0604HOUTDX,ALMOVDX,0604HINAL,DXTESTAL,20H;检测PC5JNZKEY_FCALLKEYAJMPSTTKKEY_F:TESTAL,040H;检测PC6口JNZKEY_0CALLKEYFJMPSTTKKEY_0:MOVAL,0FDH;扫描PC1口,PC1=0MOVDX,0604HOUTDX,ALMOVDX,0604HINAL,DXTESTAL,20H;检测PC5JNZKEY_2CALLKEY0JMPSTTKKEY_2:TESTAL,040H;检测PC6口JNZKEY_6CALLKEYF;否则是按键2JMPSTTKKEY_6:MOVAL,0FBH;PC2=0MOVDX,0604HOUTDX,ALMOVDX,0604HINAL,DXTESTAL,20H;检测PC5JNZKEY_7CALLKEY6JMPSTTKKEY_7:TESTAL,040H;检测PC6口JNZKEY_3CALLKEY7JMPSTTKKEY_3:MOVAL,0F7HPC3=0MOVDX,0604HOUTDX,ALMOVDX,0604HINAL,DXTESTAL,20H;检测PC5JNZKEY_BCALLKEY3JMPSTTKKEY_B:TESTAL,040H;检测PC6口JNZKEY_111CALLKEYBKEY_111:JMPSTTK;.数字XIANSHI.KEYA:CMPBH,00HJZKEYA_1KEYA_1:CALLLP1MOVAL,0EEHMOVSI,ALMOVAL,0AHMOVDI,ALCALLDISPRETKEYF:CMPBH,00HJZKEYE_1KEYF_1:CALLLP1MOVAL,8EHMOVSI,ALMOVAL,0FHMOVDI,ALCALLDISPRETKEY0:CMPBH,00HJZKEY1_1KEY0_1:CALLLP1MOVAL,0FCHMOVSI,ALMOVAL,00HMOVDI,ALCALLDISPRETKEY2:CMPBH,00HJZKEYF_1KEY2_1:CALLLP1MOVAL,0DHMOVSI,ALMOVAL,02HMOVDI,ALCALLDISPRETKEY6:CMPBH,00HJZKEY7_1KEY6_1:CALLLP1MOVAL,0BEHMOVSI,ALMOVAL,06HMOVDI,ALCALLDISPRETKEY7:CMPBH,00HJZKEYA_1KEY7_1:CALLLP1MOVAL,0E0HMOVSI,ALMOVAL,07HMOVDI,ALCALLDISPRETKEY3:CMPBH,00HJZKEY8_1KEY3_1:CALLLP1MOVAL,0F2HMOVSI,ALMOVAL,03HMOVDI,ALCALLDISPRETKEYB:CMPBH,00HJZKEYB_1KEYB_1:CALLLP1MOVAL,3EHMOVSI,ALMOVAL,0BHMOVDI,ALCALLDISPRETLP1:MOVSI,OFFSETVAR1PUSHAXMOVAL,SI+2MOVSI+3,ALMOVAL,SI+1MOVSI+2,ALMOVAL,SIMOVSI+1,ALPOPAXMOVSI,ALRET;.显示.DISP:PUSHDXPUSHCXMOVSI,OFFSETVAR1MOVDX,0604HMOVAL,11111110BOUTDX,ALMOVDX,0602HMOVAL,SI+3OUTDX,ALDECSICALLTIMEMOVDX,0604HMOVAL,11111101BOUTDX,ALMOVDX,0602HMOVAL,SI+3OUTDX,ALDECSICALLTIMEMOVDX,0604HMOVAL,11111011BOUTDX,ALMOVDX,0602HMOVAL,SI+3OUTDX,ALDECSICALLTIMEMOVDX,0604HMOVAL,11110111BOUTDX,ALMOVDX,0602HMOVAL,SI+3OUTDX,ALDECSICALLTIMEPOPAXPOPDXRET;.延时.TIME:PUSHAXPUSHCXMOVCX,0006HTIME1:MOVAX,0100HTIME2:DECAXJNZTIME2LOOPTIME1POPCXPOPAXRET;.放键测试.STTK:CALLDISPMOVAL,00HMOVDX,0604HOUTDX,ALMOVDX,0604HINAL,DXANDAL,60HCMPAL,60HJNZSTTKJMPSTTCODEENDSENDSTART任务2实现:定义键盘按键:5个为数字键:0、1、3、5、9;3个功能键:设置SET、清零CLR、开始START;按键分布如下表所示:0365SET4STARTCLR2.2源程序:STACKSEGMENTSTACKDB100DUP(?)STACKENDSDATASEGMENTVAR1DBOF7H,0FBH,0FDH,0FEHVAR2DB0FCH,0FCH,0FCH,0FCHVAR5DB00H,00H,00H,00H,00H,00HTABLDB0FCH,60H,0DH,0F2H,66H,0B6H,0BEH,0E0H,0FEH,0F6H,0EEH,3EH,9CH,7AH,9EH,8EHTAB_CDW00HORG0100HVAR3DB64DUP(?)ORG0200HVAR4DW64DUP(?)COUNTDB00HTABLEDB08H,18H,10H,30H,20H,60H,40H,48HD_COUNTDB00HD_TIMESDB00HDATAENDSCODESEGMENTASSUMECS:CODE,DS:DATASTART:MOVAX,DATAMOVDS,AXPUSHDXMOVAL,88H;8255初始化MOVDX,0606HOUTDX,ALMOVBX,0000HMOVCOUNT,00HMOVD_COUNT,00HMOVD_TIMES,00HSTT:MOVAL,00HMOVDX,0604HOUTDX,ALNEXT:MOVDX,0604HINAL,DXANDAL,60HCMPAL,60HJNZKEYABCCALLDISPJMPSTTPOPDX;.键盘扫描.KEYABC:PUSHDXCALLTIMEMOVDX,0604HINAL,DXANDAL,60HCMPAL,60H;PC6PC5=01100000JNZKEY_5JMPSTTPOPDXKEY_5:MOVAL,0FEH;扫描PC0口MOVDX,0604HOUTDX,ALMOVDX,0604HINAL,DXTESTAL,20H;检测PC5JNZKEY_CLRCALLKEY5;否则是按键5JMPSTTKKEY_CLR:TESTAL,40H;检测PC6口JNZKEY_6CALLKEYCLRJMPSTTKKEY_6:MOVAL,0FDHMOVDX,0604HOUTDX,ALMOVDX,0604HINAL,DXTESTAL,20H;检测PC5JNZKEY_STARTCALLKEY6JMPSTTKKEY_START:TESTAL,40H;检测PC6口JNZKEY_3CALLKEYSTARTJMPSTTKKEY_3:MOVAL,0FBHMOVDX,0604HOUTDX,ALMOVDX,0604HINAL,DXTESTAL,20H;检测PC5JNZKEY_4CALLKEY3JMPSTTKKEY_4:TESTAL,40H;检测PC6口JNZKEY_0CALLKEY4JMPSTTKKEY_0:MOVAL,0F7HMOVDX,0604HOUTDX,ALMOVDX,0604HINAL,DXTESTAL,20H;检测PC5JNZKEY_SETCALLKEY0JMPSTTKKEY_SET:TESTAL,40H;检测PC6口JNZKEY_111CALLKEYSETKEY_111:JMPSTTK;.KEY0:CALLLP1MOVAL,00HMOVDI,ALMOVAL,0FCHMOVSI,ALCALLDISPRETKEY3:CALLLP1MOVAL,03HMOVDI,ALMOVAL,0F2HMOVSI,ALCALLDISPRETKEY4:CALLLP1MOVAL,04HMOVDI,ALMOVAL,66HMOVSI,ALCALLDISPRETKEY5:CALLLP1MOVAL,05HMOVDI,ALMOVAL,0B6HMOVSI,ALCALLDISPRETKEY6:CALLLP1MOVAL,06HMOVDI,ALMOVAL,0BEHMOVSI,ALCALLDISPRET;.KEYSTART:CMPCOUNT,00HJZSTA1MOVAL,COUNTCBWPUSHAXMOVSI,OFFSETVAR4MOVDI,OFFSETTABLEMOVDL,00HSTA4:MOVBX,SIMOVAX,SI+2MOVDH,0FHDIVDHMOVDH,04HMULDHINCSIINCSIINCSIINCSIPUSHAXSTA5:POPAXMOVCX,AXPUSHAXSTA2:PUSHDXMOVAL,DIMOVDX,0600HOUTDX,ALPOPDXINCDIINCDLCALLDISP1CALLDALLY1CMPDL,08HJNZSTA3MOVDL,00HMOVDI,OFFSETTABLESTA3:LOOPSTA2CALLDISP1DECBXJNZSTA5INCD_COUNTMOVAL,COUNTPOPAXCALLDISP1DECCOUNTJNZSTA4POPAXCALLDISP1DECCOUNTJNZSTA4POPAXMOVCOUNT,ALMOVD_COUNT,00HMOVTAB_C,DIMOVCL,DLSTA1:RET;.KEYSET:LEASI,VAR2LEADI,VAR3MOVAL,COUNTCBWADDDI,AXADDDI,AXADDDI,AXADDDI,AXMOVCX,0004HSET1:MOVAL,SIMOVDI,ALINCDIINCSILOOPSET1LEASI,VAR5MOVDX,0000HMOVDI,OFFSETVAR4MOVAL,COUNTCBWADDDI,AXADDDI,AXADDDI,AXADDDI,AXMOVAL,SIMOVDI,ALMOVAL,SI+1MOVBL,64HMULBLADDDX,AXMOVAL,SI+2MOVCL,0AHMULBLADDDX,AXMOVBL,SI+3CBWADDAX,DXMOVDI+2,AXMOVCX,0004HLEASI,VAR2LEADI,VAR5SET2:MOVSI,0FCHMOVDI,00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IMEINCSIINCDILOOPDIRRET;.CLRR:MOVCX,0004HLEASI,VAR2LEADI,VAR5CLR8:MOVSI,0FCHINCSILOOPCLR8RET;.TIME:PUSHAXPUSHCXMOVCX,0010HTIME1:MOVAX,00300HTIME2:DECAXJNZTIME2LOOPTIME1POPCXPOPAXRETDALLY:PUSHCXPUSHAXMOVCX,1000HA6:MOVAX,0010HA7:DECAXJNZA7LOOPA6POPAXPOPCXRETDALLY1:PUSHCXPUSHAXMOVCX,0010HAA6:MOVAX,0500HAA7:DECAXJNZAA7LOOPAA6POPAXPOPCXRET;.放键测试.STTK:CALLDISPMOVAL,00HMOVDX,0604HOUTDX,ALMOVDX,0604HINAL,DXANDAL,60HCMPAL,60HJNZSTTKJMPSTTCODEENDSENDSTART