Mình có viết 1 đoạn code giao tiếp với EEPROM 24C04 với 89S52 trong đó dùng hàm:
Trong chương trình chính mình sử dụng
Write_Page_To_24LC64_EEPROM(0x0050, MxArray, 8);
Write_Page_To_24LC64_EEPROM(0x00F0, TxArray, 4);
Read_Bytes_From_24LC64_EEPROM(0x0050, RxArray, 8);
khi mô phỏng bằng Protues thi ok nhưng khi mình dùng Kit Sp200s đọc giá trị ROM thì khác?
2 vòng màu đỏ mình đánh dấu
void Write_Page_To_24LC64_EEPROM(unsigned int Address,unsigned char* pData,unsigned char NoOfBytes)
{
unsigned int i;
I2C_Start(); // Start i2c communication
// Send i2c address of 24LC64 with write command
while(I2C_Write_Byte(Device_Address_24LC64_EEPROM + 0) == 1)// Wait until device is free
{ I2C_Start(); }
I2C_Write_Byte(Address>>8); // Write Address upper byte
I2C_Write_Byte((unsigned char)Address); // Write Address lower byte
for(i=0;i<NoOfBytes;i++) // Write NoOfBytes
I2C_Write_Byte(pData[i]); // Write data byte
I2C_Stop(); // Stop i2c communication
}
{
unsigned int i;
I2C_Start(); // Start i2c communication
// Send i2c address of 24LC64 with write command
while(I2C_Write_Byte(Device_Address_24LC64_EEPROM + 0) == 1)// Wait until device is free
{ I2C_Start(); }
I2C_Write_Byte(Address>>8); // Write Address upper byte
I2C_Write_Byte((unsigned char)Address); // Write Address lower byte
for(i=0;i<NoOfBytes;i++) // Write NoOfBytes
I2C_Write_Byte(pData[i]); // Write data byte
I2C_Stop(); // Stop i2c communication
}
Write_Page_To_24LC64_EEPROM(0x0050, MxArray, 8);
Write_Page_To_24LC64_EEPROM(0x00F0, TxArray, 4);
Read_Bytes_From_24LC64_EEPROM(0x0050, RxArray, 8);
khi mô phỏng bằng Protues thi ok nhưng khi mình dùng Kit Sp200s đọc giá trị ROM thì khác?
2 vòng màu đỏ mình đánh dấu
Comment