设断点发现,程序会一直循环,这是为何?按理说发送完成SSP1IF会置1
void I2C_Start() //开启I2C
{
SSP1CON2bits.SEN = 1; //开启指令
while (SSP1CON2bits.SEN == 1);
}
void I2C_Stop() //停止I2C
{
SSP1CON2bits.PEN = 1;
while (SSP1CON2bits.PEN);
}
void write_eeprom(unsigned char address)
{
unsigned char m;
I2C_Start(); //开启
PIR1bits.SSP1IF = 0;
SSP1BUF = 0xA0 ; //E2PROM地址
while (!PIR1bits.SSP1IF);
PIR1bits.SSP1IF = 0;
SSP1BUF = address; //写地址
while(!PIR1bits.SSP1IF);
PIR1bits.SSP1IF = 0;
for (m= 0;m < 6; m++)
{
SSP1BUF = EE_Data[m]; //数值
while(!PIR1bits.SSP1IF);
PIR1bits.SSP1IF == 0;
}
I2C_Stop();
PIR1bits.SSP1IF = 0;
} |