虫虫首页|资源下载|资源专辑|精品软件
登录|注册

您现在的位置是:虫虫下载站 > 资源下载 > 单片机编程 > 24c01a的读写程序

24c01a的读写程序

  • 资源大小:30 K
  • 上传时间: 2013-12-23
  • 上传用户:zhou28
  • 资源积分:2 下载积分
  • 标      签: 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();
}

相 关 资 源