专家
公告
财富商城
电子网
旗下网站
首页
问题库
专栏
标签库
话题
专家
NEW
门户
发布
提问题
发文章
51单片机
用过c8051f SMBUS读写eeprom的进来!
2020-02-03 10:12
发布
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
站内问答
/
51单片机
3206
14
14
用c8051f120 的smbus 读写24c16 能正常! 用的是官方的example 但读写24c32时不行 个人认为应该是写地址的时候出错了 因为24c32要写2个byte的地址 有没有哪位以前遇到过哦 2个byte的地址应该怎么写进去啊?? 急急。。。
友情提示:
此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
14条回答
pingsiu
2020-02-04 02:46
//-----------------------------------------------------------------------------
// Functions Prototype
//-----------------------------------------------------------------------------
char EPROM_WriteBlock (unsigned char addr, unsigned char l, unsigned char *da)
{
unsigned char x;
unsigned int y;
//---------------------------------------------------------------
EEPwp = 0; // write on
for (x=0; x<l; x++) {
eep.chipAddr = 0xa0; // chip address
eep.addr1st = addr+x;
eep.dataLen = 1; // data len
eep.dataPtr = 0;
eep.dataArray = da+x; // data byte
eep.step = EEP_WRITE_INT;
eep.on = ON;
STO = 0;
STA = 1;
while (eep.step != EEP_READY_INT);
eep.on = OFF;
for (y=0; y<8192; y++);
}
EEPwp = 1; // write OFF
//---------------------------------------------------------------
return eep.addr1st;
}
//-----------------------------------------------------------------------------
char EPROM_ReadBlock (unsigned char addr, unsigned char l, unsigned char *da)
{
unsigned x;
unsigned int epAddr;
//---------------------------------------------------------------
for (x=0; x<l; x++) {
eep.chipAddr = 0xa0;
eep.addr1st = addr+x;
eep.dataLen = 0;
eep.step = EEP_WRITE_INT;
eep.on = ON;
STO = 0;
STA = 1;
while (eep.step != EEP_READY_INT);
// Read time data from eep.
eep.chipAddr = 0xa1;
eep.dataLen = 1;
eep.dataPtr = 0;
eep.dataArray = da+x;
eep.step = EEP_READ_INT;
STO = 0;
STA = 1;
while (eep.step != EEP_READY_INT);
eep.on = OFF;
}
//---------------------------------------------------------------
return epAddr+1;
}
//-----------------------------------------------------------------------------
// SMBUS (vector 7) Interrupt handler.
//-----------------------------------------------------------------------------
void smbus_int (void) interrupt SMB_VECTOR using 3
{
if (eep.on) {
switch (eep.step) {
case EEP_READY_INT :
break;
case EEP_WRITE_INT :
if (SMB0STA == SMB_START) {
SMB0DAT = eep.chipAddr;
STA = 0;
eep.step++;
}
break;
case EEP_WRITE_INT+1 :
SMB0DAT = eep.addr1st;
eep.step++;
break;
case EEP_WRITE_INT+2 :
if (eep.dataPtr < eep.dataLen) {
SMB0DAT = eep.dataArray[eep.dataPtr++];
} else {
STO = 1;
eep.step = EEP_READY_INT;
}
break;
//-------------------------------------------------------------------------
case EEP_READ_INT :
if (SMB0STA == SMB_START) {
STA = 0;
SMB0DAT = eep.chipAddr;
eep.step++;
}
break;
case EEP_READ_INT+1 :
if (eep.dataLen == 1)
AA = 0;
eep.step++;
break;
case EEP_READ_INT+2 :
eep.dataArray[eep.dataPtr++] = SMB0DAT;
switch (eep.dataLen-eep.dataPtr) {
case 0 :
AA = 1;
STO = 1;
eep.step = EEP_READY_INT;
break;
case 1 :
AA = 0;
break;
default :
break;
}
break;
}
SI = 0;
}
}
加载中...
查看其它14个回答
一周热门
更多
>
相关问题
【东软载波ESF0654 PDS开发板活动】开箱
1 个回答
东软载波ESF0654 PDS开发板外部中断
1 个回答
东软载波ESF0654 PDS开发板高级控制定时器AD16C4T
1 个回答
用串口调试助手为什么只能在hex模式接收发送而在文本模式不行
9 个回答
触摸芯片SC02B/SC04B在地砖灯的设计方案
1 个回答
相关文章
51单片机与蓝牙模块连接
0个评论
51单片机的硬件结构
0个评论
基于51单片机的无线遥控器制作
0个评论
51单片机 AD转换
0个评论
51单片机数码管递增显示
0个评论
如何实现对单片机寄存器的访问
0个评论
基于51单片机的指纹密码锁
0个评论
×
关闭
采纳回答
向帮助了您的知道网友说句感谢的话吧!
非常感谢!
确 认
×
关闭
编辑标签
最多设置5个标签!
51单片机
保存
关闭
×
关闭
举报内容
检举类型
检举内容
检举用户
检举原因
广告推广
恶意灌水
回答内容与提问无关
抄袭答案
其他
检举说明(必填)
提交
关闭
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
×
付费偷看金额在0.1-10元之间
确定
×
关闭
您已邀请
0
人回答
查看邀请
擅长该话题的人
回答过该话题的人
我关注的人
// Functions Prototype
//-----------------------------------------------------------------------------
char EPROM_WriteBlock (unsigned char addr, unsigned char l, unsigned char *da)
{
unsigned char x;
unsigned int y;
//---------------------------------------------------------------
EEPwp = 0; // write on
for (x=0; x<l; x++) {
eep.chipAddr = 0xa0; // chip address
eep.addr1st = addr+x;
eep.dataLen = 1; // data len
eep.dataPtr = 0;
eep.dataArray = da+x; // data byte
eep.step = EEP_WRITE_INT;
eep.on = ON;
STO = 0;
STA = 1;
while (eep.step != EEP_READY_INT);
eep.on = OFF;
for (y=0; y<8192; y++);
}
EEPwp = 1; // write OFF
//---------------------------------------------------------------
return eep.addr1st;
}
//-----------------------------------------------------------------------------
char EPROM_ReadBlock (unsigned char addr, unsigned char l, unsigned char *da)
{
unsigned x;
unsigned int epAddr;
//---------------------------------------------------------------
for (x=0; x<l; x++) {
eep.chipAddr = 0xa0;
eep.addr1st = addr+x;
eep.dataLen = 0;
eep.step = EEP_WRITE_INT;
eep.on = ON;
STO = 0;
STA = 1;
while (eep.step != EEP_READY_INT);
// Read time data from eep.
eep.chipAddr = 0xa1;
eep.dataLen = 1;
eep.dataPtr = 0;
eep.dataArray = da+x;
eep.step = EEP_READ_INT;
STO = 0;
STA = 1;
while (eep.step != EEP_READY_INT);
eep.on = OFF;
}
//---------------------------------------------------------------
return epAddr+1;
}
//-----------------------------------------------------------------------------
// SMBUS (vector 7) Interrupt handler.
//-----------------------------------------------------------------------------
void smbus_int (void) interrupt SMB_VECTOR using 3
{
if (eep.on) {
switch (eep.step) {
case EEP_READY_INT :
break;
case EEP_WRITE_INT :
if (SMB0STA == SMB_START) {
SMB0DAT = eep.chipAddr;
STA = 0;
eep.step++;
}
break;
case EEP_WRITE_INT+1 :
SMB0DAT = eep.addr1st;
eep.step++;
break;
case EEP_WRITE_INT+2 :
if (eep.dataPtr < eep.dataLen) {
SMB0DAT = eep.dataArray[eep.dataPtr++];
} else {
STO = 1;
eep.step = EEP_READY_INT;
}
break;
//-------------------------------------------------------------------------
case EEP_READ_INT :
if (SMB0STA == SMB_START) {
STA = 0;
SMB0DAT = eep.chipAddr;
eep.step++;
}
break;
case EEP_READ_INT+1 :
if (eep.dataLen == 1)
AA = 0;
eep.step++;
break;
case EEP_READ_INT+2 :
eep.dataArray[eep.dataPtr++] = SMB0DAT;
switch (eep.dataLen-eep.dataPtr) {
case 0 :
AA = 1;
STO = 1;
eep.step = EEP_READY_INT;
break;
case 1 :
AA = 0;
break;
default :
break;
}
break;
}
SI = 0;
}
}
一周热门 更多>