|
发表于 2011-11-25 23:06:03
|
显示全部楼层
/*先在24C02中写入8个数据,然后依次将其读出,用对应LED指示读出的数据是否正确。*/
/*main.c*/
#include <iom16v.h>
#include "iic.h"
#include "function.h"
void main()
{
unsigned char temp1[8]={18,17,16,15,14,13,12,11};
unsigned char temp2[8]={0};
port_init();
LED_init();
I2C_Init();
I2C_Write_(0xa0,0X00,temp1,8);//一次在[0X00-0X07]中写入8个字节
DelayMs(5);
I2C_Read_(0xa1,0X00,temp2,8); //一次在[0X00-0X07]中读取8个字节
DelayMs(5);
while(1)
{
if(temp2[0]==18)
{
PORTB=0XFE;
DelayMs(100);
PORTB=0XFF;
DelayMs(50);
}
if(temp2[1]==17)
{
PORTB=0XFD;
DelayMs(100);
PORTB=0XFF;
DelayMs(50);
}
if(temp2[2]==16)
{
PORTB=0XFB;
DelayMs(100);
PORTB=0XFF;
DelayMs(50);
}
if(temp2[3]==15)
{
PORTB=0XF7;
DelayMs(100);
PORTB=0XFF;
DelayMs(50);
}
if(temp2[4]==14)
{
PORTB=0XEF;
DelayMs(100);
PORTB=0XFF;
DelayMs(50);
}
if(temp2[5]==13)
{
PORTB=0XDF;
DelayMs(100);
PORTB=0XFF;
DelayMs(50);
}
if(temp2[6]==12)
{
PORTB=0XBF;
DelayMs(100);
PORTB=0XFF;
DelayMs(50);
}
if(temp2[7]==11)
{
PORTB=0X7F;
DelayMs(100);
PORTB=0XFF;
DelayMs(50);
}
}
} |
|