基于單片機(jī)的多路電壓采集_第1頁
基于單片機(jī)的多路電壓采集_第2頁
基于單片機(jī)的多路電壓采集_第3頁
基于單片機(jī)的多路電壓采集_第4頁
基于單片機(jī)的多路電壓采集_第5頁
已閱讀5頁,還剩4頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

1、此程序分三部分,一是主程序,二是1602顯示程序,三是ad0808采樣程序,附protues仿真圖。/*/*/*<程序名>:多路數(shù)字電壓表采集/*<功能>:使用LCD1602顯示被檢測(cè)電壓,精度為0.05V,范圍是05V。/*<版本說明>:這是第3版,使用LCD顯示。/*<作者>:程沛/*<修改>:楊堅(jiān)/*<完成時(shí)間>:2011年11月18日/*/*頭文件及宏定義#include "includes.h"#include <at89x51.h>#define TIME0H 0x3C#defi

2、ne TIME0L 0xB0/#define abc P1/*/全局變量* */*unsigned char uc_Clock=0;/定時(shí)器0中斷計(jì)數(shù)bit b_DATransform=0;/<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>

3、>>>>>>>>>>>>>>>>>>>>>>>>>>/把電壓顯示在LCD /<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>

4、>>>>>>>>>>>>>>>>>>>>>>>>>>>>void vShowVoltage(unsigned int uiNumber)unsigned char ucaNumber3,ucCount;if(uiNumber>999)uiNumber=999;ucaNumber0=uiNumber/100;/把計(jì)算數(shù)字的每個(gè)位存入數(shù)組。ucaNumber1=(uiNumber-100*(int)ucaNumber0)/10

5、;ucaNumber2=uiNumber-100*(int)ucaNumber0-10*ucaNumber1;for(ucCount=0;ucCount<3;ucCount+)vShowOneChar(ucaNumberucCount+48);/從首位到末位逐一輸出。if(ucCount=0)vShowOneChar('.');/*/*主函數(shù)/*void main() unsigned int m,g,k; unsigned char abc; / for(m=0;m<8;m+) / /<<<<<<<<<<

6、<<<<<<<設(shè)置定時(shí)器0>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>TMOD=0x01;/定時(shí)器0,模式1。TH0=TIME0H;TL0=TIME0L;TR0=1;/啟動(dòng)定時(shí)器。ET0=1;/開定時(shí)器中斷。EA=1;/開總中斷vdI

7、nitialize();vWriteCMD(0x84); /寫入顯示起始地址(第二行第一個(gè)位置)vShowChar("Voltage:");vWriteCMD(0xC9);vShowChar("(V)");while(1) abc = 0x00; for(m=0;m<8;m+) P1=abc; abc+;if(b_DATransform=1)b_DATransform=0; vWriteCMD(0x80); vShowVoltage(m);vWriteCMD(0xC4);vShowVoltage(uiADTransform();for(g=0;g&

8、lt;1000;g+) for(k=0;k<120;k+); /<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>&

9、gt;>>>>>>/<<<<<<<<<<<<<<定時(shí)器0中斷函數(shù)>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>/<<<<<<<<<<<

10、;<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>void Time0() interrupt 1if(uc_Clock=0)u

11、c_Clock=5;b_DATransform=1;elseuc_Clock-;TH0=TIME0H; /恢復(fù)定時(shí)器0。TL0=TIME0L;/*延時(shí)程序*/void adelay()/ unsigned int i,k;/ for(i=0;i<1000;i+)/ for(k=0;k<120;k+);/<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>&g

12、t;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>/<<<<<<<<<<<<<<<<<<<<<<<<<<<<<AD轉(zhuǎn)換函數(shù)>>>>>>>

13、;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>/<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>&g

14、t;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>#include <at89x51.h>#define START P3_4 /ATART,ALE接口。0->1->0:啟動(dòng)AD轉(zhuǎn)換。#define EOC P3_3 /轉(zhuǎn)換完畢由0變1.#define OUTPORT P2 /#define abc P1/AD轉(zhuǎn)換函數(shù),返回轉(zhuǎn)換結(jié)果。/轉(zhuǎn)換結(jié)果是3位數(shù),小數(shù)點(diǎn)在百位與十位之間。unsig

15、ned int uiADTransform()unsigned int uiResult;/ unsigned char abc;/for(m=0;m<8;m+) / abc=0x00;/P1=abc;START=1; /啟動(dòng)AD轉(zhuǎn)換。START=0;while(EOC=0); /等待轉(zhuǎn)換結(jié)束。uiResult=OUTPORT; /出入轉(zhuǎn)換結(jié)果。uiResult=(100*uiResult)/51; /處理運(yùn)算結(jié)果。 / abc+;return uiResult;/*/*驅(qū)動(dòng)程序*/*/<<<<<<<<<<<<<

16、;<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>/<<<<<<<<<<<<<<&l

