View Single Post
Old 26-08-2009, 09:03 AM   #3
enti
Đệ tử 2 túi
 
Tham gia ngày: Nov 2006
Bài gửi: 26
:
Trích:
Nguyên văn bởi bebungbu View Post
EEPROM này của Microchip phải không bồ
Mình tìm được đoạn code này bồ thử xem sao nhe.
Code:
unsigned char read_ext_eeprom(unsigned long address)
{
    unsigned char command;
    unsigned char data;

    IdleI2C1();

    if (address > 65535)
        command = 0xa8;
    else
        command = 0xa0;

    StartI2C1();
    status = MasterWriteI2C1(command);
    while(I2C1STATbits.TBF); //Wait till address is transmitted
    AckI2C1();
    IdleI2C1();

    MasterWriteI2C1(address >> 8);
    while(I2C1STATbits.TBF); //Wait till address is transmitted
    AckI2C1();
    IdleI2C1();

    MasterWriteI2C1(address);
    while(I2C1STATbits.TBF); //Wait till address is transmitted
    AckI2C1();
    IdleI2C1();

    StartI2C1();
    MasterWriteI2C1(command | 0x01);
    while(I2C1STATbits.TBF); //Wait till address is transmitted
    AckI2C1();

    IdleI2C1();

    data = MasterReadI2C1();
    NotAckI2C1();

    StopI2C1();

    return data;
}
Cám ơn bạn bebungbu nhưng mình chỉ đọc ra được giá trị 0x00.
Có bạn nào đã làm rồi có thể giúp mình giải quyết nó không?
enti vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn