找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1834|回复: 0
收起左侧

IIC协议发送多字节的数字,NFC M24R64

[复制链接]
ID:94642 发表于 2020-10-13 17:17 | 显示全部楼层 |阅读模式
/*******************************************************************************
* 函数名         : void At24c02Write(unsigned char addr,unsigned char dat)
* 函数功能                   : 往24c02的一个地址写入一个数据
* 输入           : 无
* 输出                  : 无
*******************************************************************************/

void At24c02Write(unsigned int addr, unsigned char dat)
{
        I2cStart();
        I2cSendByte(0xa6);//发送写器件地址
        I2cSendByte(addr>>8);//发送要写入内存地址
        I2cSendByte(addr&0xff);//发送要写入内存地址
//        I2cSendByte(dat<<8);        //发送数据
        //I2cSendByte(addL);//发送要写入内存地址
        I2cSendByte(dat);        //发送数据
        I2cStop();
}

/*******************************************************************************
* 函数名         : unsigned char At24c02Read(unsigned char addr)
* 函数功能                   : 读取24c02的一个地址的一个数据
* 输入           : 无
* 输出                  : 无
*******************************************************************************/

unsigned char At24c02Read(unsigned int addr)
{
        unsigned char num;
        I2cStart();
        I2cSendByte(0xa6); //发送写器件地址
        I2cSendByte(addr>>8); //发送要读取的高八位地址
        I2cSendByte(addr&0xff); //发送要读取低八位的地址
//        I2cSendByte(addL); //发送要读取的地址
        I2cStart();
        I2cSendByte(0xa7); //发送读器件地址
        num=I2cReadByte(); //读取数据
//        num=num<<8|I2cReadByte(); //读取数据
        I2cStop();
        return num;       
}



void write_m_data_24c64(u16 addr,u8 *m_data_24c64,u8 n) //从某地址开始连续多字节写入
{
    u8 i;
                I2cStart();
                I2cSendByte(0xa6);//发送写器件地址
                I2cSendByte(addr>>8);//发送要写入内存地址
                I2cSendByte(addr&0xff);//发送要写入内存地址

    for(i=0; i<n; i++)
    {
        I2cSendByte(*(m_data_24c64++));//写储存数据
        Delay10us();
    }
   I2cStop();
}


void read_m_data_24c64(u16 addr,u8 n)//从某地址开始连续读取n个数据
        {
                u8 i;
                for(i=0;i<n;i++)
                {
                        I2cStart();
                        I2cSendByte(0xa6); //发送写器件地址
                        I2cSendByte(addr>>8); //发送要读取的高八位地址
                        I2cSendByte(addr&0xff); //发送要读取低八位的地址
                        addr++;
                        I2cStart();
                        I2cSendByte(0xa7); //发送读器件地址
                        receive[i]= I2cReadByte();
                        Delay10us();
                        I2cStop();
                }
        }

对于单字节相当于页写,普通的是8位数据,这个传递是32位的数据


程序.zip

71.89 KB, 下载次数: 4, 下载积分: 黑币 -5

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表