📄 24c01a.txt
字号:
文章编号:938----加入日期:2003-12-18
『关闭窗口』
24c01a的读写程序—原创的(清风徐徐)
#include <at24c01a.h>
/*******************************************************************************
******
向24C01A写入一个字节
输入:E2ROM地址,字节数据
********************************************************************************
******/
void write24c01a(uchar uadd_1,uchar udata_1)
{
sendbyte=0xa0;
start();
send(sendbyte);
if (!ack())
continue;
send(uadd_1);
if (!ack())
continue;
send(udata_1)
if (!ack())
continue;
stop();
}
/*************************************************************************
发送开始
************************************************************************/
void start(void)
{
a_scl=1;
a_sda=1;
a_sda=0;
a_scl=0;
a_scl=1;
}
/****************************************************************************
发送停止
****************************************************************************/
void stop(void)
{
a_scl=0;
a_sda=0;
a_scl=1;
a_sda=1;
}
/*******************************************************************************
发送反馈
********************************************************************************
/
bit ack(void)
{
int a_ack
a_scl=0;
a_scl=0;
a_scl=0;
a_scl=1;
a_ack=a_sda;
a_scl=0;
return(a_ack)
}
/*******************************************************************************
*
发送无反馈
*******************************************************************************/
bit noack(void)
{
int a_ack;
a_scl=1;
a_scl=1;
a_scl=0;
}
/*******************************************************************************
*
发送
********************************************************************************
/
void send(uchar undata)
{
uchar i;
sendbyte=undata
for(i=8;i>0;i--)
{
a_sda=sendbyte7;
a_scl=0;
a_scl=1;
sendbyte=sendbyte<<1
}
}
/******************************************************************************
接受
********************************************************************************
/
void receive(void)
{
int i;
uchar data;
for(i=8;i>0;i--)
{ a_scl=1;
receivebyte7=a_sda;
a_scl=0;
receivebyte=receivebyte>>1
}
receivedata=receivebyte;
}
/*******************************************************************************
*
向 24c01a读一个字节;
输入:EEROM地址;
输出:EEROM数据;
*******************************************************************************/
void read24c01a(uchar counter)
{
receivebyte=0xa1;
start();
send(receivebyte);
if (!ack())
continue;
send(counter);
if (!ack())
continue;
receive()
noack();
stop();
}
(文章推荐人:晓奇)
返回大虾论坛 返回首页
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -