新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > PIC單片機之I2C(從模式)

PIC單片機之I2C(從模式)

作者: 時間:2013-05-30 來源:網(wǎng)絡(luò) 收藏

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;

}

}

}

單片機相關(guān)文章:單片機教程


單片機相關(guān)文章:單片機視頻教程


單片機相關(guān)文章:單片機工作原理



上一頁 1 2 3 下一頁

關(guān)鍵詞: PIC單片機 I2C 從模式

評論


相關(guān)推薦

技術(shù)專區(qū)

關(guān)閉