?? 24c01a.txt
字號(hào):
文章編號(hào):938----加入日期:2003-12-18
『關(guān)閉窗口』
24c01a的讀寫程序—原創(chuàng)的(清風(fēng)徐徐)
#include <at24c01a.h>
/*******************************************************************************
******
向24C01A寫入一個(gè)字節(jié)
輸入:E2ROM地址,字節(jié)數(shù)據(jù)
********************************************************************************
******/
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();
}
/*************************************************************************
發(fā)送開始
************************************************************************/
void start(void)
{
a_scl=1;
a_sda=1;
a_sda=0;
a_scl=0;
a_scl=1;
}
/****************************************************************************
發(fā)送停止
****************************************************************************/
void stop(void)
{
a_scl=0;
a_sda=0;
a_scl=1;
a_sda=1;
}
/*******************************************************************************
發(fā)送反饋
********************************************************************************
/
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)
}
/*******************************************************************************
*
發(fā)送無反饋
*******************************************************************************/
bit noack(void)
{
int a_ack;
a_scl=1;
a_scl=1;
a_scl=0;
}
/*******************************************************************************
*
發(fā)送
********************************************************************************
/
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讀一個(gè)字節(jié);
輸入:EEROM地址;
輸出:EEROM數(shù)據(jù);
*******************************************************************************/
void read24c01a(uchar counter)
{
receivebyte=0xa1;
start();
send(receivebyte);
if (!ack())
continue;
send(counter);
if (!ack())
continue;
receive()
noack();
stop();
}
(文章推薦人:曉奇)
返回大蝦論壇 返回首頁
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -