PIC单片机之I2C(从模式)

时间:2013-05-30来源:网络

while(PIR1bits.SSP1IF == 0)

{

timercounter--;

if(timercounter==0)

{

return;

}

}//waiting for ~ACK

SSP1IF = 0;

if(SSP1CON2bits.ACKSTAT == 1)

{

return ; //NOACK

}

else

{

i2c_counter++;//ACK

}

}

SSP1IF = 0;

}

}

void i2c_salve_interrupt_rx()//master writer

{

unsigned char rx_status;

unsigned char Temp;

unsigned int timercounter;

rx_status=false;

Temp=SSP1STAT;

Temp = 0x2D;

if(Temp==0x09)//Write operation,last byte was an address,buffer is full

{

SSP1IF = 0;

i2c_address = SSP1BUF;

timercounter=while_delay;

while(PIR1bits.SSP1IF == 0)

{

timercounter--;

if(timercounter==0)

{

return ;

}

}//waiting for send ~ACK

SSP1IF = 0;

word_address = SSP1BUF;

return ;

}

if(Temp==0x29)//Write operation,last byte was data,buffer is full

{

SSP1IF=0;

Register[word_address]=SSP1BUF;

word_address++;

if(word_address>=RX_BUF_LEN)

{

word_address=0;

}

}

}

1 2 3

关键词: PIC单片机 I2C 从模式

加入微信
获取电子行业最新资讯
搜索微信公众号:EEPW

或用微信扫描左侧二维码

相关文章

查看电脑版