/**********************************************************************24c02驱动的使用方法1、要想出入数据时只要使用write_data24c02(ucharaddress,ulongdate);函数即可2、要想读出数据时只要使用read_address24c02(ucharaddress)即可返回其内容值**********************************************************************///ucharshuju_24c02;//需要显示我们存入24c02的内容时才要使用此变量,否则将其屏蔽sbitSCK24c02=P1^5;sbitSDA24c02=P1^4;voiddelay24c02(uintz)//6us延时函数{while(z--);}voidinit24c02()//总线初始化函数{SCK24c02=1;delay24c02(1);SDA24c02=1;delay24c02(1);}voidstart24c02()//2402开始信号函数{SDA24c02=1;delay24c02(1);SCK24c02=1;delay24c02(1);SDA24c02=0;}voidstop24c02()//2402停止信号函数{SDA24c02=0;delay24c02(1);SCK24c02=1;delay24c02(1);SDA24c02=1;delay24c02();}voidyingda24c02()//2402应答函数{uchari;SCK24c02=1;delay24c02(1);while((SDA24c02==1)&&(i250))i++;SCK24c02=0;delay24c02(1);}voidwrite24c02(uchardate)//2402写一个字节函数{uchari,k;k=date;for(i=0;i8;i++){k=k1;SCK24c02=0;delay24c02(1);SDA24c02=CY;delay24c02(1);SCK24c02=1;delay24c02(1);}SCK24c02=0;//产生第9个脉冲}read24c02()//24c02读一个字节函数{uchari,date1;for(i=0;i8;i++){SCK24c02=1;delay24c02(1);date1=(date11)|SDA24c02;SCK24c02=0;delay24c02(1);}returndate1;}voidwrite_data24c02(ucharaddress,ulongdate)//写数据到24c02存储器的某一地址中{init24c02();start24c02();write24c02(0xa0);yingda24c02();write24c02(address);yingda24c02();write24c02(date);yingda24c02();stop24c02();}read_address24c02(ucharaddress)//读取24c02存储器中某一地址的内容,并将其返回{uchardate24c02;start24c02();//读开始write24c02(0xa0);yingda24c02();write24c02(address);yingda24c02();start24c02();write24c02(0xa1);yingda24c02();date24c02=read24c02();stop24c02();return(date24c02);}/*voiddisplay_24c02()//需要显示我们存入24c02的内容时才要使用此函数,否则将其屏蔽{ucharshuju;write_com12864(0x80);shuju=shuju_24c02/100;write_data12864(0x30+shuju);shuju=shuju_24c02%100/10;write_data12864(0x30+shuju);shuju=shuju_24c02%10;write_data12864(0x30+shuju);}*/