找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

搜索
查看: 2127|回復(fù): 0
收起左側(cè)

IIC協(xié)議發(fā)送多字節(jié)的數(shù)字,NFC M24R64

[復(fù)制鏈接]
ID:94642 發(fā)表于 2020-10-13 17:17 | 顯示全部樓層 |閱讀模式
/*******************************************************************************
* 函數(shù)名         : void At24c02Write(unsigned char addr,unsigned char dat)
* 函數(shù)功能                   : 往24c02的一個(gè)地址寫(xiě)入一個(gè)數(shù)據(jù)
* 輸入           : 無(wú)
* 輸出                  : 無(wú)
*******************************************************************************/

void At24c02Write(unsigned int addr, unsigned char dat)
{
        I2cStart();
        I2cSendByte(0xa6);//發(fā)送寫(xiě)器件地址
        I2cSendByte(addr>>8);//發(fā)送要寫(xiě)入內(nèi)存地址
        I2cSendByte(addr&0xff);//發(fā)送要寫(xiě)入內(nèi)存地址
//        I2cSendByte(dat<<8);        //發(fā)送數(shù)據(jù)
        //I2cSendByte(addL);//發(fā)送要寫(xiě)入內(nèi)存地址
        I2cSendByte(dat);        //發(fā)送數(shù)據(jù)
        I2cStop();
}

/*******************************************************************************
* 函數(shù)名         : unsigned char At24c02Read(unsigned char addr)
* 函數(shù)功能                   : 讀取24c02的一個(gè)地址的一個(gè)數(shù)據(jù)
* 輸入           : 無(wú)
* 輸出                  : 無(wú)
*******************************************************************************/

unsigned char At24c02Read(unsigned int addr)
{
        unsigned char num;
        I2cStart();
        I2cSendByte(0xa6); //發(fā)送寫(xiě)器件地址
        I2cSendByte(addr>>8); //發(fā)送要讀取的高八位地址
        I2cSendByte(addr&0xff); //發(fā)送要讀取低八位的地址
//        I2cSendByte(addL); //發(fā)送要讀取的地址
        I2cStart();
        I2cSendByte(0xa7); //發(fā)送讀器件地址
        num=I2cReadByte(); //讀取數(shù)據(jù)
//        num=num<<8|I2cReadByte(); //讀取數(shù)據(jù)
        I2cStop();
        return num;       
}



void write_m_data_24c64(u16 addr,u8 *m_data_24c64,u8 n) //從某地址開(kāi)始連續(xù)多字節(jié)寫(xiě)入
{
    u8 i;
                I2cStart();
                I2cSendByte(0xa6);//發(fā)送寫(xiě)器件地址
                I2cSendByte(addr>>8);//發(fā)送要寫(xiě)入內(nèi)存地址
                I2cSendByte(addr&0xff);//發(fā)送要寫(xiě)入內(nèi)存地址

    for(i=0; i<n; i++)
    {
        I2cSendByte(*(m_data_24c64++));//寫(xiě)儲(chǔ)存數(shù)據(jù)
        Delay10us();
    }
   I2cStop();
}


void read_m_data_24c64(u16 addr,u8 n)//從某地址開(kāi)始連續(xù)讀取n個(gè)數(shù)據(jù)
        {
                u8 i;
                for(i=0;i<n;i++)
                {
                        I2cStart();
                        I2cSendByte(0xa6); //發(fā)送寫(xiě)器件地址
                        I2cSendByte(addr>>8); //發(fā)送要讀取的高八位地址
                        I2cSendByte(addr&0xff); //發(fā)送要讀取低八位的地址
                        addr++;
                        I2cStart();
                        I2cSendByte(0xa7); //發(fā)送讀器件地址
                        receive[i]= I2cReadByte();
                        Delay10us();
                        I2cStop();
                }
        }

對(duì)于單字節(jié)相當(dāng)于頁(yè)寫(xiě),普通的是8位數(shù)據(jù),這個(gè)傳遞是32位的數(shù)據(jù)


程序.zip

71.89 KB, 下載次數(shù): 4, 下載積分: 黑幣 -5

回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表