protuesDS18B20仿真.doc_第1頁
protuesDS18B20仿真.doc_第2頁
protuesDS18B20仿真.doc_第3頁
protuesDS18B20仿真.doc_第4頁
protuesDS18B20仿真.doc_第5頁
已閱讀5頁,還剩2頁未讀 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

程序 代碼#include #include #define uint unsigned int#defineuchar unsigned char#define nops(); _nop_();_nop_();_nop_();_nop_();sbit DQ=P30;uchar code led = 0x3f,0x06,0x5b,0x4f, 0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71 ;uchar code leddg = 0xbf,0x86,0xdb,0xcf, 0xe6,0xed,0xfd,0x87, 0xff,0xef,0xf7,0xfc ;void display (double x); void delayms(uint z);void delay1(uint z);uint ds18b20();uchar reset18b20();void main () double a; while(1)a=ds18b20();display(a); /void delayms(uint z) /延時函數(shù) uint x,y;for(x=z;x0;x-)for(y=110;y0;y-); /void delay1(uint z) while(-z); /void display (double x) /顯示函數(shù)uint a,b,d,e; int c; double g,h; if (x=128)c=(int)x;/45 10.12 a=c/100;/提取個位,百位b=c%100/10;d=c%100%10;g=x-c;/0.119999 有誤差/*if(int)(g*100)+1)-g*100)=0.0001 ) /判斷下 消除誤差g=g+0.01;d=(int)(g*10);h=10*g-d;e=(int)(h*10);*/ e=(int)(10*g); P2=0xfe;P0=leda;delayms(10);P2=0xfd;P0=ledb;delayms(10);P2=0xfb;P0=leddgd;delayms(10);P2=0xf7;P0=lede;delayms(10);else c=(int)(256-x);b=c/10;d=c%10;e=0; P2=0xfe;P0=0x40;delayms(10);P2=0xfd;P0=ledb;delayms(10);P2=0xfb;P0=leddgd;delayms(10);P2=0xf7;P0=lede;delayms(10);/ uchar reset18b20() /復位18B20 uchar a; DQ=1;_nop_();_nop_(); DQ=0;delay1(80);DQ=1;nops();a=DQ;delay1(20);return a ; / void write (uchar dat) /向18B20里寫 uchar i;DQ=1;_nop_();for(i=0;i=1; / uchar read() /讀取18b20 uchar i,dat=0;DQ=1;_nop_();for(i=0;i=1;DQ=1;nops();if(DQ)dat|=0x80;delay1(30);DQ=1;return dat; / uint ds18b20() /啟動18B20溫度傳感器uint a,b;reset18b20();write(0xcc); /跳過ID地址write(0x44); /啟動溫度轉換reset18b20();write(0xcc);write(0xbe

溫馨提示

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

評論

0/150

提交評論