在线看毛片网站电影-亚洲国产欧美日韩精品一区二区三区,国产欧美乱夫不卡无乱码,国产精品欧美久久久天天影视,精品一区二区三区视频在线观看,亚洲国产精品人成乱码天天看,日韩久久久一区,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>

            新聞中心

            EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > PCF8563驅動(C語言版)

            PCF8563驅動(C語言版)

            作者: 時間:2016-11-21 來源:網絡 收藏
            //CPU:STC89C52RC 晶震:11.0592M

            #include 〈reg52.h>

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

            #include

            #include

            #define uchar unsigned char

            #define uint unsigned int

            uchar TAB_T[]={ 0x31,0x06,0x10,//秒,分,時

            0x13,0x01,0x07,0x08};//日,星期,月,年.

            sbit SDA=P2^6; //數(shù)據(jù)

            sbit SCL=P2^7; //時鐘

            void Delay5us(void)

            {

            _nop_();

            _nop_();

            _nop_();

            _nop_();

            _nop_();

            }

            void Start(void)

            {

            SDA=1;

            SCL=1;

            Delay5us();

            SDA=0;

            Delay5us();

            }

            void Stop(void)

            {

            SDA=0;

            SCL=1;

            Delay5us();

            SDA=1;

            Delay5us();

            }

            void Reack(void)

            {

            uchar i=0;

            SCL=1; //準備檢測SDA Delay5us();

            while((SDA==1)&&(i<100))i++;//SDA=0為應該信號,SDA=1為非應答

            SCL=0; //準備下一變化數(shù)據(jù)

            }

            void WriteByte(uchar ucByte)

            {

            uchar i;

            SCL=0;

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

            {

            SDA=(bit)(ucByte&0x80);//先寫入高位

            SCL=1;

            Delay5us();

            SCL=0;

            ucByte<<=1;

            }

            SDA=1; //釋放數(shù)據(jù)線

            }

            uchar ReadByte(void)

            {

            uchar i,ucByte;

            SCL=0;

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

            {

            ucByte<<=1;

            if(SDA)

            ucByte++;

            SCL=1;

            Delay5us();

            SCL=0;

            }

            return ucByte;

            }

            void Write8563(uchar ucAddr,uchar ucData)

            {

            Start();

            WriteByte(0xa2);

            Reack();

            WriteByte(ucAddr);

            Reack();

            WriteByte(ucData);

            Reack();

            Stop();

            }

            uchar Read8563(uchar ucAddr)

            {

            uchar ucData;

            Start();

            WriteByte(0xa2); //寫器件地址

            Reack();

            WriteByte(ucAddr); //寫字節(jié)地址

            Reack();

            Start();

            WriteByte(0xa3); //寫器件地址,最低為1表示讀

            Reack();

            ucData=ReadByte(); //寫字節(jié)地址

            Stop();

            return ucData; //讀數(shù)據(jù)

            }

            void Init8563(void)

            {

            uchar i,ucAddr=0x02;

            Write8563(0x00,0x00);

            Write8563(0x01,0x11);

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

            {

            Write8563(ucAddr,TAB_T[i]);

            ucAddr++;

            }

            }

            void GetTime(void)

            {

            uchar i,ucData1,ucData2,ucAddr=0x02;

            uchar *pTime=TAB_T;

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

            {

            pTime[i]=Read8563(ucAddr);

            ucAddr++;

            }

            pTime[0]&=0x7f; //屏蔽無效位

            pTime[1]&=0x7f;

            pTime[2]&=0x3f;

            pTime[3]&=0x3f;

            pTime[4]&=0x07;

            pTime[5]&=0x1f;

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

            {

            ucData1=pTime[i]/16; //BCD碼轉十六進制

            ucData2=pTime[i]%16;

            pTime[i]=ucData1*10+ucData2;

            }

            }



            關鍵詞: PCF8563驅動C語言

            評論


            技術專區(qū)

            關閉