C語言程序源代碼.doc_第1頁
C語言程序源代碼.doc_第2頁
C語言程序源代碼.doc_第3頁
C語言程序源代碼.doc_第4頁
C語言程序源代碼.doc_第5頁
已閱讀5頁,還剩5頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

C語言程序源代碼#include / 51寄存器定義#include intrins.h#define control P1 /P1_0:A相,P1_1:B相,P1_2:C相,P1_3:D相#define discode P0 /顯示代碼控制端口#define uchar unsigned char /定義無符號(hào)型變量#define uint unsigned int sbit en_dm=P30; /顯示代碼鎖存控制sbit en_wk=P31; /位控鎖存控制uchar code corotation4= 0x03,0x06,0x0c,0x09;/電機(jī)正轉(zhuǎn)uchar code rollback4=0x0c,0x06,0x03,0x09; /電機(jī)反轉(zhuǎn)uchar code tab10=0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f;/顯示字段uint code Levspeed5=500,400,300,200,100;/電機(jī)速度等級(jí)uchar Hscan,speedcount;/Hscan行掃描,speedcount 速度等級(jí)計(jì)數(shù)uint uu; /頻率計(jì)數(shù)uint step,setstep; /step:電機(jī)步伐計(jì)數(shù),setstep:手動(dòng)設(shè)置電機(jī)步伐uint speed=500; /電機(jī)初始速度uchar count; uchar flag5;uchar butcount; /按鍵次數(shù)/*/flag0 正轉(zhuǎn)標(biāo)志/flag1 反轉(zhuǎn)標(biāo)志/flag2 加速標(biāo)志/flag3 減速標(biāo)志/flag4 設(shè)置標(biāo)志/*Delay1mS(unsigned int tt) /延時(shí)1ms “Delay1mS”延時(shí)子程序,用循環(huán)語句延時(shí)。 unsigned char i; while(tt-) for(i=113;i0;i-);keyscan() /鍵盤掃描 “keyscan”鍵盤掃描子程序,用于尋找是否有按鍵按下。 P2=0xf0; /把oxfe賦值給P2口 /將按鍵控制口置于未按鍵的狀態(tài).單片機(jī)輸出/口假設(shè)不是按鍵按下狀態(tài). if(P2!=0xf0) /如果P2口的值不等于0xfe /檢查是否有按鍵按下.如果有,處理內(nèi)的事 /有按鍵按下. Delay1mS(150);/調(diào)用延時(shí)函數(shù)/有按鍵按下,避開無效讀碼值的時(shí)間.,或者是脈沖長(zhǎng)度 Hscan=0xfe; /將Hscan賦值,初始遙控值是要置高電平的. P2=Hscan; / while(Hscan&0x10)!=0) /檢查X10口是否有鍵按下。未按下是1, /在這顯示出你的按鍵口是P2_4.即檢查P2_4是高電平,無/鍵按下,低電平有鍵按下。 P2=Hscan; if(P2&0xf0)!=0xf0) /檢查按鍵脈沖是否是變化, return P2;else Hscan=(Hscan=5) /輸入的數(shù)字超過5個(gè)就置0,無效 butcount=0; setstep=0; break;case 0xde: /按鍵8 /讀取的碼值=0xdE,則是按鍵“8”的代碼 /其他同”7” /while(P2=0xde); setstep=setstep*10+8; butcount+; step=setstep; if(butcount=5) butcount=0; setstep=0; break; case 0xbe: /按鍵9 /同上”7” /while(P2=0xbe); setstep=setstep*10+9; butcount+; step=setstep; if(butcount=5) butcount=0; setstep=0; break; case 0x7e: /按鍵正轉(zhuǎn) /正轉(zhuǎn)按鍵識(shí)別 while(P2=0x7e); /等待按鍵松開/一值按住電機(jī)是不轉(zhuǎn)的,放開后才轉(zhuǎn).有檢查/P2口的狀態(tài)值 flag0=0xff; /開啟正轉(zhuǎn)標(biāo)志,關(guān)閉反轉(zhuǎn)/置正轉(zhuǎn)標(biāo)志. flag1=0x00; /清除反轉(zhuǎn)標(biāo)志. butcount=0; speedcount=0; speed=500; /置電機(jī)的轉(zhuǎn)速. if(!flag4) step=0; TR0=1; break; case 0xed: /按鍵4 /同上”7” while(P2=0xed); setstep=setstep*10+4; butcount+; step=setstep; if(butcount=5) butcount=0; setstep=0; break; case 0xdd: /按鍵5 /同上”7” /while(P2=0xdd); setstep=setstep*10+5; step=setstep; butcount+; if(butcount=5) butcount=0; setstep=0; break;我上周剛做的這個(gè)實(shí)驗(yàn) 成功拉,給你參考一下吧 這可是我當(dāng)時(shí)辛辛苦苦編出來的啊,不過我用的是L298驅(qū)動(dòng)的 和ULN2003一樣,你把它換成2003就行拉#include unsigned char code table=0xf1,0xf3,0xf2,0xf6,0xf4,0xfc,0xf8,0xf9,0x00,0xf1,0xf9,0xf8,0xfc,0xf4,0xf6,0xf2,0xf3,0x00;unsigned char temp,temp_old;unsigned char key;unsigned char i,j,k,m,s;void delay(int i) for(m=i;m0;m-) for(j=250;j0;j-) for(k=10;k0;k-); void saomiao() P3=0xff; P3_4=0; temp=P3; temp=temp&0x0f; if(temp!=0x0f) for(i=50;i0;i-) for(j=200;j0;j-); temp=P3; temp=temp&0x0f; if(temp!=0x0f) temp=P3; temp=temp&0x0f; switch(temp) case 0x0e: key=1; break; case 0x0d: key=2; break; case 0x0b: key=3; break; case 0x07: key=4; break; temp=P3; temp=temp&0x0f; while(temp!=0x0f) temp=P3; temp=temp&0x0f; P3=0xff; P3_5=0; temp=P3; temp=temp&0x0f; if(temp!=0x0f) for(i=50;i0;i-) for(j=200;j0;j-); temp=P3; temp=temp&0x0f; if(temp!=0x0f) temp=P3; temp=temp&0x0f; switch(temp) case 0x0d: key=5; break; case 0x0b: key=6; break; case 0x07: key=7; break; temp=P3; temp=temp&0x0f; while(temp!=0x0f) temp=P3; temp=temp&0x0f; void main(void) while(1) saomiao(); if(key=1) P1=0; P2=0; saomiao(); if(key=2) temp_old=key; for(s=0;s8;s+) P2=tables; P1_4=0; delay(13); saomiao(); if(key!=temp_old) P1_4=1; break; if(key=3) temp_old=key; for(s=0;s8;s+) P2=tables; P1_5=0; delay(5); saomiao(); if(key!=temp_old) P1_5=1; break; if(key=4) temp_old=key; for(s=0;s8;s+) P2=tables; P1_6=0; delay(20); saomiao(); if(key!=temp_old) P1_6=1; break; if(key=5) temp_old=key; for(s=9;s17;s+) P2=tables; P1_7=0; delay(13); saomiao(); if(key!=temp_old) P1_7=1; break; if(key=6) temp_old=key; for(s=9;s17;s+) P2=tables; P1_5=0; delay(5); saomiao(); if(key!=temp_old) P1_5=1; break; if(key=7) temp_old=key; for(s=9;s17;s+) P2=tables; P1_6=0; delay(20); saomiao(); if(key!=temp_old) P1

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(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)論