int SCCB_ReadByte_one(uint8 *pBuffer, uint16 length, uint8 ReadAddress) { if(!SCCB_Start()) { return 0; } SCCB_SendByte( DEV_ADR ); /* 器件地址 */ if( !SCCB_WaitAck() ) { SCCB_Stop(); return 0; } SCCB_SendByte( ReadAddress ); /* 设置低起始地址 */ SCCB_WaitAck(); SCCB_Stop(); if(!SCCB_Start()) { return 0; } SCCB_SendByte( DEV_ADR + 1 ); /* 器件地址 */ if(!SCCB_WaitAck()) { SCCB_Stop(); return 0; } while(length) { *pBuffer = SCCB_ReceiveByte(); if(length == 1) { SCCB_NoAck(); } else { SCCB_Ack(); } pBuffer++; length--; } SCCB_Stop(); return 1; }
int SCCB_WriteByte_one( uint16 WriteAddress , uint8 SendByte ) { if(!SCCB_Start()) { return 0; } SCCB_SendByte( DEV_ADR ); /* 器件地址 */ if( !SCCB_WaitAck() ) { SCCB_Stop(); return 0; } SCCB_SendByte((uint8)(WriteAddress & 0x00FF)); /* 设置低起始地址 */ SCCB_WaitAck(); SCCB_SendByte(SendByte); SCCB_WaitAck(); SCCB_Stop(); return 1; }
/* 函数名:SCCB_WriteByte * 描述 :写一字节数据 * 输入 :- WriteAddress: 待写入地址 - SendByte: 待写入数据 - DeviceAddress: 器件类型 * 输出 :返回为:=1成功写入,=0失败 * 注意 :无 */ int SCCB_WriteByte( uint16_t WriteAddress , uint8_t SendByte ) { if(!SCCB_Start()) { return DISABLE; } SCCB_SendByte( DEV_ADR ); /* 器件地址 */ if( !SCCB_WaitAck() ) { SCCB_Stop(); return DISABLE; } SCCB_SendByte((uint8_t)(WriteAddress & 0x00FF)); /* 设置低起始地址 */ SCCB_WaitAck(); SCCB_SendByte(SendByte); SCCB_WaitAck(); SCCB_Stop(); return ENABLE; }