|
8位Byte的读方法可以参考以下代码:
- unsigned char I2C_Read_Byte(void)
- {
- int t,rxData;
- unsigned char receive;
- SDA_Input();
- for(t=0;t<8;t++)
- {
- SCL_Low(); // Clear the SCL
- Delay(I2CDelay);
- SCL_High(); // Set the SCL
- receive<<=1;
- rxData = SDA_Data_Register ;
- if(rxData)
- {
- receive++;
- }
- Delay(I2CDelay);
- }
- return receive;
- }
寄存器的读方法可以参考以下代码:
- unsigned char I2C_Read_Register(unsigned char Device_Write,unsigned char Device_Read, unsigned char Register)
- {
- unsigned char ReadData;
- I2C_Start();
- I2C_Send_Byte(Device_Write); //Send the device address
- I2C_Wait_Ack(); //Wait for the ack signal
- I2C_Send_Byte(Register); //Send the register address
- I2C_Wait_Ack(); //Wait for the ack signal
- I2C_Start();
- I2C_Send_Byte(Device_Read); //Send register value
- I2C_Wait_Ack();
- SDA_High(); // Set the SDA
- ReadData = I2C_Read_Byte();
- I2C_NAck();
- Delay(1);
- I2C_Finish();
- return ReadData;
- }
|
|