?? at24cxx.c
字號:
/*******************************************************************************
AT24512 Introduction:
65536bytes *8Bit=512 pages *128bytes/page
word address=16bit
*******************************************************************************/
#include "App\Global.h"
#include "I2C.h"
#include "AT24CXX.h"
#include "App\time.h"
BOOLEAN AT24CXXReadByte(INT16U WordAdd,INT8U *pReadData)
{
if(I2C_ReadBlock(AT24CXX_I2CSlaveWriteAddress,AT24CXX_I2CSlaveReadAddress,pReadData,WordAdd,1)==NG)
return NG;
return OK;
}
BOOLEAN AT24CXXWriteByte(INT16U WordAddr,INT8U value)
{
if(I2C_WriteBlock(AT24CXX_I2CSlaveWriteAddress,&value,WordAddr,1)==NG)
return NG;
return OK;
}
BOOLEAN AT24CXXWriteBlock(INT8U *pWriteData,INT16U StartWordAdd,INT16U size)
{
INT8U FirstPageNo,IntPageNos,LastPageNo;
INT8U FirstPageBytes,LastPageBytes;
INT8U i;
FirstPageNo=StartWordAdd/PageBytes;
FirstPageBytes=PageBytes-StartWordAdd%PageBytes;
IntPageNos=(size-FirstPageBytes)/PageBytes;
LastPageNo=FirstPageNo+IntPageNos+1;
LastPageBytes=size-FirstPageBytes-IntPageNos*PageBytes;
//首頁零散字節
if(I2C_WriteBlock(AT24CXX_I2CSlaveWriteAddress,pWriteData,StartWordAdd,FirstPageBytes)==NG)
return NG;
DelayNms(10);//臨時增加延時
//中間整數字節
if(IntPageNos!=0)
{
for(i=0;i<IntPageNos;i++)
{
if(I2C_WriteBlock(AT24CXX_I2CSlaveWriteAddress,pWriteData+FirstPageBytes+i*PageBytes,(FirstPageNo+i+1)*PageBytes,PageBytes)==NG)
break;
DelayNms(10);
}
}
DelayNms(10);//臨時增加延時
//尾頁零散字節
if(LastPageBytes!=0)
{
if(I2C_WriteBlock(AT24CXX_I2CSlaveWriteAddress,pWriteData+FirstPageBytes+IntPageNos*PageBytes,LastPageNo*PageBytes,LastPageBytes)==NG)
return NG;
}
DelayNms(10);//臨時增加延時
}
BOOLEAN AT24CXXReadBlock(INT8U *pReadData,INT16U StartWordAdd,INT16U size)
{
INT8U FirstPageNo,IntPageNos,LastPageNo;
INT8U FirstPageBytes,LastPageBytes;
INT8U i;
FirstPageNo=StartWordAdd/PageBytes;
FirstPageBytes=PageBytes-StartWordAdd%PageBytes;
IntPageNos=(size-FirstPageBytes)/PageBytes;
LastPageNo=FirstPageNo+IntPageNos+1;
LastPageBytes=size-FirstPageBytes-IntPageNos*PageBytes;
//首頁零散字節
if(I2C_ReadBlock(AT24CXX_I2CSlaveWriteAddress,AT24CXX_I2CSlaveReadAddress,pReadData,StartWordAdd,FirstPageBytes)==NG)
return NG;
DelayNms(10);//臨時增加延時
//中間整數字節
if(IntPageNos!=0)
{
for(i=0;i<IntPageNos;i++)
{
if(I2C_ReadBlock(AT24CXX_I2CSlaveWriteAddress,AT24CXX_I2CSlaveReadAddress,pReadData+FirstPageBytes+i*PageBytes,(FirstPageNo+i+1)*PageBytes,PageBytes)==NG)
break;
DelayNms(10);
}
}
DelayNms(10);//臨時增加延時
//尾頁零散字節
if(LastPageBytes!=0)
{
if(I2C_ReadBlock(AT24CXX_I2CSlaveWriteAddress,AT24CXX_I2CSlaveReadAddress,pReadData+FirstPageBytes+IntPageNos*PageBytes,LastPageNo*PageBytes,LastPageBytes)==NG)
return NG;
}
DelayNms(10);//臨時增加延時
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -