电子制作天地网站欢迎您的光临,欢迎提出宝贵意见或建议。本站信息产业部备案: 粤ICP备05114582号
24c02读写程序(已通过测试)
24C02 read / write process

时间:2010-1-25 21:18:27 来源:互联网 作者:不详 编辑: 【关闭


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
 


◆相关文章◆
◆ 编辑推荐 ◆
用户:
更多评论
您要为您所发的言论的后果负责,故请各位遵纪守法并注意语言文明。60个字以内
留言:
验证码:

免责声明:
●本站所有内容均来自网络,以学习为目的,如果侵犯了您的利益,请来信告知,立即删除,站长邮件为"diy+dzdiy.com",请将"+"变更为"@"
●电子制作存在风险,请注意人身安全,如果您在根据本站电路进行制作过程中发生伤害,本站不负任何责任。

版权所有:www.dzdiy.com ? 2001-2019 本站信息产业部备案: 粤ICP备05114582号