|
Tài trợ cho PIC Vietnam |
Giao tiếp USB, CAN, I2C, SPI, USART... Những giao tiếp được tích hợp trên PIC |
|
Ðiều Chỉnh | Xếp Bài |
25-08-2009, 04:35 PM | #2 |
Đệ tử 1 túi
Tham gia ngày: Jun 2009
Bài gửi: 25
: |
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; } |
|
|