溫控步進(jìn)電機(jī)的實(shí)現(xiàn)_第1頁(yè)
溫控步進(jìn)電機(jī)的實(shí)現(xiàn)_第2頁(yè)
溫控步進(jìn)電機(jī)的實(shí)現(xiàn)_第3頁(yè)
溫控步進(jìn)電機(jī)的實(shí)現(xiàn)_第4頁(yè)
溫控步進(jìn)電機(jī)的實(shí)現(xiàn)_第5頁(yè)
已閱讀5頁(yè),還剩6頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、基于Proteus的單片機(jī)溫控步進(jìn)電機(jī)電路及程序仿真設(shè)計(jì)一.課設(shè)目的:1 .通過本設(shè)計(jì),使學(xué)生綜合運(yùn)用單片機(jī)原理及應(yīng)用及電子技術(shù)等課程的內(nèi)容,為以后從事基于單片機(jī)的檢測(cè)與控制工作奠定一定的基礎(chǔ)。2 .主要掌握芯片DS18B20ULN2803等器件的使用,掌握步進(jìn)電機(jī)的使用。3 .學(xué)會(huì)用KeilC51語(yǔ)言編寫一個(gè)完整的程序。4 .掌握單片機(jī)應(yīng)用開發(fā)的全過程:分析需求、設(shè)計(jì)原理圖、選用元器件、布線、編程、調(diào)試、撰寫報(bào)告等步驟。5 .掌握Proteus軟件的應(yīng)用。二.課設(shè)內(nèi)容:采用單片機(jī)內(nèi)部定時(shí)器,設(shè)計(jì)1s定時(shí),每秒檢查一次由溫度傳感器輸入的當(dāng)前溫度。設(shè)置溫度白上限(t2)和下限(t1),假定當(dāng)前溫

2、度為to由此可知:若tRt2,則控制步進(jìn)電機(jī)順時(shí)針旋轉(zhuǎn);若twt1,則控制步進(jìn)電機(jī)逆時(shí)針旋轉(zhuǎn);若t1vtvt2,步進(jìn)電機(jī)停止轉(zhuǎn)動(dòng)。3 .問題分析及設(shè)計(jì)思路:由設(shè)計(jì)要求可知,需要通過由溫度傳感器采集的溫度來控制步進(jìn)電機(jī)的轉(zhuǎn)動(dòng),因此可以在源程序中加入相應(yīng)的語(yǔ)句加以實(shí)現(xiàn)。電路原理圖的設(shè)計(jì)思路如下:1 .單片機(jī)P1.0接溫度傳感器DS18B20采集外界的當(dāng)前溫度。DS18B20的電源和地線分另I接VCCGND2 .單片機(jī)P2.0P2.3接74LS04,74LS04的輸出接ULN2803,ULN2803的輸出通過電阻接步進(jìn)電機(jī)。3 .設(shè)計(jì)程序每秒檢查一次由溫度傳感器輸入的當(dāng)前溫度,根據(jù)設(shè)置的溫度控制步進(jìn)

3、電機(jī)轉(zhuǎn)動(dòng)的方向或停止步進(jìn)電機(jī)。4 .電路原理圖:“eIWfklVWI聞*1口硝林/馬啦kr地南加鄧佃富五.程序流程圖:E#fl6MmcaMmiPDraow*2i*aiUlllPZMIliF?WdPUMKfrM.VTWt劉理nFssdririr姬身nnsaiMH#-F;m*T初始化電機(jī)反轉(zhuǎn)延時(shí)六.實(shí)驗(yàn)源程序:#include#defineucharunsignedchar#defineuintunsignedintucharcodefortab9=0x0e,0x0c,0x0d,0x09,0x0b,0x03,0x07,0x06,0x00;ucharcoderevtab9=0x0e,0x06,0x0

4、7,0x03,0x0b,0x09,0x0d,0x0c,0x00;inttime=500;voiddisp(ucharcc);voiddsend(ucharbb);voiddmsec(unsignedintcount);voidtmreset(void);voidtmpre(void);bittmrbit(void);unsignedchartmrbyte(void);voidtmwbyte(unsignedchardat);voidtmstart(void);uchartmrtemp(void);voiddfor(void);voiddrev(void);rom();/對(duì)調(diào)用的函數(shù)進(jìn)行初始化定

5、義ucharcodetemper_tab100=0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x50,0x51,0x52,0x53,0x54,0

6、x55,0x56,0x57,0x58,0x59,0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99;/定義溫度范圍,0到100度ucharcodedis_code10=0x03,0x9F,0x25,0x0D,0x99,0x49,0x41,0x1F,0x

7、01,0x09;0123456789sbitTMDAT=P1A0;/根據(jù)實(shí)實(shí)際情況設(shè)定ucharTMP;讀取后溫度值存于TMP中,將其除以2即可得出實(shí)際溫度;ucharf;結(jié)果是否為負(fù)溫,“0”為正溫,“1”為負(fù)溫。/正轉(zhuǎn)子程序voiddfor(void)uchari;uintj;for(i=0;i=8;i+)P2=fortabi;for(j=0;jtime;j+);/中斷服務(wù)子程序(反轉(zhuǎn))voiddrev(void)/interrupt1using0uchari;uintj;for(i=0;i=8;i+)P2=revtabi;for(j=0;j4;dsend(bb);)voiddsend(u

8、charbb)(uchari=bb;SBUF=dis_codei;while(TI=0);TI=0;)/voiddmsec(unsignedintcount)(unsignedinti;while(count)(i=115;Wiile(i0)i-;count-;)lllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllvoidtmreset(void)(unsignedinti;TMDAT=0;i=103;while(i0)i

9、-;llTMDAT=1;i=4;while(i0)i-;)llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll延時(shí)部分llllllllllllllllllllllllllllllllllllllllllllll發(fā)送復(fù)位llllllllllllllllllllllllllllllllllll延時(shí)900uS(11.0592Mhz時(shí))llllllllllll判斷DS1820是否存在的子程序。最好不要用,因?yàn)楫?dāng)器件不存在時(shí)將會(huì)進(jìn)入死循環(huán)llllllllllllllllllllllllllllllllllll

