×

24c01a的读写程序

消耗积分:10 | 格式:rar | 大小:33 | 2009-01-19

分享资料个

#include
/*******************************************
******
向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();
}

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

评论(2)
发评论
wlq47 2011-09-19
0 回复 举报
支持 收起回复
请输入网名 2011-04-18
0 回复 举报
很好 收起回复

下载排行榜

全部2条评论

快来发表一下你的评论吧 !