在线看毛片网站电影-亚洲国产欧美日韩精品一区二区三区,国产欧美乱夫不卡无乱码,国产精品欧美久久久天天影视,精品一区二区三区视频在线观看,亚洲国产精品人成乱码天天看,日韩久久久一区,91精品国产91免费

<menu id="6qfwx"><li id="6qfwx"></li></menu>
    1. <menu id="6qfwx"><dl id="6qfwx"></dl></menu>

      <label id="6qfwx"><ol id="6qfwx"></ol></label><menu id="6qfwx"></menu><object id="6qfwx"><strike id="6qfwx"><noscript id="6qfwx"></noscript></strike></object>
        1. <center id="6qfwx"><dl id="6qfwx"></dl></center>

            新聞中心

            EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 51測溫度并顯示華氏和攝氏程序

            51測溫度并顯示華氏和攝氏程序

            作者: 時間:2016-11-18 來源:網(wǎng)絡(luò) 收藏
            ///////頭文件區(qū)//////////////////////////////////////

            #include"reg51.h"
            #include"intrins.h"
            ////////////////////////////////////////////////////
            /////對于按鍵的位定義//////////////////////////////
            sbit k_TH=P1^0; // 10 16 *
            sbit k_TL=P1^1; //11 15 *
            sbit k_E=P1^2; //12 14 *
            ////////////////////////////////////////////////////
            /////對于溫度傳感器DS18B20的引腳及全局變量定義////////
            sbit DQ_D=P3^2;
            char TH=10; //定義高位寄存器 需要符號
            char TL=0; //定義低位寄存器 需要符號
            float T=0; //定義全局溫度值寄存器
            bit flag_h=0; //定義高溫報警標(biāo)志 1有效
            bit flag_l=0; //定義低溫報警標(biāo)志 1有效
            sbit HEATER=P1^5; //低電平有效
            sbit FAN=P1^3; //低電平有效
            sbit SPEAKER=P1^6; //低電平有效 P15 *
            unsigned int n=0; //風(fēng)扇速度采集當(dāng)中 定時器1用到的倍數(shù)軟件計數(shù)器
            bit flag_COUNTER=0; //計數(shù)器0溢出中斷標(biāo)志 不使用查詢方式 節(jié)省系統(tǒng)資源
            bit flag_capture=0; //速度采樣是否完成標(biāo)志
            unsigned int speed=0;//風(fēng)扇速度
            /////////////////////////////////////////////
            /////對于液晶顯示的引腳及全局變量定義//////////////
            //////////////////////////////////////////////////
            #define DQ_L P2 //聲明數(shù)據(jù)端口
            sbit BG=P2^6; //低電平有效
            sbit E=P1^2;
            sbit RW=P1^1;
            sbit RS=P1^0;
            unsigned char code fig[10]={"0123456789"};
            unsigned char code tab0[]={"CTemper:"};
            unsigned char code tab1[]={"HTemper:"};
            ///////////////////////////////////////////
            //////////中斷標(biāo)志////////////////////////
            bit flag_X0=0;
            ////////////////////////////////////////////
            void delay_us(unsigned int us)
            {
            while(us--)
            {
            _nop_();
            }
            return;
            }
            void delay_ms(unsigned int ms)
            {
            unsigned char i=0;
            while(ms--)
            {
            for(i=0;i<250;i++)
            {
            _nop_();
            _nop_();
            _nop_();
            _nop_();
            }
            }
            return;
            }
            void delay(unsigned int i)
            {
            while(i--);
            }
            ///////////////////以上是通用代碼區(qū)//////////////////////
            ////////下列程序是對溫度傳感器DS18B20控制的實現(xiàn)//////////
            //初始化函數(shù)
            Init_DS18B20(void)
            {
            unsigned char x=0;
            DQ_D=1; //DQ復(fù)位
            delay(8); //稍做延時
            DQ_D=0; //單片機將DQ拉低
            delay(80); //精確延時 大于 480us
            DQ_D=1; //拉高總線
            delay(14);
            x=DQ_D; //稍做延時后 如果x=0則初始化成功 x=1則初始化失敗
            delay(20);
            }
            //讀一個字節(jié)
            ReadOneChar(void)
            {
            unsigned char i=0;
            unsigned char dat = 0;
            for (i=8;i>0;i--)
            {
            DQ_D=0; // 給脈沖信號
            dat>>=1;
            DQ_D=1; // 給脈沖信號
            if(DQ_D)
            dat|=0x80;
            delay(4);
            }
            return(dat);
            }
            //寫一個字節(jié)
            WriteOneChar(unsigned char dat)
            {
            unsigned char i=0;
            for (i=8; i>0; i--)
            {
            DQ_D=0;
            DQ_D=dat&0x01;
            delay(5);
            DQ_D=1;
            dat>>=1;
            }
            }
            //讀取溫度
            unsigned int ReadTemperature(void)
            {
            unsigned char a=0;
            unsigned char b=0;
            unsigned int t=0;
            float tt=0;
            Init_DS18B20();
            WriteOneChar(0xCC); // 跳過讀序號列號的操作
            WriteOneChar(0x44); // 啟動溫度轉(zhuǎn)換
            Init_DS18B20();
            WriteOneChar(0xCC); //跳過讀序號列號的操作
            WriteOneChar(0xBE); //讀取溫度寄存器等(共可讀9個寄存器) 前兩個就是溫度
            a=ReadOneChar();
            b=ReadOneChar();
            t=b;
            t<<=8;
            t=t|a;
            tt=t*0.0625; //將溫度的高位與低位合并 賦予tt的是測得的溫度 是一個單精度的浮點數(shù)據(jù)
            T=tt;
            //////////// 寫溫度標(biāo)記
            if(T>TH)
            {
            flag_h=1;
            flag_l=0;
            }
            else if(T{
            flag_h=0;
            flag_l=1;

            本文引用地址:http://www.biyoush.com/article/201611/315790.htm

            }
            else if(T>=TL&&T<=TH)
            {
            flag_h=0;
            flag_l=0;
            }
            ///////////////////
            t=tt*10+0.5; //對結(jié)果進行4舍5入 //這部算法非常重要
            return(t);
            }
            void DS18B20_deal_data() //溫度數(shù)據(jù)處理
            {
            unsigned char high,mid,low,high1,mid1,low1;
            unsigned int temp,temp2,l=0,l1=0;
            void DisplayOneChar(unsigned char x,unsigned char y,unsigned char __data);
            //////////////溫度數(shù)據(jù)處理////////////////
            temp=ReadTemperature();
            temp2=(temp-10)*9/5+50;
            if(temp>=1000)
            {
            temp/=10;l=1;
            }
            if(temp2>=1000)
            {
            temp2/=10; l1=1;
            }
            high=temp/100%10;
            mid=temp/10%10;
            low=temp%10;
            high1= temp2/100%10;
            mid1= temp2/10%10;
            low1= temp2%10;
            ///////////數(shù)據(jù)顯示/////////////////////////////////////////
            if(temp<0) DisplayOneChar(0x08,0,-);
            if(l==1)
            {
            DisplayOneChar(0x09,0,1);/////位數(shù)顯示
            DisplayOneChar(0x0a,0,fig[high]);
            DisplayOneChar(0x0b,0,fig[mid]);
            DisplayOneChar(0x0c,0,.);
            DisplayOneChar(0x0d,0,fig[low]);
            }
            else
            {
            DisplayOneChar(0x09,0,fig[high]);/////位數(shù)顯示
            DisplayOneChar(0x0a,0,fig[mid]);
            DisplayOneChar(0x0b,0,.);
            DisplayOneChar(0x0c,0,fig[low]);
            }
            if(temp2<0)
            DisplayOneChar(0x48,1,-);
            if(l1==1)
            {
            DisplayOneChar(0x49,1,1);/////位數(shù)顯示
            DisplayOneChar(0x4a,1,fig[high]);
            DisplayOneChar(0x4b,1,fig[mid]);
            DisplayOneChar(0x4c,1,.);
            DisplayOneChar(0x4d,1,fig[low]);
            }
            else
            {
            DisplayOneChar(0x49,1,fig[high1]);/////位數(shù)顯示
            DisplayOneChar(0x4a,1,fig[mid1]);
            DisplayOneChar(0x4b,1,.);
            DisplayOneChar(0x4c,1,fig[low1]);
            }
            }
            /////////////////////////////////////////////////////////////////
            ///////////////////以下是液晶代碼區(qū)/////////////////////////////
            //////////////////////////////////液晶指令集/////////////
            void lcd_findbusy() //忙查詢
            {
            E=0;
            RS=0;
            RW=1;
            E=1;
            while(DQ_L&0x80);
            delay_us(4);
            E=0;
            }
            void lcd_wcmd(unsigned char cmd)//寫命令
            {
            lcd_findbusy();
            delay_us(1);
            E=0;
            RS=0;
            RW=0;
            DQ_L=cmd;
            E=1;
            lcd_findbusy();
            delay_us(4);
            E=0;
            }
            void lcd_wdata(unsigned char _data) //寫數(shù)據(jù)
            {
            lcd_findbusy();
            delay_us(1);
            E=0;
            RS=1;
            RW=0;
            DQ_L=_data;
            E=1;
            lcd_findbusy();
            delay_us(4);
            E=0;
            }
            void lcd_pos(unsigned char adress) //設(shè)定顯示位置
            {
            lcd_findbusy();
            delay_us(1);
            lcd_wcmd(adress|0x80); //注意用或運算,否則第一位不是1,地址數(shù)據(jù)寫入錯誤
            lcd_findbusy();
            return;
            }
            void lcd_first() //液晶顯示初始化
            {
            BG=0;
            delay_ms(1);
            lcd_wcmd(0x38); //顯示設(shè)置 雙行 8線 5*10點陣
            delay_ms(1);
            lcd_wcmd(0x08); //顯示關(guān)閉
            delay_ms(1);
            lcd_wcmd(0x01); //顯示清屏
            delay_ms(1);
            lcd_wcmd(0x06); //光標(biāo)移動設(shè)置__向右
            delay_ms(1);
            lcd_wcmd(0x0c); //顯示開 不顯示光標(biāo) 光標(biāo)不閃爍
            delay_ms(1);
            lcd_findbusy();
            return;
            }
            void DisplayOneChar(unsigned char x,unsigned char y,unsigned char __data)
            {
            y=y&0x01;
            x=x&0x0f;
            if(y)
            x=x|0x40;/// 如果要顯示第二行
            lcd_pos(x);
            lcd_wdata(__data);
            return;
            }
            void DisplayListChar(unsigned char x,unsigned char y,unsigned char code *__data)
            {
            unsigned char j=0;
            y=y&0x01;
            x=x&0x0f;
            while(x<=0x0f&&__data[j]!=