10、ll等待存在脈沖lllllllllllllllllllllllllvoidtmpre(void)ll判斷器件是否在llllllllunsignedinti;llllwhile(TMDAT);llllwhile(TMDAT);lllli=4;while(i0)i-;lllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll讀一位llllllllllllllllllllllllllllllbittmrbit(void)lll

11、lunsignedinti;llbitdat;llTMDAT=0;i+;llTMDAT=1;i+;i+;ll微量延時(shí)dat=TMDAT;ll)/讀一個(gè)字節(jié)/unsignedchartmrbyte(void)/(/unsignedchari,j,dat;/dat=0;/for(i=1;i=8;i+)/(/j=tmrbit();/dat=(j1);/)/return(dat);/)/寫一個(gè)字節(jié)/voidtmwbyte(unsignedchardat)/(/unsignedinti;/unsignedcharj;/bittestb;/for(j=1;j1;/if(testb)/(/TMDAT=0;/

12、寫0i+;i+;/TMDAT=1;/i=8;while(i0)i-;/)/else/(/TMDAT=0;/寫0/i=8;while(i0)i-;/TMDAT=1;/i+;i+;/)/)/)/發(fā)送ds1820開始轉(zhuǎn)換/voidtmstart(void)/(/tmreset();/復(fù)位/tmpre();/等待存在脈沖/dmsec(1);/延時(shí)/tmwbyte(0xcc);/跳過序列號(hào)命令/tmwbyte(0x44);/發(fā)轉(zhuǎn)換命令44H,/)/讀取溫度/uchartmrtemp(void)/(/unsignedcharl,h,i;/tmreset();/復(fù)位/tmpre();/等待存在脈沖/dmse

13、c(1);/延時(shí)/tmwbyte(0xcc);/跳過序列號(hào)命令/tmwbyte(0xbe);/發(fā)送讀取命令/i=8;while(i0)i-;return(dat);/延時(shí)/l=tmrbyte();/讀取低位溫度/h=tmrbyte();/讀取高位溫度/TMP=l4;/if(l3)&0x01=0x01)/TMP=TMP+1;/TMP=(h&0x07)4)|TMP;/i=TMP;/TMP=temper_tabi;/一/return(TMP);/voidmain(void)/ucharaa,i;/do/tmstart();/dmsec(100);/如果是不斷地讀取的話可以不延時(shí)/aa=tmrtemp

14、();/讀取溫度,執(zhí)行完畢溫度將存于TMP中disp(aa);/if(aa=0x25)/drev();/若讀取溫度大于等于25度則電機(jī)反轉(zhuǎn)/else;/若讀取溫度在20度與25度之間,則電機(jī)停止轉(zhuǎn)動(dòng)for(i=0;i100;i+);/while(1);/七.遇到的問題及解決方法:1 .在使用Proteus軟件繪制電路圖時(shí),遇到的器件名稱不唯一的問題。解決方法:在繪制電路圖時(shí),必須保證器件名稱唯一,否則就會(huì)仿真時(shí)就會(huì)提示出錯(cuò)。需進(jìn)行修改使其唯一。2 .繪制電路圖時(shí),器件的安放及線路連接問題。解決方法:由于該電路涉及的功能模塊比較多,故器件排布及線路連接有些復(fù)雜。在進(jìn)行了多次修改之后,確定了比較合

15、理的布局方式,使電路圖看起來較為整潔有條理。3 .在編寫源程序時(shí),出現(xiàn)的某些函數(shù)無法進(jìn)行調(diào)用的問題。解決方法:在對(duì)老師所給的代碼進(jìn)行分析之后,發(fā)現(xiàn)若需要在主程序中對(duì)函數(shù)進(jìn)行調(diào)用,則應(yīng)該在代碼前面對(duì)其進(jìn)行聲明,否則編譯時(shí)會(huì)出現(xiàn)錯(cuò)誤。八.仿真結(jié)果:1.若讀取的溫度大于20度且小于25度,則電機(jī)停止轉(zhuǎn)動(dòng):尸產(chǎn)%需小fl,喳,事2.若讀取的溫度大于等于0rnncwKirCLWMHPCCVM3PU3M3PEL/皿陽(yáng)FZJgF2WKKJM11FZ.&U,工一安門W2MU.njMic的EArajWTT0hEF3U&T1piiscrw:0ltE25度,則電機(jī)反轉(zhuǎn):ue_RXIrbTkla口1rln-Vnn3-Jp,二廿語(yǔ)rrjf.n產(chǎn)AMiljFzsa仃FZfl*.l+FZTfi*.l5,:)口FliE:l!FizrrmnimT3rn.33mrusn.rajilFWj3.若讀取的溫度小于等于20度,則電機(jī)正轉(zhuǎn):九.課設(shè)小結(jié):通過本次課設(shè),熟悉了proteus軟件的使用方法,了

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論