| 由于程序比较大,我简单的介绍一下两个的区别(主要是红色部分的区别): 1.小容量发送存储地址的示例程序:
 
 Bool i2c_MasterStart( I2C_Direction direct, BYTE addr )
 {
 BYTE retry = 3;
 
 if( direct == I2C_READ ) // Set I2C direction bit.
 addr |= BIT0;
 else
 addr &= ~BIT0;
 
 while( retry-- )
 {
 if( i2c_Start() == FALSE )
 {
 i2c_Stop();
 continue;
 }
 
 if( i2c_SendByte( addr ) == TRUE ) // send address success
 return TRUE;
 i2c_Stop();
 ForceDelay1ms( 2 );
 }
 return FALSE;
 }
 
 
 2.大容量发送存储的示例程序:
 
 Bool i2c_MasterStart( I2C_Direction direct, BYTE addr )
 {
 #define NVRAM_DEVICE    0xA0
 
 BYTE u8Retry=5;
 BYTE addr1 = addr;
 //BYTE u8NvRamID=NVRAM_DEVICE;
 if (direct==I2C_READ) // Set I2C direction bit.
 {
 addr1=NVRAM_DEVICE;// get 0xA0
 addr1|=BIT0;
 }
 else
 addr1&=~BIT0;
 
 while (u8Retry--)
 {
 if (i2c_Start()==FALSE)
 {
 ForceDelay1ms(1);
 continue;
 }
 if(direct==I2C_READ)
 {
 if (i2c_SendByte(addr1)==TRUE) // send address success
 return TRUE;
 }
 else
 {
 if (i2c_SendByte(NVRAM_DEVICE)==TRUE) // send address success
 {
 
 if (i2c_SendByte(ucADDR_HI_BYTE)==TRUE) // send address success
 return TRUE;
 }
 }
 i2c_Stop();
 ForceDelay1ms(2);
 }
 return FALSE;
 }
 
 |