在线看毛片网站电影-亚洲国产欧美日韩精品一区二区三区,国产欧美乱夫不卡无乱码,国产精品欧美久久久天天影视,精品一区二区三区视频在线观看,亚洲国产精品人成乱码天天看,日韩久久久一区,91精品国产91免费

<menu id="6qfwx"><li id="6qfwx"></li></menu>
    1. <menu id="6qfwx"><dl id="6qfwx"></dl></menu>

      <label id="6qfwx"><ol id="6qfwx"></ol></label><menu id="6qfwx"></menu><object id="6qfwx"><strike id="6qfwx"><noscript id="6qfwx"></noscript></strike></object>
        1. <center id="6qfwx"><dl id="6qfwx"></dl></center>

            新聞中心

            0832ADC的51測(cè)試程序

            作者: 時(shí)間:2016-11-13 來(lái)源:網(wǎng)絡(luò) 收藏
            #include"reg52.h"

            #include
            #include"intrins.h"

            本文引用地址:http://www.biyoush.com/article/201611/316339.htm

            //==========================================================
            sbit CS=P3^0; //使能片選
            sbit CLK=P3^1; //時(shí)鐘
            sbit Do=P3^2; //數(shù)據(jù)輸出
            sbit Di=P3^2; //數(shù)據(jù)輸入
            sbit Do2=P3^3; //數(shù)據(jù)輸出
            sbit Di2=P3^3; //數(shù)據(jù)輸入
            sbit Do3=P3^4; //數(shù)據(jù)輸出
            sbit Di3=P3^4; //數(shù)據(jù)輸入
            sbit Do4=P3^5; //數(shù)據(jù)輸出
            sbit Di4=P3^5; //數(shù)據(jù)輸入
            sbit Do5=P3^6; //數(shù)據(jù)輸出
            sbit Di5=P3^6; //數(shù)據(jù)輸入

            unsigned char data_f=0,data_c=0,data_f2=0,data_c2=0,data_f3=0,data_c3=0,data_f4=0,data_c4=0,data_f5=0,data_c5=0; //data_f正確順序 data_c逆序

            unsigned char last[5]; //記錄上一時(shí)刻各AD轉(zhuǎn)換得到的值
            unsigned char current[5]; //記錄此次AD轉(zhuǎn)換得到的值

            int left = 0; //記錄0.1秒內(nèi)電機(jī)向左轉(zhuǎn)動(dòng)的步數(shù)
            int right = 0;//記錄0.1秒內(nèi)電機(jī)向右轉(zhuǎn)動(dòng)的步數(shù)

            sbit RS = P2^4;//Pin4
            sbit RW = P2^5; //Pin5
            sbit E = P2^6;//Pin6

            #define Data P0 //數(shù)據(jù)端口

            char data TimeNum[]=" ";
            char data Test1[]=" ";


            /******************************************************************/
            /* 函數(shù)聲明 */
            /******************************************************************//***************************************************************/
            void DelayUs(unsigned char us)//delay us
            {
            unsigned char uscnt;
            uscnt=us>>1;/* Crystal frequency in 12MHz*/
            while(--uscnt);
            }
            /******************************************************************/
            void DelayMs(unsigned int ms)//delay Ms
            {
            while(--ms)
            {
            DelayUs(250);
            DelayUs(250);
            DelayUs(250);
            DelayUs(250);
            }
            }
            void WriteCommand(unsigned char c)
            {
            DelayMs(5);//short delay before operation
            E=0;
            RS=0;
            RW=0;
            _nop_();
            E=1;
            Data=c;
            E=0;
            }
            /****************************************************************/
            void WriteData(unsigned char c)
            {
            DelayMs(5); //short delay before operation
            E=0;
            RS=1;
            RW=0;
            _nop_();
            E=1;
            Data=c;
            E=0;
            RS=0;
            }
            /*********************************************************************/
            void ShowChar(unsigned char pos,unsigned char c)
            {
            unsigned char p;
            if (pos>=0x10)
            p=pos+0xb0; //是第二行則命令代碼高4位為0xc
            else
            p=pos+0x80; //是第二行則命令代碼高4位為0x8
            WriteCommand (p);//write command
            WriteData (c); //write data
            }
            /*************************************************************************/
            void ShowString (unsigned char line,char *ptr)
            {
            unsigned char l,i;
            l=line<<4;
            for (i=0;i<16;i++)
            ShowChar (l++,*(ptr+i));//循環(huán)顯示16個(gè)字符
            }
            /*********************************************************************/
            void InitLcd()
            {
            DelayMs(15);
            WriteCommand(0x38); //display mode
            WriteCommand(0x38); //display mode
            WriteCommand(0x38); //display mode
            WriteCommand(0x06); //顯示光標(biāo)移動(dòng)位置
            WriteCommand(0x0c); //顯示開(kāi)及光標(biāo)設(shè)置
            WriteCommand(0x01); //顯示清屏

            }


            //////////////////////////////////////////////////////////////////////
            //ADC轉(zhuǎn)換函數(shù)========================================================
            void ADconv()
            {
            unsigned char i;


            //時(shí)能前初始化====================================================
            Di=1;
            Di2=1;
            Di3=1;
            Di4=1;
            Di5=1;


            CS=1;
            _nop_();
            CS=0;
            Di=1;
            Di2=1;
            Di3=1;
            Di4=1;
            Di5=1;
            //=================================================================

            //第一個(gè)下降沿===================================================
            CLK=1;
            _nop_();
            _nop_();
            CLK=0;
            //=================================================================

            //確定通道方式,第二個(gè)下降沿===================================
            _nop_();
            _nop_();
            CLK=1;
            Di=1;
            Di2=1;
            Di3=1;
            Di4=1;
            Di5=1;
            _nop_();
            _nop_();
            CLK=0;
            //=================================================================

            //第三個(gè)下降沿===================================================
            _nop_();
            _nop_();
            CLK=1;
            Di=0;
            Di2=1;
            Di3=1;
            Di4=1;
            Di5=1;
            _nop_();
            _nop_();
            CLK=0; //AD初始化完成
            //=================================================================

            //讀取數(shù)據(jù)========================================================
            Di=1; //IO變?yōu)檩斎?br /> Di2=1;
            Di3=1;
            Di4=1;
            Di5=1;
            CLK=1;
            _nop_();
            _nop_();
            CLK=0;

            CLK=1;
            CLK=1;
            _nop_();
            _nop_();
            CLK=0;

            CLK=1;
            //得到一個(gè)正常排序的8位數(shù)據(jù)
            for(i=8;i>0;i--)
            {
            data_f<<=1;
            data_f2<<=1;
            data_f3<<=1;
            data_f4<<=1;
            data_f5<<=1;

            data_f|=Do;
            data_f2|=Do2;
            data_f3|=Do3;
            data_f4|=Do4;
            data_f5|=Do5;

            CLK=1;
            _nop_();
            _nop_();
            CLK=0;
            _nop_();
            }
            //==============================
            //得到一個(gè)反序排列的8位數(shù)據(jù)
            for(i=8;i>0;i--)
            {
            data_c<<=1;
            data_c2<<=1;
            data_c3<<=1;
            data_c4<<=1;
            data_c5<<=1;

            data_c|=Do;
            data_c2|=Do2;
            data_c3|=Do3;
            data_c4|=Do4;
            data_c5|=Do5;

            _nop_();
            CLK=1;
            _nop_();
            _nop_();
            CLK=0;
            _nop_();
            }
            //==============================
            CLK=0;
            _nop_();
            _nop_();
            CLK=1;
            _nop_();
            _nop_();
            CLK=0;
            _nop_();
            _nop_();
            CLK=1;
            _nop_();
            CS=1;
            _nop_();
            _nop_();


            }
            //===================================================================

            //顯示轉(zhuǎn)換===========================================================
            char huanhuan(unsigned char benben)
            {
            switch(benben)
            {
            case 0:
            return 0;
            break;

            case 1:
            return 1;
            break;

            case 2:
            return 2;
            break;

            case 3:
            return 3;
            break;

            case 4:
            return 4;
            break;

            case 5:
            return 5;
            break;

            case 6:
            return 6;
            break;

            case 7:
            return 7;
            break;

            case 8:
            return 8;
            break;

            case 9:
            return 9;
            break;

            default:
            break;
            }
            }
            //===================================================================

            void main()
            {
            unsigned xianshi=0;
            InitLcd();
            DelayMs(15);
            sprintf(Test1," wo shi tiancai ");//the first line
            ShowString(0,Test1);
            sprintf(TimeNum,"AD value is ");//the first line
            ShowString(1,TimeNum);
            while(1)
            {
            DelayMs(800);
            xianshi=data_f;
            ADconv();
            TimeNum[12]=huanhuan(xianshi/100);
            TimeNum[13]=huanhuan(xianshi/10%10);
            TimeNum[14]=huanhuan(xianshi%10);
            ShowString(1,TimeNum);
            }
            }



            關(guān)鍵詞: 0832ADC51測(cè)試程

            評(píng)論


            技術(shù)專(zhuān)區(qū)

            關(guān)閉