17、t;<<<<<<頭文件及宏定義>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>/<<<<<<<<<<<<<<<<<<<<<<<<<<>>&g

18、t;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>#include "SMC1602.h"/<<<<<<<<<<<<<<<<<<<<

19、;<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>/<<<<<<<<<<<<<<<<<<<&l

20、t;<把1個(gè)命令寫入LCD>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>/<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>

21、;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>void vWriteCMD(unsigned char ucCommand) vDelay();/先延時(shí)。LCDE=1;/然后把改為寫入命令狀態(tài)。LCDRS=0;LCDRW=0;LCDPORT=ucCommand;/再輸出命令。LCDE=0;/最后執(zhí)行命令。/<<<

22、<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>/<<<

23、;<<<<<<<<<<<<<<<<<<<<<把1個(gè)數(shù)據(jù)寫入LCD>>>>>>>>>>>>>>>>>>>>>>>>>>>/<<<<<<<<<<<<<<<<<<<>>>>>

24、>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>void vWriteData(unsigned char ucData) vDelay(); /先延時(shí)。LCDE=1; /然后把改為寫入數(shù)據(jù)狀態(tài)。LCDRS=1;LCDRW=0;LCDPORT=ucData; /再輸出數(shù)據(jù)。LCDE=0;

25、 /最后顯示數(shù)據(jù)。void vShowOneChar(unsigned char ucChar)switch(ucChar)case ' ': vWriteData(0x20);break;case '!': vWriteData(0x21);break;case '"': vWriteData(0x22);break;case '#': vWriteData(0x23);break;case '$': vWriteData(0x24);break;case '%': vWriteData

26、(0x25);break;case '&': vWriteData(0x26);break;case '>': vWriteData(0x27);break;case '(': vWriteData(0x28);break;case ')': vWriteData(0x29);break;case '*': vWriteData(0x20);break;case '+': vWriteData(0x2A);break;case '-': vWriteData(0x2D)

27、;break;case '/': vWriteData(0x2F);break;case '=': vWriteData(0x3D);break;case '<': vWriteData(0x3E);break;case '?': vWriteData(0x3F);break;case '.': vWriteData(0x2E);break;case ':': vWriteData(0x3A);break;case '0': vWriteData(0x30);break;cas

28、e '1': vWriteData(0x31);break;case '2': vWriteData(0x32);break;case '3': vWriteData(0x33);break;case '4': vWriteData(0x34);break;case '5': vWriteData(0x35);break;case '6': vWriteData(0x36);break;case '7': vWriteData(0x37);break;case '8'

29、: vWriteData(0x38);break;case '9': vWriteData(0x39);break;case 'A': vWriteData(0x41);break;case 'B': vWriteData(0x42);break;case 'C': vWriteData(0x43);break;case 'D': vWriteData(0x44);break;case 'E': vWriteData(0x45);break;case 'F': vWriteData(

30、0x46);break;case 'G': vWriteData(0x47);break;case 'H': vWriteData(0x48);break;case 'I': vWriteData(0x49);break;case 'J': vWriteData(0x4A);break;case 'K': vWriteData(0x4B);break;case 'L': vWriteData(0x4C);break;case 'M': vWriteData(0x4D);break;c

31、ase 'N': vWriteData(0x4E);break;case 'O': vWriteData(0x4F);break;case 'P': vWriteData(0x50);break;case 'Q': vWriteData(0x51);break;case 'R': vWriteData(0x52);break;case 'S': vWriteData(0x53);break;case 'T': vWriteData(0x54);break;case 'U

32、9;: vWriteData(0x55);break;case 'V': vWriteData(0x56);break;case 'W': vWriteData(0x57);break;case 'X': vWriteData(0x58);break;case 'Y': vWriteData(0x59);break;case 'Z': vWriteData(0x5A);break;case 'a': vWriteData(0x61);break;case 'b': vWriteDat

33、a(0x62);break;case 'c': vWriteData(0x63);break;case 'd': vWriteData(0x64);break;case 'e': vWriteData(0x65);break;case 'f': vWriteData(0x66);break;case 'g': vWriteData(0x67);break;case 'h': vWriteData(0x68);break;case 'i': vWriteData(0x69);break

34、;case 'j': vWriteData(0x6A);break;case 'k': vWriteData(0x6B);break;case 'l': vWriteData(0x6C);break;case 'm': vWriteData(0x6D);break;case 'n': vWriteData(0x6E);break;case 'o': vWriteData(0x6F);break;case 'p': vWriteData(0x70);break;case 'q&

35、#39;: vWriteData(0x71);break;case 'r': vWriteData(0x72);break;case 's': vWriteData(0x73);break;case 't': vWriteData(0x74);break;case 'u': vWriteData(0x75);break;case 'v': vWriteData(0x76);break;case 'w': vWriteData(0x77);break;case 'x': vWriteData(0x78);break;case 'y': vWriteDat

溫馨提示

  • 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)論