ES =0;
switch(type)
{
case 0x01:
case 0x02:
case 0x04:
case 0x08:
case 0x16:
type =0x02;
addr[1] |=0xa0;
device_addr 《《=1;
addr[1] |=device_addr;
break;
default:
type =0x03;
addr[2] |=0xa0;
device_addr 《《=1;
addr[2] |=device_addr;
}
if(rw ==0x01) //读EEPROM
{
read_eeprom();
}
else if(rw ==0x00) //写EEPROM
{
write_eeprom();
}
else //error command
{
error();
ACC =0x01;
SBUF =ACC;
while(!TI);
TI =0;
}
}
}
void read_eeprom(void)
{
uchar i;
WP =1;
iic_start();
for(i=1;i《=type;i++)
{
send_data =addr[type-i];
send_byte();
iic_ack();
if(ack_flag ==0x01)
break;
}
if(ack_flag ==0x00)
{
iic_start();
addr[type-1] |=0x01;
send_data =addr[type-1];
send_byte();
iic_ack();
if(ack_flag ==0x00)
{
for(i=0;i
//如果你对本程序或者24C01读写还有什么疑问,欢迎到的论坛去交流。
void write_eeprom(void)
{
uchar i;
WP =0;
iic_start();
for(i=1;i《=type;i++)
{
send_data =addr[type-i];
send_byte();
iic_ack();
if(ack_flag ==0x01)
break;
}
if(ack_flag ==0x00)
{
for(i=0;i
void read_byte(void)
{
uchar i,temp=0x80;
send_data =0x00;
SCL =0;
for(i=0;i《8;i++)
{
SDA =1;
SCL =1;
if(SDA)
send_data |=temp;
temp/=2;
SCL =0;
iic_delay();
}
}
void send_byte(void)
{
uchar i,temp=0x80;
for(i=0;i《8;i++)
{
if((send_data&temp)==temp)