u8 eeprom_read_byte(u8 addr)
{
u8 temp=0;
while(i2c_flag_get(I2C0,I2C_FLAG_I2CBSY));
i2c_start_on_bus(I2C0);
while(!i2c_flag_get(I2C0,I2C_FLAG_SBSEND));
i2c_master_addressing(I2C0,0xa0,I2C_TRANSMITTER);
while(!i2c_flag_get(I2C0,I2C_FLAG_ADDSEND));
i2c_flag_clear(I2C0,I2C_FLAG_ADDSEND);
while(!i2c_flag_get(I2C0,I2C_FLAG_TBE));
i2c_data_transmit(I2C0,addr);
while(!i2c_flag_get(I2C0,I2C_FLAG_BTC));
i2c_start_on_bus(I2C0);
while(!i2c_flag_get(I2C0,I2C_FLAG_SBSEND));
i2c_master_addressing(I2C0,0xa0,I2C_RECEIVER);
i2c_ack_config(I2C0,I2C_ACK_DISABLE);
while(!i2c_flag_get(I2C0,I2C_FLAG_ADDSEND));
i2c_flag_clear(I2C0,I2C_FLAG_ADDSEND);
i2c_data_receive(I2C0);
i2c_stop_on_bus(I2C0);
while(I2C_CTL0(I2C0)&0x0200);
i2c_ack_config(I2C0,I2C_ACK_ENABLE);
temp=i2c_data_receive(I2C0);
return temp;
}
|