www.pudn.com > uCOSV262.rar > AT24C256.c
#include "IIC.h"
#include "at24c256.h"
unsigned char AT24C256_ReadBlock(unsigned int blockAddress,unsigned char *recBuf);
unsigned char AT24C256_WriteBlock(unsigned int blockAddress,unsigned char *SendBuf);
unsigned char AT24C256_ReadMultiBlock(unsigned int blockAddress,unsigned int blockNum,unsigned char *recBuf);
unsigned char AT24C256_WriteMultiBlock(unsigned int blockAddress,unsigned int blockNum,unsigned char *sendBuf);
unsigned char AT24C256_ReadBlock(unsigned int blockAddress,unsigned char *recBuf)
{
unsigned char slaveAddress;
unsigned int tmp;
unsigned char subAddress[2];
if(blockAddress>=(AT24C256_BLOCK_SIZE*4))
return 0;
if(blockAddress>8);
subAddress[1] = (unsigned char) (tmp);
}
if((blockAddress>=AT24C256_BLOCK_SIZE)&&(blockAddress<(AT24C256_BLOCK_SIZE*2)))
{
slaveAddress = AT24C256_ADDRESS +0x01;
tmp = (blockAddress-AT24C256_BLOCK_SIZE);
tmp *= (AT24C256_BYTE_SIZE);
subAddress[0] = (unsigned char) (tmp>>8);
subAddress[1] = (unsigned char) tmp;
}
if(blockAddress>=AT24C256_BLOCK_SIZE*2&blockAddress>8);
subAddress[1] = (unsigned char) (tmp);
}
if(blockAddress>=AT24C256_BLOCK_SIZE*3&blockAddress>8);
subAddress[1] = (unsigned char) (tmp);
}
return SmbRec(slaveAddress,subAddress,TWO_BYTE_SUBA,AT24C256_BYTE_SIZE,recBuf);
}
unsigned char AT24C256_WriteBlock(unsigned int blockAddress,unsigned char *SendBuf)
{
unsigned char slaveAddress;
unsigned int tmp;
unsigned char subAddress[2];
if(blockAddress>=AT24C256_BLOCK_SIZE*4)
return 0;
if(blockAddress>8);
subAddress[1] = (unsigned char) (tmp);
}
if(blockAddress>=AT24C256_BLOCK_SIZE&blockAddress>8);
subAddress[1] = (unsigned char) (tmp);
}
if(blockAddress>=AT24C256_BLOCK_SIZE*2&blockAddress>8);
subAddress[1] = (unsigned char) (tmp);
}
if(blockAddress>=AT24C256_BLOCK_SIZE*3&blockAddress>8);
subAddress[1] = (unsigned char) (tmp);
}
return SmbSend(slaveAddress,subAddress,TWO_BYTE_SUBA,AT24C256_BYTE_SIZE,SendBuf);
}
unsigned char AT24C256_ReadMultiBlock(unsigned int blockAddress,unsigned int blockNum,unsigned char *recBuf)
{
unsigned char tmp;
unsigned char tmp1;
for(tmp=0;tmp