PIC单片机用IIC总线读写片外EEPROM????
[复制链接]
单片机用的PIC18F65J10,片外EEPROM是24LC16B,用IIC总线读写
代码是这样的:
void Iic_EepromRd(BYTE chip,BYTE address,BYTE *p,BYTE num) { while (num>EEPROM_PAGE_LENGTH) { StartI2C(); while ( SSPCON2bits.SEN ); WriteI2C(chip &= 0xFE); WriteI2C(address); RestartI2C(); while ( SSP1CON2bits.RSEN ); WriteI2C(chip|=0x01); getsI2C(p,EEPROM_PAGE_LENGTH); NotAckI2C(); while ( SSP1CON2bits.ACKEN ); StopI2C(); while ( SSP1CON2bits.PEN ); address += EEPROM_PAGE_LENGTH; num -= EEPROM_PAGE_LENGTH; } StartI2C(); while ( SSP1CON2bits.SEN ); WriteI2C(chip &= 0xFE); WriteI2C(address); RestartI2C(); while ( SSP1CON2bits.RSEN ); WriteI2C(chip|=0x01); getsI2C(p,num); NotAckI2C(); while ( SSP1CON2bits.ACKEN ); StopI2C(); while ( SSP1CON2bits.PEN ); }
现在就卡在getsI2C(p,num);这里过不去了,一直死循环。求高手指点下!!!!!
|