AT24C256完整程序.docx

上传人:b****5 文档编号:11927628 上传时间:2023-04-16 格式:DOCX 页数:9 大小:28.48KB
下载 相关 举报
AT24C256完整程序.docx_第1页
第1页 / 共9页
AT24C256完整程序.docx_第2页
第2页 / 共9页
AT24C256完整程序.docx_第3页
第3页 / 共9页
AT24C256完整程序.docx_第4页
第4页 / 共9页
AT24C256完整程序.docx_第5页
第5页 / 共9页
点击查看更多>>
下载资源
资源描述

AT24C256完整程序.docx

《AT24C256完整程序.docx》由会员分享,可在线阅读,更多相关《AT24C256完整程序.docx(9页珍藏版)》请在冰豆网上搜索。

AT24C256完整程序.docx

AT24C256完整程序

AT24C256完整程序

/******************************************

AT24C64C语言程序

copyright@lance

******************************************/

#include"c8051F020.h"

#include"24C256.h"

#include"LCD_display.h"

sbitISCL=P1^4;

sbitISDA=P1^3;

/*****************************************

I2cWait

WaitforsometimetogetproperI2Ctiming

******************************************/

voidI2cWait(void)

{

/*****************************************

I2csotp

conditionSDA=0-1whileSCL=1

******************************************/

voidI2cStop(void)

{

ISDA=0;

I2cWait();

ISCL=1;

I2cWait();

ISDA=1;

I2cWait();

}

/*****************************************

I2cInit

InitializeI2Cinterface

ReleaseI2cBUS

****************************************

voidI2cInit(void)

{

ISDA=1;

ISCL=1;

I2cWait();

}

**/

/*****************************************

I2cSentByte

mastertransferdatatoslaveandreturnacknowledgebit

don'tinclude

******************************************/

bitI2cSentByte(unsignedcharbytedata)

{

unsignedchari;

bitack;

for(i=0;i<8;i++)

{

if(bytedata&0x80)

ISDA=1;

else

ISDA=0;

bytedata<<=1;

I2cWait();

ISCL=1;

I2cWait();

ISCL=0;

I2cWait();

}

ISDA=1;

I2cWait();

ISCL=1;

I2cWait();

ack=ISDA;

ISCL=0;

I2cWait();

returnack;

}

/*****************************************

I2cReceiveByte

slavetrransferdatatomaster

******************************************/

unsignedcharI2cReceiveByte(void)

{

unsignedchari;

unsignedcharbytedata=0;

ISCL=0;

I2cWait();

for(i=0;i<8;i++)

{

ISCL=1;

I2cWait();

bytedata=bytedata<<1;

if(ISDA==1)

{

bytedata=bytedata|0x01;

}

I2cWait();

ISCL=0;

I2cWait();

}

returnbytedata;

}

/*****************************************

I2cSendAcknowledge

Mastersendacknowledgebittoslave

acknowledge="0",non-acknowledge="1"

******************************************/

voidSendAcknowledge(bitack)

{

ISDA=ack;

ISCL=1;

I2cWait();

ISCL=0;

}

/*****************************************

24c64WriteByte

addr:

0-8192

value:

数据

******************************************/

void_24c64WriteByte(unsignedintaddr,unsignedcharvalue)

{

I2cStart();

I2cSentByte(0xA0);

I2cSentByte(addr>>8);//送高位地址

I2cSentByte(addr&0xff);//送低位地址

I2cSentByte(value);

I2cStop();

delay1ms(15);

}

/*****************************************

24c64WriteMulti

page:

0-255

count:

要写入的数个数

******************************************/

void_24c64WriteMulti(unsignedintpage,unsignedcharcount,unsignedchar*SenBuf)

{

unsignedchari;

unsignedintaddr=page*32;

I2cStart();

I2cSentByte(0xa0);

I2cSentByte(addr>>8);//送高位地址

I2cSentByte(addr&0x00ff);//送低位地址

for(i=0;i

{

I2cSentByte(SenBuf[i]);

}

I2cStop();

delay1ms(15);

}

/*****************************************

24c64ReadByte

addr:

0-8192

******************************************/

unsignedchar_24c64ReadByte(unsignedintaddr)

{

unsignedchartemp;

I2cStart();

I2cSentByte(0xa0);

I2cSentByte(addr>>8);//送高位地址

I2cSentByte(addr&0x00ff);//送低位地址

 

I2cStart();

I2cSentByte(0xa1);

temp=I2cReceiveByte();

SendAcknowledge

(1);

I2cStop();

returntemp;

}

/*****************************************

24c64ReadMulti

page:

0-256,count0-32

count:

要读出的数的个数

******************************************/

void_24c64ReadMulti(unsignedintpage,unsignedcharcount,unsignedchar*RedBuf)

{unsignedintaddr=page*32;

unsignedchari;

for(i=0;i

{

RedBuf[i]=_24c64ReadByte(addr);

addr++;

}

SendAcknowledge

(1);

I2cStop();

}

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 小学教育 > 其它课程

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1