简洁清晰的例程:
/***********************************************************************
º¯ÊýÃû³Æ£ºI2C_Test(void)
¹¦ ÄÜ£º²âÊÔEEPROM
ÊäÈë²ÎÊý£º
Êä³ö²ÎÊý£º
±àдʱ¼ä£º2012.11.22
±à д ÈË£º
×¢ Ò⣺ÏÈÏòEEPROMдָ¶¨Êý¾Ý£¬È»ºóÔÙ¶Á³öÀ´£¬×îºóͨ¹ýRS232·¢Ë͵½µçÄÔÉÏ£¬
ÒÔÑéÖ¤¶ÁдÊÇ·ñÕýÈ·
***********************************************************************/
void I2C_Test(void)
{
unsigned int i = 0;
unsigned char WriteBuffer[256];
unsigned char ReadBuffer[256];
for(i = 0;i < 256;i ++)//³õʼ»¯´ýдÊý¾ÝÇø
{
WriteBuffer[i] = i;
}
I2C_Write(I2C1,ADDR_24LC02,0,WriteBuffer,sizeof(WriteBuffer)); //ÏòEEPROMдÊý¾Ý
I2C_Read(I2C1,ADDR_24LC02,0,ReadBuffer,sizeof(WriteBuffer)); //ÏòEEPROM¶ÁÊý¾Ý
RS232_Send_Data(ReadBuffer,256); //ͨRS232½«¶Áµ½µÄÊý¾Ý·¢³öÈ¥
}
1