void I2C_Start(void)
{
SDA_H;
SCL_H;
I2C_delay();
SDA_L;
I2C_delay();
SCL_L;
}
bool I2C_WaitAck(void) //返回为:=1有ACK,=0无ACK
{
SCL_L;
I2C_delay();
SDA_H;
I2C_delay();
SCL_H;
I2C_delay();
if(SDA_read)
{
SCL_L;
I2C_delay();
return FALSE;
}
SCL_L;
I2C_delay();
return TRUE;
}
void I2C_Stop(void)
{
SDA_L;
SCL_H;
I2C_delay();
SDA_H;
I2C_delay();
}
void I2C_SendByte(u8 SendByte) //数据从高位到低位//
{
u8 i=8;
while(i--)
{
SCL_L;
I2C_delay();
if(SendByte&0x80)
SDA_H;
else
SDA_L;
SendByte<<=1;
I2C_delay();
SCL_H;
I2C_delay();
}
SCL_L;
}
uint8_t AT24C256_ReadOneByte(uint16_t ReadAddr) //在特定地址读出一个字节的值
{
uint8_t DataToRead=0;
I2C_Start();
I2C_SendByte(0xA0); //0xA0表示写
I2C_WaitAck();
I2C_SendByte(ReadAddr>>8)
I2C_WaitAck();
I2C_SendByte(ReadAddr%256);
I2C_WaitAck();
I2C_Start();
I2C_SendByte(0xA1);
I2C_WaitAck();
DataToRead=I2C_RadeByte();
I2C_Stop();
return DataToRead;
}
p=AT24C256_ReadOneByte(32767);
代码如上面所示,读不出P的值,想请大家帮看看 |