新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 24LCxx系列的讀寫EEPROM的例C語言源程序?qū)嵗?/p>

24LCxx系列的讀寫EEPROM的例C語言源程序?qū)嵗?/h1>
作者: 時間:2012-08-18 來源:網(wǎng)絡(luò) 收藏

//*
//***********************************************
void EE_SEQU_Read(unsigned char ctrl,unsigned char addr,unsigned char length,unsigned char *dptr)
{
IdleI2C(); // ensure module is idle
StartI2C(); // Start condition
I2C_Done(); // Wait Start condition completed

本文引用地址:http://butianyuan.cn/article/171029.htm

WriteI2C(ctrl); // Write Control to
while(SSPCON2bits.ACKSTAT); // test for ACK condition, if received
I2C_Done(); // Clear SSPIF flag

WriteI2C(addr); // Write Address to
while(SSPCON2bits.ACKSTAT); // test for ACK condition, if received
I2C_Done(); // Clear SSPIF flag

RestartI2C(); // initiate Restart condition
I2C_Done();

WriteI2C(ctrl+1); // Write Control to
while(SSPCON2bits.ACKSTAT); // Test for ACK condition, if received
I2C_Done(); // Clear SSPIF flag

while (length!=0)
{
*dptr=ReadI2C(); // Enable I2C Receiver Store EEPROM data to Point buffer
I2C_Done();
dptr++;
length--;

if (length==0) NotAckI2C();
else AckI2C(); // Continue read next data, send a acknowledge to EEPROM

I2C_Done();
}

StopI2C(); // send STOP condition
I2C_Done(); // wait until stop condition is over
}

//***********************************************
//* Check I2C action that is completed *
//***********************************************
void I2C_Done(void)
{
while (!PIR1bits.SSPIF); // Completed the action when the SSPIF is Hi.
PIR1bits.SSPIF=0; // Clear SSPIF
}

//************************************************
//* Initial I2C Master Mode with 7 bits Address *
//* Clock Speed : 100KHz @4MHz *
//************************************************
void Initialize_I2C_Master(void)
{
OpenI2C(MASTER,SLEW_ON);
SSPADD= 9;
}


上一頁 1 2 3 下一頁


評論


相關(guān)推薦

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

關(guān)閉