<acronym id="xonnx"></acronym>
      <td id="xonnx"></td>
    1. <pre id="xonnx"></pre>

      1. 專注電子技術學習與研究
        當前位置:單片機教程網 >> MCU設計實例 >> 瀏覽文章

        HR202程序,基本按照數據手冊寫的

        作者:X弓雖   來源:轉自X弓雖   點擊數:  更新時間:2014年07月27日   【字體:

        最近用到了HR202網上的資料實在是太少了,按照數據手冊上寫的程序更少,沒辦法,自己一點一點的敲吧!
              首先你得確定普通的51單片機不能按照數據手冊上的方法,沒有方向寄存器的雙向IO口充電時間很難確定。
        本實驗使用的是LCD1602,HR202,STC12LE60S2

        J15,J16,J17分別和P1.3,P1.4,P1.5相連
        實驗代碼如下,1602的驅動找度娘吧,貼上來有點亂


        #include"reg52.h"
        #include "typedef.h"
        #include "LCD1602.H"

        sbit hr202 = P1^3;
        sbit ref = P1^4;
        sbit test = P1^5;

        unsigned long time0int = 0;
        unsigned long time_ref = 0;    //精確到us
        unsigned long time_hr = 0;
        unsigned int res_hr;
        unsigned char humidity = 0;

        void res2humidity(unsigned int res);

        void Time0_Init()
        {
         TMOD = 0X01;
         TH0 = (65536-50000)/256;
         TL0 = (65536-50000)%6;
         ET0 = 1;
         EA = 1;
        }


        void main()
        {
         Lcd_Init();
         Write_String(0x80,"humidity:");
         Time0_Init();
         while(1)
         {
          P1M1 = 0X00;
          test = 0;//都設置為0,讓電容放點
          hr202 = 0;
          ref = 0;
          delayms(10);
          //標準電阻充電
          P1M1 = 0X28; //高阻輸入
          ref = 1;
          TR0 = 1;//start time0
          while(!test);
          TR0 = 0;//STOP
          time_ref = 50000*time0int + (TH0*256+TL0);//精確到us
          TH0 = (65536-50000)/256;
          TL0 = (65536-50000)%6;
          time0int = 0;
          //放電
          P1M1 = 0X00;
          test = 0;//都設置為0,讓電容放點
          hr202 = 0;
          ref = 0;
          delayms(10);

          //hr202充電
          P1M1 = 0X30;
          hr202 = 1;
          TR0 = 1;
          while(!test);
          TR0 = 0;
          time_hr = 50000*time0int + (TH0*256+TL0);//精確到us
          TH0 = (65536-50000)/256;
          TL0 = (65536-50000)%6;
          time0int = 0;
         
          //計算hr202電阻
          res_hr = time_hr*100/time_ref;     //結果擴大了10倍
          res2humidity(res_hr);
          Write_Char(0xc0,humidity/10+48);
          Write_Char(0xc1,humidity+48);
         }
        }

        //查表函數
        void res2humidity(unsigned int res)
        {
          unsigned char humidity10 = 0; //十位
          unsigned char humidity1 = 0;//個位
          if((res>28)&&(res<50000))//濕度范圍在20%~90%之間
          {
            if((res>28)&&(res<40))
            {humidity10 = 8;humidity1 = 10 - (res-28)*0.4;}    //按直線關系處理 數據不是太準確
            if((res>40)&&(res<57))
            {humidity10 = 8;humidity1 = 5 - (res-40)*0.29;}
            if((res>57)&&(res<84))
            {humidity10 = 7;humidity1 = 10 - (res-57)*0.185;}
            if((res>84)&&(res<130))
            {humidity10 = 7;humidity1 = 5 - (res-84)*0.11;}
            if((res>130)&&(res<195))
            {humidity10 = 6;humidity1 = 10 - (res-130)*0.076;}
            if((res>195)&&(res<310))
            {humidity10 = 6;humidity1 = 5 - (res-195)*0.043;}
            if((res>310)&&(res<490))
            {humidity10 = 5;humidity1 = 10 - (res-310)*0.027;}
            if((res>490)&&(res<870))
            {humidity10 = 5;humidity1 = 5 - (res-490)*0.0131;}
            if((res>870)&&(res<1600))
            {humidity10 = 4;humidity1 = 10 - (res-870)*0.0068;}
            if((res>1600)&&(res<3100))
            {humidity10 = 4;humidity1 = 5 - (res/100-16)*0.33;}
            if((res>3100)&&(res<6300))
            {humidity10 = 3;humidity1 = 10 - (res/100-31)*0.156;}
            if((res>6300)&&(res<13000))
            {humidity10 = 3;humidity1 = 5 - (res/100-63)*0.07;}
            if((res>13000)&&(res<26000))
            {humidity10 = 2;humidity1 = 10 - (res/1000-13)*0.38;}
            if((res>26000)&&(res<5000))
            {humidity10 = 2;humidity1 = 5 - (res/1000-26)*0.208;}
          }
          humidity = humidity10*10+humidity1;
        }
        void time0_ser() interrupt 1
        {
         time0int++;
         TH0 = (65536-50000)/256;
         TL0 = (65536-50000)%6;
        }
        感覺有用的話請點個

        關閉窗口

        相關文章

        欧美性色欧美精品视频,99热这里只有精品mp4,日韩高清亚洲日韩精品一区二区,2020国自产拍精品高潮