在线看毛片网站电影-亚洲国产欧美日韩精品一区二区三区,国产欧美乱夫不卡无乱码,国产精品欧美久久久天天影视,精品一区二区三区视频在线观看,亚洲国产精品人成乱码天天看,日韩久久久一区,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首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 單片機(jī)模擬I2C讀寫(xiě)E2PROM

            單片機(jī)模擬I2C讀寫(xiě)E2PROM

            作者: 時(shí)間:2016-11-22 來(lái)源:網(wǎng)絡(luò) 收藏
            單片機(jī)模擬I2C讀寫(xiě)E2PROM

            //Name: I2C standard program

            //Author: Ares
            //Date:2005.11.4

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

            #i nclude
            #i nclude

            sbit SDA=P2^5;
            sbit SCL=P1^0;

            #define uchar unsigned char
            #define uint unsigned int
            #define byte unsigned char

            void delay()
            {
            _nop_();
            _nop_();
            _nop_();
            _nop_();
            _nop_();
            }


            void delayms (uint x)
            {
            byte j;
            while(x--){
            for(j=0;j<125;j++){;}
            }
            }

            void I2C_Start()//I2C START
            {
            SDA=1;
            _nop_();
            SCL=1;
            delay();
            SDA=0;
            delay();
            SCL=0;
            _nop_();
            }

            void I2C_Stop()//I2C STOP
            {
            SDA=0;
            _nop_();
            SCL=1;
            delay();
            SDA=1;
            delay();
            }

            bit I2C_ReceiveAck()
            {
            bit ck;
            SDA=1;//THE HOST RELEASE THE BUS
            _nop_();
            _nop_();
            SCL=1;
            _nop_();
            _nop_();
            ck=SDA;
            _nop_();
            _nop_();
            SCL=0;
            _nop_();
            return(ck);
            }


            void I2C_SendAck()

            {
            SDA=0;
            _nop_();
            _nop_();
            SCL=1;
            delay();//remain
            SCL=0;
            _nop_();
            _nop_();
            }

            void I2C_SendNoAck()

            {
            SDA=1;
            _nop_();
            _nop_();
            SCL=1;
            delay();//remain
            SCL=0;
            _nop_();
            _nop_();
            }

            void I2C_SendByte(byte SData)
            {uchar i;
            for(i=0;i<8;i++)
            { SDA=(bit)(SData&0x80);
            SData=SData<<1;
            SCL=1;
            delay();
            SCL=0;
            }
            }

            byte I2C_ReceiveByte()
            {uchar i;
            byte RData;
            RData=0;

            for(i=0;i<8;i++)
            { SDA=1;
            _nop_();
            SCL=1;
            _nop_();
            _nop_();
            RData=RData<<1;
            RData=RData|SDA;
            _nop_();
            _nop_();
            SCL=0;
            }
            return(RData);
            }

            void I2C_SendToSubAddress(byte SlaveAddress,byte SubAddress,byte *pSData,uchar N)
            {uchar i;
            I2C_Start();
            I2C_SendByte(SlaveAddress);//send slave address(write device)
            I2C_ReceiveAck();
            I2C_SendByte(SubAddress);//send sub address
            I2C_ReceiveAck();

            for(i=0;i{
            I2C_SendByte(pSData[i]);
            I2C_ReceiveAck();
            }
            I2C_Stop();
            }

            void I2C_ReceiveFromSubAddress(byte SlaveAddress,byte SubAddress,byte *pRData,uchar N)
            {uchar i;
            I2C_Start();
            I2C_SendByte(SlaveAddress);//send slave address(write device)
            I2C_ReceiveAck();
            I2C_SendByte(SubAddress);//send sub address
            I2C_ReceiveAck();
            I2C_Start();//I2C Start Again!
            I2C_SendByte(SlaveAddress+1);//send slave address(read device)
            I2C_ReceiveAck();
            for(i=0;i{
            pRData[i]=I2C_ReceiveByte();
            I2C_SendAck();
            }
            pRData[i]=I2C_ReceiveByte();
            I2C_SendNoAck();
            I2C_Stop();
            }

            main()
            {byte *pData;
            byte a[16]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
            pData=a;
            I2C_ReceiveFromSubAddress(0xA0,0x20,pData,16);
            I2C_SendToSubAddress(0xA0,0,pData,16);
            }



            評(píng)論


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

            關(guān)閉