




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、51單片機(jī)控制步進(jìn)電機(jī)硬件圖#include /51芯片管腳定義頭文件#include /內(nèi)部包含延時(shí)函數(shù) _nop_();#include#define uchar unsigned char#define uint unsigned intuchar code FFW8=0x01,0x03,0x02,0x06,0x04,0x0c,0x08,0x09; /四相八拍正轉(zhuǎn)編碼uchar code REV8=0x09,0x08,0x0c,0x04,0x06,0x02,0x03,0x01; /四相八拍反轉(zhuǎn)編碼sbit P14=P14; /將P14位定義為P1.4引腳sbit P15=P15; /將P
2、15位定義為P1.5引腳sbit P16=P16; /將P16位定義為P1.6引腳sbit P17=P17; /將P17位定義為P1.7引腳sbit P20=P20;/將P20位定義為P2.0引腳sbit P21=P21;/將P21位定義為P2.1引腳sbit P22=P22;/將P22位定義為P2.2引腳sbit P23=P23;/將P23位定義為P2.3引腳sbit P24=P24; /將P24位定義為P2.4引腳sbit P25=P25; /將P25位定義為P2.5引腳sbit P26=P26; /將P26位定義為P2.6引腳sbit P27=P27; /將P27位定義為P2.7引腳sb
3、it P34=P34; /將P34位定義為P3.4引腳sbit P35=P35; /將P35位定義為P3.5引腳sbit P36=P36; /將P36位定義為P3.6引腳sbit P37=P37; /將P37位定義為P3.7引腳sbit P30=P30; /將P30位定義為P3.0引腳sbit P31=P31; /將P31位定義為P3.1引腳sbit BEEP=P32; /蜂鳴器bit on=0; bit off=1; /運(yùn)行與停止標(biāo)志bit zdirection=0; /方向標(biāo)志bit fdirection=0; /方向標(biāo)志uchar h,l,k;/定義行鍵值/定義列鍵值uchar idat
4、a count3; /0-9數(shù)值儲(chǔ)存unsigned char code Tab =0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90; /數(shù)字09的段碼uchar keyval=0; /定義變量?jī)?chǔ)存按鍵值uchar dat=0; /按鍵值uint run_i=0;uchar count_i=0;uint run=0;/需要運(yùn)行的步數(shù)uint drun=0; /當(dāng)前運(yùn)行的步數(shù)bit flag; uint x=60;uint y=60;uint z=0;/*uint k=0; /調(diào)速按鍵次 */ /*/void led_delay1(void) u
5、nsigned char j;for(j=0;j52;j+) ; void beep() uchar j; for (j=0;j200;j+) led_delay1(); BEEP=!BEEP; /BEEP取反 BEEP=1; /關(guān)閉蜂鳴器 /*函數(shù)功能:數(shù)碼管動(dòng)態(tài)掃描延時(shí)*/void led_delay(void) unsigned char j;for(j=0;j200;j+) ; /*/*函數(shù)功能:軟件延時(shí)去抖動(dòng)子程序*/ void delay20ms(void) unsigned char i,j;for(i=0;i70;i+) for(j=0;j=0)&(dat=9)&(on=0)&
6、(off=1) countcount_i=dat;if(count0!=0)count_i+;if(count_i=3)&(on=0)&(off=1)count_i=0;if(count_i=0)&(on=0)&(off=1) if(count0=0)run=0; else run=count0*100+count1*10+count2;if(count_i=1)&(on=0)&(off=1)run=count0;if(count_i=2)&(on=0)&(off=1) run=count0*10+count1; if(dat=0)&(on=1)off=1;if(dat=16);flag=0;
7、 /*if(run!=0)*/ ddisplay(drun); dddisplay(); display(run);/* */ /調(diào)用按鍵值的數(shù)碼管顯示子程序if(run=drun)&run!=0)on=0;off=1;beep(); drun=0; run=0;count0=0; /顯示清零count1=0;count2=0;count_i=0; /* 外部中斷鍵盤(pán)掃描鍵值保存在dat中 */ void Interrupt1() interrupt 2 using 3 flag=1; /*/ void Interrupt2() interrupt 1 using 1 TR0=0; EX1=1
8、; TH0=0xec; TL0=0x78; x-; if(x=0) if(zdirection=1)&(fdirection=0)&(on=1)&(off=0)P1=FFWrun_i;fdirection=0; led_delay(); /動(dòng)態(tài)掃描延時(shí) led_delay(); /動(dòng)態(tài)掃描延時(shí) led_delay(); /動(dòng)態(tài)掃描延時(shí) led_delay(); /動(dòng)態(tài)掃描延時(shí) drun+;run_i+;if(run_i=8)run_i=0;if(run=drun)on=0;off=1; if(zdirection=0)&(fdirection=1)&(on=1)&(off=0)P1=REVrun_i; led_delay(); /動(dòng)態(tài)掃描延時(shí) led_delay(); /動(dòng)態(tài)掃描延時(shí) led_delay(); /動(dòng)態(tài)掃描延時(shí)
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝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ù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年河南云河信息科技有限公司招聘高層次人才考試筆試試題(含答案)
- 斑羚飛渡教學(xué)課件
- 艦艇槍炮教學(xué)課件
- 文庫(kù)發(fā)布:將相和課件
- 課桌主題班會(huì)課件
- 整式加減說(shuō)課課件
- 六年級(jí)單音節(jié)字教學(xué)課件
- 鄉(xiāng)思李覯教學(xué)課件
- 明年酒類活動(dòng)方案
- 新春購(gòu)車活動(dòng)方案
- 給攪拌站送石子合同范本
- 2023年副主任醫(yī)師(副高)-學(xué)校衛(wèi)生與兒少衛(wèi)生(副高)考試歷年真題集錦帶答案
- 法律基礎(chǔ)(第4版)PPT完整全套教學(xué)課件
- 倉(cāng)管應(yīng)聘求職簡(jiǎn)歷表格
- 五年級(jí)下冊(cè)語(yǔ)文期末考試學(xué)霸?shī)Z冠解密卷人教部編版含答案
- 房屋加固工程監(jiān)理規(guī)劃
- 一級(jí)煙草專賣管理師理論考試題庫(kù)(含答案)
- von frey絲K值表完整版
- SAP月結(jié)年結(jié)用戶手冊(cè)精
- 碳捕集、利用與封存技術(shù)課件
- 碳達(dá)峰和“碳中和”環(huán)境知識(shí)科普宣傳PPT教學(xué)課件
評(píng)論
0/150
提交評(píng)論