乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      51/51單片機第9課:DS18B20溫度檢測系統(tǒng)

       xpxys99 2019-09-04

      51/51單片機第9課:DS18B20溫度檢測系統(tǒng)

      51/51單片機第9課:DS18B20溫度檢測系統(tǒng)

      #include <reg51.h>//頭文件

      #define uint unsigned int//宏定義

      #define uchar unsigned char //宏定義

      sbit DQ=P3^2;//18B20的2腳與單片機P3.2口相接

      sbit P10=P1^0;//數(shù)碼管位選引腳P1.0

      sbit P11=P1^1;//數(shù)碼管位選引腳P1.1

      uchar temp;

      code unsigned char sz []={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};//0-9數(shù)組

      void delay (uint t);//延時函數(shù)聲明

      void delayms(uint a);//for語句延時函數(shù)聲明

      void init();//18B20初始化程序聲明

      void write (uchar dat);//寫1字節(jié)程序聲明

      uchar read ();//讀1字節(jié)程序聲明

      void display();//顯示程序聲明

      uchar readtemp();//讀溫度程序聲明

      void delay (uint t)//延時函數(shù)

      {

      while(t--);

      }

      void delayms(uint a) //for語句延時函數(shù)

      {

      uint x,y;

      for(x=a;x>0;x--)

      for(y=110;y>0;y--);

      }

      void init ()//18B20初始化程序

      {

      uchar n;

      DQ=1;

      delay(8);

      DQ=0;

      delay(80);

      DQ=1;

      delay(8);

      n=DQ;

      delay(4);

      }

      void write (uchar dat)//寫1字節(jié)程序

      {

      uchar i;

      for (i=0;i<8;i++)

      {

      DQ=0;

      DQ=dat&0x01;

      delay (4);

      DQ=1;

      dat>>=1;//dat=dat>>1

      }

      delay(4);

      }

      uchar read ()//讀1字節(jié)程序

      {

      uchar i,value;

      for (i=0;i<8;i++)

      {

      DQ=0;

      value>>=1;

      DQ=1;

      if(DQ)

      value|=0x80;

      delay(4);

      }

      return value;

      }

      uchar readtemp()//讀溫度程序

      {

      uchar a,b;

      init();

      write (0xcc);

      write (0x44);

      delay (300);

      init ();

      write (0xcc);

      write (0xbe);

      a=read();

      b=read();

      b<<=4;

      b+=(a&0xf0)>>4;

      return b;

      }

      void display ()//顯示程序

      {

      P10=0;

      P0=sz[temp/10];

      delayms(2);

      P10=1;

      P11=0;

      P0=sz[temp%10];

      delayms(2);

      P11=1;

      }

      void main()//主程序

      {

      while(1)

      {

      temp=readtemp();

      display ();

      }

      }

        本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
        轉(zhuǎn)藏 分享 獻花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多