<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > ds18b20電冰箱控制系統(tǒng)

          ds18b20電冰箱控制系統(tǒng)

          作者: 時(shí)間:2016-12-01 來源:網(wǎng)絡(luò) 收藏

          /*******************************DS復(fù)位函數(shù)******************************/
          void ow_reset(void)
          {
          uchar presence=1;

          本文引用地址:http://www.ex-cimer.com/article/201612/324235.htm

          while(presence)
          {
          while(presence)
          {
          DQ=1; //DQ復(fù)位
          DQ=0; //單片機(jī)將DQ拉低
          delay(50); //延時(shí)550毫秒
          DQ=1; //拉高總線
          delay(6);
          presence=DQ; //如果=0則初始化成功 =1則初始化失敗
          }
          delay(45);
          presence=~DQ;
          }
          DQ=1;
          }
          /*****************************DS寫命令函數(shù)*********************************/
          void write_byte(uchar dat) //向1-WIRE總線上寫一字節(jié)
          {
          uchar i = 0 ;
          for (i = 8 ; i > 0 ; i--)
          {
          DQ = 0 ;
          DQ = dat&0x01 ;
          delay(7) ; //0時(shí)序延時(shí)至少60US
          DQ = 1 ;
          dat>>=1 ;
          }
          }
          /*******************************DS讀一字節(jié)函數(shù)****************************************************/
          uchar read_byte(void)
          {
          uchar i = 0 ;
          uchar dat = 0 ;

          for (i = 8 ; i > 0 ; i--)
          {
          DQ = 0 ; // 給脈沖信號
          dat >>= 1 ;
          DQ = 1 ; // 給脈沖信號

          if(DQ)
          dat |= 0x80 ;
          delay(7) ;
          }
          return (dat) ;
          }

          /******************************讀出溫度函數(shù)*************************************************/
          void read_temp(void)
          {
          ow_reset();
          write_byte(0xcc);//skip ROM
          write_byte(0x44);// 啟動(dòng)溫度轉(zhuǎn)換

          ow_reset();
          write_byte(0xcc);
          write_byte(0xbe); //讀取溫度寄存器

          temp_data[0]=read_byte(); //溫度低8位
          temp_data[1]=read_byte(); //溫度高8位

          }


          /*****************第二個(gè)ds18b20處理函數(shù)******************/

          /******************************讀出溫度函數(shù)*************************************************/
          void read_temp2(void)
          {
          ow_reset2();
          write_byte2(0xcc);//skip ROM
          write_byte2(0x44);// 啟動(dòng)溫度轉(zhuǎn)換

          ow_reset2();
          write_byte2(0xcc);
          write_byte2(0xbe); //讀取溫度寄存器

          temp_data[0]=read_byte2(); //溫度低8位
          temp_data[1]=read_byte2(); //溫度高8位

          }
          /********************************計(jì)算溫度子函數(shù)**********************************************/
          void temp_work2(void)
          {
          disp_buff[4]=10;

          if(temp_data[1]>127)
          {temp_data[1]=(255-temp_data[1]);temp_data[0]=(255-temp_data[0])+1;disp_buff[4]=11;} //負(fù)溫度求補(bǔ)碼
          tt2=((temp_data[0]&0xf0)>>4)|((temp_data[1]&0x0f)<<4) ;
          disp_buff[5]=tt2/10;
          disp_buff[6]=tt2%10;
          disp_buff[7]=0;

          if(!disp_buff[5])
          disp_buff[5]=10;

          }
          /**********eeprom函數(shù)******************/
          ////////延時(shí)//////////////////////////////////
          voidflash()
          { ; ; }
          void x24c02_init() //24c02初始化子程序
          {
          scl=1; //拉高
          flash(); //延時(shí)
          sda=1;
          flash();//同上
          }
          void start() //啟動(dòng)I2C總線
          {
          sda=1;
          flash();
          scl=1;
          flash();
          sda=0;
          flash();
          scl=0;
          flash();
          }
          void stop() //停止I2C總線
          {
          sda=0;
          flash();
          scl=1;
          flash();
          sda=1;
          flash();
          }
          void writex(uchar j) //寫一個(gè)字節(jié)
          {
          uchar i,temp;
          temp=j;
          for (i=0;i<8;i++)
          {
          temp=temp<<1;
          scl=0;
          flash();
          sda=CY;
          flash();
          scl=1;
          flash();
          }

          scl=0;
          flash();
          sda=1;
          flash();
          }
          char readx() //讀一個(gè)字節(jié)
          {
          char i,j,k=0;
          scl=0;
          flash();
          sda=1;
          for (i=0;i<8;i++)
          {
          flash();
          scl=1;
          flash();
          if (sda==1) j=1;
          else j=0;
          k=(k<<1)|j;
          scl=0;
          }
          flash();
          return(k);
          }
          void clock() //I2C總線時(shí)鐘,在此作第個(gè)時(shí)鐘
          {

          scl=1;
          flash();
          while (sda==1);//如果SDA為0即收到應(yīng)答則跳過,為1則等應(yīng)答
          scl=0;
          flash();
          }

          ////////從24c02的地址address中讀取一個(gè)字節(jié)數(shù)據(jù)/////

          char x24c02_read(uchar address)
          {
          char i;
          start();
          writex(0xa0);
          clock();//第9個(gè)時(shí)鐘
          writex(address);//選中24C02
          clock();
          start();
          writex(0xa1); //選中24C02中的存儲(chǔ)器地址
          clock();
          i=readx();
          stop();
          delay(10);
          return(i);
          }

          void x24c02_write(char address,char info)
          {
          EA=0;
          start();
          writex(0xa0);
          clock();
          writex(address);
          clock();
          writex(info);
          clock();
          stop();
          EA=1;
          delay(50);
          }

          /*******************************主函數(shù)**********************************************************/
          void main (void)
          {
          char i,num1,num2;
          TMOD=0x11; //定時(shí)器0設(shè)置方式1,定時(shí)器1設(shè)置方式1
          TH0=0xf4; //定時(shí)3ms 為了計(jì)數(shù)值顯示的需要
          TL0=0x48;

          TH1=0xbf; //定時(shí)16.6ms 為了計(jì)數(shù)值顯示的需要
          TL1=0x28;

          EA=1; //開總中斷
          ET0=1; //定時(shí)器中斷使能
          ET1=1;
          TR0=1; //啟動(dòng)定時(shí)器0
          TR1=1;

          P2=0x00;

          kmbj=0;
          motordc=0;

          hghlgt=0;
          setlclgt =0;
          syslgt=1;

          opndrspk=0;


          主程序略。


          上一頁 1 2 下一頁

          關(guān)鍵詞: ds18b20電冰箱控制系

          評論


          技術(shù)專區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();