1 24c02读写程序(已通过测试),24C02 read / write process-德赢Vwin官网 网

24c02读写程序(已通过测试),24C02 read / write process

电子说

1.3w人已加入

描述

24c02读写程序(已通过测试),24C02 read / write process

关键字:24c02读写程序(已通过测试)

24c02读写程序(已通过测试)
 
24c02读写程序(已通过测试)#ifndef _24C02_H
#define _24C02_H

// 脚定义
sbit SCL = P3^7; //24c02 SCL
sbit SDA = P3^6; //24c02 SDA

// 功能函数
void x24c02_delay(char x)
{
int i;
for(i=0;i}

void x24c02_start()
{
SDA = 1;
SCL = 1;
SDA = 0;
SCL = 0;
}

void x24c02_stop()
{
SDA=0;
SCL=1;
SDA=1;
}
void x24c02_writex(char j)
{
char i,temp;
temp=j;
for (i=0;i<8;i++)
{
temp=temp<<1;
SCL=0;
SDA=CY;
SCL=1;
}
SCL=0;
SDA=1;
}
char x24c02_readx()
{
char i,j,k=0;
SCL=0;
SDA=1;
for (i=0;i<8;i++)
{
SCL=1;
if (SDA==1) j=1;
else j=0;
k=(k<<1)|j;
SCL=0;
}
return(k);
}
void x24c02_clock()
{
char i=0;
SCL=1;
while ((SDA==1)&&(i<255))i++;
SCL=0;
}

void x24c02_init()
{
SCL = 1;
SDA = 1;
}

char x24c02_read(char address)
{
char i;
x24c02_start();
x24c02_writex(0xa0);
x24c02_clock();
x24c02_writex(address);
x24c02_clock();
x24c02_start();
x24c02_writex(0xa1);
x24c02_clock();
i=x24c02_readx();
x24c02_stop();
x24c02_delay(10);
return(i);
}

void x24c02_write(char address, char info)
{
EA=0;
x24c02_start();
x24c02_writex(0xa0);
x24c02_clock();
x24c02_writex(address);
x24c02_clock();
x24c02_writex(info);
x24c02_clock();
x24c02_stop();
EA=1;
x24c02_delay(50);
}

void x24c02_writestr(char address, unsigned char *wdata, unsigned char wlen)
{
unsigned char k=0;
do
{
x24c02_write(address+k, *(wdata + k));
k++;
} while(k < wlen);
}

void x24c02_readstr(char address, unsigned char *rdata, unsigned char rlen)
{
unsigned char k=0;
do
{
rdata[k] = x24c02_read(address+k);
k++;
} while(k < rlen);
}

#endif
 
打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表德赢Vwin官网 网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
  • 相关推荐

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分