中文字幕 另类精品,亚洲欧美一区二区蜜桃,日本在线精品视频免费,孩交精品乱子片免费

<sup id="3hn2b"></sup>

    1. <sub id="3hn2b"><ol id="3hn2b"></ol></sub><legend id="3hn2b"></legend>

      1. <xmp id="3hn2b"></xmp>

      2. 新聞中心

        EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > ADC0831模數(shù)轉(zhuǎn)換程序

        ADC0831模數(shù)轉(zhuǎn)換程序

        作者: 時(shí)間:2012-11-10 來(lái)源:網(wǎng)絡(luò) 收藏

        /*
        程序效果:數(shù)碼管顯示AD轉(zhuǎn)換到的一字節(jié)數(shù)據(jù),以顯示
             調(diào)節(jié)相應(yīng)的電位器,顯示數(shù)據(jù)作相應(yīng)的變化
        程序開(kāi)發(fā):http://www.51hei.com
        原理:0831是串行AD芯片,調(diào)節(jié)點(diǎn)位器就是調(diào)節(jié)了輸入0831的模擬電壓的大小,然后通過(guò)數(shù)碼管顯示
        運(yùn)行環(huán)境:51hei單片機(jī)學(xué)習(xí)板
        */
        #includereg52.h>
        #includeintrins.h>
        #define uchar unsigned char
        #define uint unsigned int
        uchar code table[]={0x3f,0x06,0x5b,//數(shù)碼管顯示的數(shù)值
        0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
        sbit scl1=P1^3; //芯片的通信脈沖引腳
        sbit sda1=P1^4; //數(shù)據(jù)傳輸引腳
        sbit px1=P1^5; //片選引腳,即選擇和DS1302
        sbit cs1=P1^6; //片選引腳
        uchar tmpdata[]={0,0,0};
        uchar readad0831();//定義該函數(shù)為讀取的數(shù)據(jù)
        void display(uchar *lp,uchar lc); //顯示子函數(shù)
        void delay(); //延時(shí)子函數(shù)
        void main() // 主函數(shù)
        {
          uchar i=0,tmp;
          px1=0; //選擇該芯片
          while(1)
          {
            i++;
            if(i==255)   //這里為循環(huán)255個(gè)周期讀取一次0831,
            {      //因?yàn)镃PU得運(yùn)行速度很快,所以沒(méi)有必要每一次
              tmp=readad0831(); //讀取數(shù)據(jù),這樣可以充分利用CPU的資源
              i=0;
              tmpdata[0]=tmp/100;//分離百位
               tmp=tmp%100;
              tmpdata[1]=tmp/10; //分離十位
              tmpdata[2]=tmp%10;//分離個(gè)位
            }
          display(tmpdata,3); //輸出顯示
          }
        }
        void display(uchar *lp,uchar lc) //顯示子函數(shù)
        {
          uchar i; //定義局部變量
          P2=0; //端口P2為輸出口
          P1=P10xf8; //P1口的前三位用于控制那個(gè)數(shù)碼管亮,
                 //如果改為P1=0xf8,可能會(huì)出現(xiàn)數(shù)碼管
                //不停的顯示,難以分清顯示的數(shù)值
          for(i=0;ilc;i++)
          {
            P2=table[lp[i]]; //循環(huán)顯示
            delay(); //延時(shí)五個(gè)空指令
            if(i==7) //檢測(cè)是否顯示完8位,完成則直接退出
              //不讓P1口再加一,否則會(huì)影響P1^4口
              break;
            P2=0; //清零端口,準(zhǔn)備顯示下一位
            P1++; //點(diǎn)亮下一個(gè)數(shù)碼管
          }
        }
        void delay() //延時(shí)子函數(shù)
        {
          _nop_();_nop_();_nop_();_nop_();_nop_();
        }
        uchar readad0831() //本函數(shù)是按照ADC0831的協(xié)議編寫(xiě)的
        {
          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=1;
            if(sda1)
              tmp++;
            scl1=1;
            _nop_();
            _nop_();
            scl1=0;
            _nop_();
            _nop_();
          }
          cs1=1;
          return tmp;
        }
        如程序無(wú)法編譯,請(qǐng)去掉所有前導(dǎo)空白。



        評(píng)論


        相關(guān)推薦

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

        關(guān)閉