• <li id="00i08"><input id="00i08"></input></li>
  • <sup id="00i08"><tbody id="00i08"></tbody></sup>
    <abbr id="00i08"></abbr>
  • 新聞中心

    EEPW首頁 > 嵌入式系統 > 設計應用 > 數碼管顯示的ADC0831電壓表程序

    數碼管顯示的ADC0831電壓表程序

    作者: 時間:2012-11-10 來源:網絡 收藏
    /*
    程序效果:0.00-5.00U電壓,調節電位器,得到
         的2腳電壓值。
    注:測量時先把電位器調節到中間,也就是2.5U,但切記
      所測的引腳的電壓值不能超過5U,否則會燒壞
       芯片和單片機,小心哦。
    程序版權所有:http://www.51hei.com,如無法編譯,請去掉所有前導空白。
    */
    #includereg52.h>
    #includeintrins.h>
    #define uchar unsigned char
    #define uint unsigned int
    uchar code table[]={
    0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,//共陰的數碼管的顯示值為0-9
    0x8f,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef,//顯示值為:帶有小數點的0-9
    0x40,0x3e,0x00}; //分別顯示“-”,U(伏的單位),空表
    sbit scl1=P1^3;
    sbit sda1=P1^4;
    sbit px1=P1^5;
    sbit cs1=P1^6;
    uchar tmpdata[]={0,0,0,0};
    uchar readad0831();
    void display(uchar *lp,uchar lc);
    void delay();
    void main()
    {
      uint i=0,tmp; //這要定位為整型,防止數據溢出
      px1=0;
      while(1)
      {
        i++;
        if(i==255)
        {
           i=0;
          tmp=readad0831()*100; //這里乘以100,是保留兩位小數的意思
          tmp=tmp/51;
          tmpdata[0]=tmp/100; //得到百位數,其實是原來的個位數
          tmpdata[0]+=10; //這里加上10,是因為帶小數點的數字在后面十位
          tmp=tmp%100;
           tmpdata[1]=tmp/10; //得到十位,即小數點的后一位
          tmpdata[2]=tmp%10; //得到各位,即小數點的第二位
          tmpdata[3]=21; //加上單位U,即伏
        }
        display(tmpdata,4); //調用顯示子函數
      }
    }
    void display(uchar *lp,uchar lc)
    {
      uchar i;
      P2=0;
      P1=P10xf8; //防止改變后五位數
      for(i=0;ilc;i++)
      {
        P2=table[lp[i]];
        delay();
        if(i==7)
          break;
        P2=0;
        P1++;
      }
    }
    uchar readad0831()//根據協議編寫的語句
    {
      uchar i=0,tmp=0;
      sda1=1;
      cs1=0;
      _nop_();
      _nop_();
      scl1=0;
      _nop_();
      _nop_();
      scl1=1;
      _nop_();
      _nop_();
      scl1=0;
      _nop_();
      _nop_();
      scl1=1;
      _nop_();
      _nop_();
      scl1=0;
      _nop_();
      _nop_();
      for(i=0;i8;i++)
      {
        tmp=_crol_(tmp,1);
        if(sda1)
          tmp++;
        scl1=1;
        _nop_();
        _nop_();
        scl1=0;
        _nop_();
         _nop_();
      }
      cs1=1;
      return tmp;
    }
    void delay() //延時子函數
    {
       _nop_();_nop_();_nop_();_nop_();_nop_();
    }


    評論


    相關推薦

    技術專區

    關閉
    主站蜘蛛池模板: 汉源县| 合作市| 乡宁县| 霍林郭勒市| 合肥市| 勃利县| 鸡东县| 全州县| 雷波县| 余姚市| 施秉县| 方城县| 临沂市| 大宁县| 普宁市| 鹤岗市| 建瓯市| 文山县| 临武县| 通州区| 渝中区| 鞍山市| 黄骅市| 桃园县| 台东县| 怀来县| 永安市| 霸州市| 河曲县| 唐海县| 达州市| 敦化市| 漳浦县| 康保县| 彭山县| 饶河县| 镇平县| 呼玛县| 吴川市| 信丰县| 余干县|