




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、#include<reg52.h>sbit s2=P00;sbit led=P13;unsigned char wendushangxian=0;sbit DQ=P16;sbit wei1=P30;sbit wei2=P31;sbit wei3=P32;sbit wei4=P33;sbit key_Max_jia=P00;sbit key_Max_jian=P01;sbit key_Min_jia=P02;sbit key_Min_jian=P03;sbit dianji_jian=P12;sbit dianji_jia=P17;sbit Led_tempreture_Max=P1
2、3;sbit Led_tempreture_Min=P14;sbit Led_normal=P15;unsigned char num11=0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf;int tempreture_Max=40;int tempreture_Min=-10;void delay_mylself(int temp)unsigned int i,j;for(i=0;i<temp;i+)for(j=0;j<1140;j+);void delay(unsigned int i) /如果i是unsigend c
3、har類型,則會出現(xiàn)錯誤結(jié)果while(i-);void DS18B20_Init(void)/初始化unsigned char flag=0;DQ = 1; /DQ復(fù)位delay(1); DQ = 0; /單片機將DQ拉低 delay(80); /精確延時 大于 480us小于960us DQ = 1; /拉高總線 delay(6);while(DQ);while(!DQ); /flag=DQ; /稍做延時后 如果flag=0則初始化成功 flag=1則初始化失敗/delay(30);unsigned char Read(void)/讀字節(jié)unsigned char i=0; unsigne
4、d char dat = 0; for (i=8;i>0;i-) DQ = 0; / 給脈沖信號 dat>>=1; DQ = 1; / 給脈沖信號 if(DQ) dat|=0x80; delay(5); return(dat);void Write(unsigned char dat)/寫字節(jié)unsigned char i=0; for (i=8; i>0; i-) DQ = 0; DQ = dat&0x01; delay(5); DQ = 1; dat>>=1; void init()wei1=0;wei2=0;wei3=0;wei4=0;void
5、 Display(unsigned int temp)unsigned char one,two,three,four;int wendu=0;if(temp<=0xf000)temp>>=4; /右移4位,相當(dāng)于乘0.0625,將溫度化為十進制 /temp*=10; /擴大10倍,顯示一位小數(shù)one=temp/1000; /千位two=temp%1000/100; /百位three=temp%1000%100/10; /十位four=temp%1000%100%10; /個位wendu=temp;elsetemp=temp;temp+=1;temp>>=4;on
6、e=10; /負數(shù) two=temp%1000/100; /百位three=temp%1000%100/10; /十位four=temp%1000%100%10; /個位wendu=-temp;if(wendu>tempreture_Max)Led_tempreture_Max=0;Led_tempreture_Min=1;Led_normal=1;dianji_jian=1;dianji_jia=0;else if(wendu<tempreture_Min)Led_tempreture_Max=1;Led_tempreture_Min=0;Led_normal=1; dianji
7、_jia=1;dianji_jian=0;elseLed_tempreture_Max=1;Led_tempreture_Min=1;Led_normal=0; dianji_jian=0; dianji_jia=0;/第1位wei1=1;wei2=0;wei3=0;wei4=0;P2=numone;delay_mylself(1);/第2位wei1=0;wei2=1;wei3=0;wei4=0;P2=numtwo;delay_mylself(1);/第3位wei1=0;wei2=0;wei3=1;wei4=0;P2=numthree;delay_mylself(1);/第4位wei1=0;w
8、ei2=0;wei3=0;wei4=1;P2=numfour;delay_mylself(10);void common_display(int temp)unsigned char one,two,three,four;one=temp/1000; /千位two=temp%1000/100; /百位three=temp%1000%100/10; /十位four=temp%1000%100%10; /個位if(temp<0)temp=-temp;two=temp%1000/100; /百位three=temp%1000%100/10; /十位four=temp%1000%100%10;
9、/個位/第1位wei1=1;wei2=0;wei3=0;wei4=0;P2=num10;delay_mylself(50);else/第1位wei1=1;wei2=0;wei3=0;wei4=0;P2=numone;delay_mylself(50);/第2位wei1=0;wei2=1;wei3=0;wei4=0;P2=numtwo;delay_mylself(50);/第3位wei1=0;wei2=0;wei3=1;wei4=0;P2=numthree;delay_mylself(50);/第4位wei1=0;wei2=0;wei3=0;wei4=1;P2=numfour;delay_myl
10、self(60);void key()unsigned char flag=0;if(key_Max_jia=0)flag=1;tempreture_Max+=1;if(tempreture_Max>125) tempreture_Max=125;while(!key_Max_jia); /按鍵松手檢測else if(key_Max_jian=0)flag=2;tempreture_Max-=1;if(tempreture_Max<tempreture_Min) tempreture_Max=tempreture_Min;while(!key_Max_jian); /按鍵松手檢測e
11、lse if(key_Min_jia=0)flag=3;tempreture_Min+=1;if(tempreture_Min>tempreture_Max) tempreture_Min=tempreture_Max;while(!key_Min_jia);/按鍵松手檢測else if(key_Min_jian=0)flag=4;tempreture_Min-=1;if(tempreture_Min<-55) tempreture_Min=-55;while(!key_Min_jian);/按鍵松手檢測if(flag=1|flag=2)common_display(tempreture_Max);delay_mylself(200);flag=0;else if(flag=4|flag=3)common_display(tempreture_Min);delay_mylself(200);flag=0;void main() unsigned int temp;unsigned char tl=0,th=0; while(1) DS18B20_Init(); Write(0xCC); / 跳過讀序號列號的操作 Write(0x44);
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年高新創(chuàng)業(yè)區(qū)物業(yè)管理協(xié)議
- 五年級下冊數(shù)學(xué)教案 -1.4 公因數(shù) ︳西師大版
- 2024-2025學(xué)年三年級下冊數(shù)學(xué) 一 除法《練習(xí)二》(教案)
- 六年級下冊數(shù)學(xué)教案 圖形的認識 北師大版
- 2025年貴陽康養(yǎng)職業(yè)大學(xué)單招職業(yè)技能測試題庫帶答案
- 化學(xué)-四川省金太陽2025屆高三2月開學(xué)考試試題和答案
- 2025年惠州城市職業(yè)學(xué)院單招職業(yè)技能測試題庫審定版
- 2025年廣西衛(wèi)生職業(yè)技術(shù)學(xué)院單招職業(yè)傾向性測試題庫一套
- 2025年湖北輕工職業(yè)技術(shù)學(xué)院單招職業(yè)傾向性測試題庫新版
- 2025年湖北科技職業(yè)學(xué)院單招職業(yè)傾向性測試題庫完整
- 新《卷煙營銷》理論知識考試題庫(附答案)
- 三年級下冊語文核心素養(yǎng)教案電子版
- 中考英語688高頻詞大綱詞頻表
- 知識產(chǎn)權(quán)保護與跨境執(zhí)法合作
- 肉類食品配送服務(wù)投標方案(技術(shù)方案)
- 含新能源發(fā)電接入的電力系統(tǒng)低頻振蕩阻尼控制研究綜述
- 財務(wù)管理學(xué)(第10版)課件 第3章 財務(wù)分析
- NB-T32019-2013太陽能游泳池加熱系統(tǒng)技術(shù)規(guī)范
- 道閘施工方案
- 寺廟佛事活動方案設(shè)計
- 湘教版高中地理必修2全冊導(dǎo)學(xué)案
評論
0/150
提交評論