《计算机控制技术课程设计--步进电机角度控制(5).docx》由会员分享,可在线阅读,更多相关《计算机控制技术课程设计--步进电机角度控制(5).docx(12页珍藏版)》请在第壹文秘上搜索。
1、课程设计课程名称计算机控制技术课程设计题目名称步进电机角度控制(5)专业电气工程及其自动化目的1 .巩固和加深对计算机控制技术课程内容的认识和理解,提高应用水平2 .熟悉键盘控制和七段数码管的使用3 .掌握步进电机的控制和测试方法一、系统设计说明:键盘的输入及七段数码管通过8255A接口与系统总线连接,如电路框图所示。犍盘的8个键按4X2矩阵,其中4根矩阵线作为8255A的输出线与PA0-PA3连接,2根矩阵线作为8255A的输入线与PC6PC7连接。键盘采用逐次扫描原理,8个按键如系统原理图所示,03、5有5个数字按键,功能键有CLR、STARTSET3个。4位七段数码管用于显示4位数值数据
2、,数码管采用动态显示方式工作,PBO-PB7提供段码。PA3PA0提供位选。Pa)3与驱动单元连接进而控制驱动步进电机。依次输入4个数值,第一个数为步进电机转动次数,后三个数为转动一次的角度值,按SET设置好次数和角度数,再按START就开始转动该角度并按次数转动这个角度多少次。按CLR后电机转Pl转动前的原处。二、系统原理图:5,3X2SsIo wIORMIOYOSv键盘如图所示:CLRSET21STARTO65三、程序设计流程图:程序设计流程图四、源程序:STACKSEGMENTSTACKDW64DUP(?)STACKENDSDATASEGMENTVAlDB0F7H,OFBH,OFDH,O
3、FEHVA2DBOOH,OOH,OOH,OOH;数码管位选VA3DVVOOOOH;角度VA4DVVOOOOH;次数TABLEDB3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FHJ7H,7CH,39H3EH,79H,71H;数码管段选BJDJDB01H,03H,02H,06H,04H,0CH,08H,09HDATAENDSCODESE(iMENTASSUMECS:CODE,DS:DATA;30度步进电机字表startjmovax,dataMOVDS,AXMOVDX,0606HMOVAL,88HOUTDX,ALMOVBX,OOOOH;初始化设置STT:MOVAL,OO
4、HMOVDX,0600HOUTDX,ALMOVDX,0604HINAL,DXANDAL,OCOHCMPAL,OCOHJNZKEYABCCALLDISPJMPSTT;键盘扫描检测KEYABCCALLtimeMOVDX,0604HINAL,DXANDAL,OCOHCMPAL,OCOHJNZKEYJMPSTT;消除抖动KEY:MOVDX,0600HMOVAL,OFEHOUTDX,ALMOVDX,0604H;键位检测INAL,DXTESTAL,40HJNZKEY_7CALLKEYCLR;KEYOJMPSTTKKEY_7:TESTAL,80HJNZKEY_2CALLKEYSTART;KEY4JMPSTT
5、KKEY_2:MOVDX,060()HMOVAL,OFDHOUTDX,ALMOVDX,0604HINAL,DXTESTAL,40HJNZKEY_6CALLKEYSET;KEY1JMPSTTKKEY_6:TESTAL,80HJNZKEY_1CALLKEY0;KEY5JMPSTTKKEY_1:MOVDX,060()HMOVAL,OFBHOUTDX,ALMOVDX,0604HINAL,DXTESTAL,40HJNZKEY_5CALLKEY2;KEY2JMPSTTKKEY_5:TESTAL,80HJNZKEY_0CALLKEY6JMPSTTKKEY_0:MOVDX,0600HMOVAL,0F7HOUT
6、DX,ALMOVDX,0604HINAL,DXTESTAL,40HJNZKEY_4CALLKEY1;KEY3JMPSTTKKEY_4:TESTAL,80HJNZKEY.C1:按键处理CALLKEY5;KEY7KEY_CIiJMPSTTKKEYOrCALLLPlMOVAL,OOHMOVDI+03H,ALCALLDISPRETKEYkCALLLPlMOVAL,OlHMOVDI+03H,ALCALLDISPRETKEY2:CALLLPlMOVAL,02HMOVDI+03H,ALCALLDISPRETKEY3:CALLLPlMOVAL,03HMOVrDI+03H,ALCALLDISPRETKEY4:C
7、ALLLPlMOVAL,04HMOV(DI+03H,ALCALLDISPRETKEY5:CALLLPlMOVAL,05HMOVDI+03H,ALCALLDISPRETKEY6:CALLLPlMOVAL,06HMOVDI+03H,ALCALLDISPRETKEY7:CALLLPlMOVAL,07HMOVDI+03H,ALCALLDISPRET;清除键位程序段;步进电机反转回原位程序段KEYCLR:CALLKEYSETMOVDI,OFFSETVA3MOVBX,DIMOVDI,OFFSETVA4MOVAL,DIMOVAH,OOHCMPAL,OOHJZN7MOVCX,AXNBJ:PUSHCXPUSHB
8、XMOVAX,BXMOVBL,1EH;3ODIVBLCMPAL,OOHJZN6MOVCL,ALNI:PUSHCXMOVSI,OFFSETBJDJMOVCX,0008HN2:MOVAL,SI+07HMOVDX,0604HOUTDX,ALCALLDELAYDECSILOOPN2POPCXLOOPNlN6:MOVAL,AHMOVAH,OOHMOVBL,04HDIVBLMOVCL,ALMOVCH,OOHCMPAL,00HJZN5MOVSI,OFFSETBJDJN4:MOVAL,SI+07HMOVDX,0604HOUTDX,ALCALLDELAYDECSILOOPN4N5:POPBXPOPCXLOOPN
9、BJN7:MOVDI,OFFSETVA2MOVAX,OOHMOVSI,OFFSETVA3MOVSI,AXMOVSI,OFFSETVA4MOVSI,AXMOVCX,04HCLREN:MOVDI,OOHINCDILOOPCLRENCALLDISPRETKEYSTART:MOVDI,OFFSETVA3;开始键位程序段MOVBXjDI;度数MOVDI,OFFSETVA2MOVALJDl+03H;次数CMPAL,OOHJZA7MOVAH,00HMOVCX,AXMOVfDI+03H,00HMOVDI,OFFSETVA4MOV(DI,AXCALLDELAYCALLDELAYBJ:MOVDI,OFFSETVA
10、2;步进电机程序段INCDI+03HCALLDISPPUSHCXPUSHBXMOVAX,BXMOVBL,1EH;3ODIVBLMOVCL,ALCMPCL,OOHCALLDELAYJZA6Al:PUSHCXMOVSI,OFFSETBJDJMOVCX,OOO8HA2:MOVAL,SIMOVDX,0604HOUTDX,ALCALLDELAYINCSILOOPA2POPCXLOOPAlA6:MOVAL,AHMOVAH,OOHMOVBL,04HDIVBLMOVCL,ALMOVCH,OOHCMPAL,OOHJZA5MOVSI,OFFSETBJDJA4:MOVAL,SIMOVDX,0604HOUTDX,AL
11、CALLDELAYINCSILOOPA4A5:POPBXPOPCXLOOPB.JA7:RET;设置键程序段KEYSET:MOVDI,OFFSETVA2MOVAL,DI+02HMOVBL,64H;100MULBLMOVCX,AXMOVAL,DI+01HMOVBL,0AH;10MULBLADDCX,AXMOVAL,DIMOVAH,OOHADDCX,AXMOVDI,OFFSETVA3MOVDI,CXRETLPkMOVDI,OFFSETVA2MOVCX,0()03HLP2:MOVAL,DI+02HMOVDI+03HLDECSIDECDILOOPLP2;显示程序段RETDISP:PUSHCXPUSHBX
12、MOVSI,OFFSETVAlMOVDI,OFFSETVA2MOVBX,OFFSETTABLEMOVDL,DI+03HCMPDL,3FHJNZDIR3MOVDL,DI+02HCMPDL,3FHJNZDIR2MOVDL,DI+01HCMPDL,3FHJNZDIRl.IMPDIRODIR3:MOVCX,0004HJMPDIRDIR2:MOVCX,0003HJMPDIRDIRkMOVCX,0002HJMPDIRDIROrMOVCX,OOOlHDIRzMOVDX,0600HMOVAL,SIOUTDX,ALMOVDX,0602HMOVAL,DIXLATOUTDX,ALCALLTIMEINCSIINCDI
13、LOOPDIRPOPBXPOPCXRETTIME:PUSHAXPUSHCXMOVCX,0005HTIMEkMOVAX,OOFOHTIME2:DECAXJNZTIME2LOOPTIMElPOPCXPOPAXRETDELAY:PUSHCXMOVCX,8()00HA3:PUSHAXPOPAXLOOPA3POPCXRETSTTKrCALLDISPMOVAL,(M)HMOVDX,0600HOUTDX,ALMOVDX,0604HINAL,DXANDAL,OCOHCMPAL,OCOHJNZSTTKJMPSTTCODEENDSENDSTART;延时程序段1;延时程序段2;松键检测调试如实现以下功能:1、键入2
14、(次数)165(角度数)键入SET设置完毕,键入START步进电机转动165度2次;停止后即纳入CLR返回零位;每个过程都必须有相关的显示。2、键入5(次数)120(角度数)键入SET设置完毕,键入START步进电机转动120度5次;停止后即纳入CLR返回零位;每个过程都必须有相关的显示。以上程序可调试成功五、课程设计分析总结通过这次对计算机控制技术课程设计,我收获最大的便是感受到了8255控制方式与实际运用的强大结合。和同学们一步步调试修改,然后设计出来,当电机转动一刹那,真的有种如同自己的孩子出生的感觉。无比兴奋与激动。我的时间基本耗在了对问题的理解和思路的架构,其中,我也参考了很多书本并加以修改,最深有体会的是那按规则及各项代码标准,耗尽半生精力,但最终我还是克服了重重困难