admin 管理员组文章数量: 887007
编程器提取eeprom
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
我来传一下我的I2C 24CXX的控制器的代码
看看有没有什么要改的地方
#include
#include
#define AT24C02_WriteDeviceAddress 0xa0
#define AT24C02_ReadDeviceAddress 0xa1
sbit SCL=P1^0;
sbit SDA=P1^1;
unsigned int addr=0;
void Delay()
{
unsigned char i, j;
_nop_();
i = 2;
j = 199;
do
{
while (--j);
} while (--i);
}
void Start()
{
SDA=1;
Delay();
SCL=1;
Delay();
SDA=0;
Delay();
SCL=0;
Delay();
}
void Stop()
{
SCL=0;
SDA=0;
Delay();
SCL=1;
Delay();
SDA=1;
Delay();
}
void Ack()
{
SDA=0;
Delay();
SCL=1;
Delay();
SCL=0;
Delay();
SDA=1;
Delay();
}
void NoAck()
{
SDA=1;
Delay();
SCL=1;
Delay();
SCL=0;
Delay();
}
bit TestAck()
{
bit ErrorBit;
SDA=1;
Delay();
SCL=1;
Delay();
ErrorBit=SDA;
Delay();
SCL=0;
Delay();
return (ErrorBit);
}
bit Write8Bit(unsigned char input)
{
unsigned char temp;
for(temp=8;temp!=0;temp--)
{
SDA=(bit)(input&0x80);
Delay();
SCL=1;
Delay();
SCL=0;
Delay();
input=input<<1;
}
return 1;
}
void WriteI2C(unsigned char *Wdata,unsigned char RomAddress,unsigned char number)
{
Start();
Write8Bit(AT24C02_WriteDeviceAddress);
TestAck();
Write8Bit(RomAddress);
TestAck();
for(;number!=0;number--)
{
Write8Bit(*Wdata);
TestAck();
Wdata++;
}
Stop();
Delay();
}
unsigned char Read8Bit()
{
unsigned char temp,rbyte=0;
for(temp=8;temp!=0;temp--)
{
SCL=1;
Delay();
rbyte=rbyte<<1;
Delay();
rbyte=rbyte|((unsigned char)(SDA));
SCL=0;
Delay();
}
return (rbyte);
}
void ReadI2C(unsigned char *Wdata,unsigned char RomAddress,unsigned char bytes)
{
Start();
Write8Bit(AT24C02_WriteDeviceAddress);
TestAck();
Write8Bit(RomAddress);
TestAck();
Start();
Write8Bit(AT24C02_ReadDeviceAddress);
TestAck();
while(bytes!=1)
{
*Wdata=Read8Bit();
Ack();
Wdata++;
bytes--;
}
*Wdata=Read8Bit();
NoAck();
Stop();
}
void Main(void)
{
unsigned char ch[]={0,0,0,0,0,0,0,0};
unsigned char i=0;
for(i=0;i<256;i++)
{
WriteI2C(ch,addr,8);
addr=addr+8;
}
}
本文标签: 编程器提取eeprom
版权声明:本文标题:编程器提取eeprom 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.freenas.com.cn/jishu/1732351496h1533198.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论