?? 24c02.c
字號:
/***********************************************************
* source file for operation at24c02
* write by : lp.xiao
* Rev 1.0 06.9.29
***********************************************************/
#include "24C02.h"
#include "i2c.h"
void DelayEEPROM()
{
unsigned int sq0;
for(sq0=0;sq0<20000;sq0++);
}
/***********************************************************
* write one byte in at24c02
* input parameter:1:address 2:data buffer be wrote
* output parameter: 1:success 0:fail
***********************************************************/
unsigned char WriteByte(unsigned int addr,unsigned char *pbuf)
{
START;
if(!SendByte(DEVICE_W)) return 0;
if(!SendByte(addr)) return 0;
if(!SendByte(*pbuf)) return 0;
STOP;
return 1;
}
/***********************************************************
* write more than one byte in at24c02 from random beginning address
* input parameter:1:address 2:data buffer be wrote 3:size be wrote
* output parameter: 1:success 0:fail
***********************************************************/
unsigned char WritePage(unsigned int addr,unsigned char *pbuf,unsigned int num)
{
START;
if(!SendByte(DEVICE_W)) return 0;
if(!SendByte(addr)) return 0;
for(;num>0;num--)
{
if(!SendByte(*pbuf))
return 0;
else
pbuf++;
}
STOP;
DelayEEPROM();
return 1;
}
/***********************************************************
* Read one byte in at24c02 from random address
* input parameter:1:address 2:point to data be read
* output parameter: 1:success 0:fail
***********************************************************/
unsigned char ReadByte(unsigned int addr,unsigned char *pbuf)
{
START;
if(!SendByte(DEVICE_W)) return 0;
if(!SendByte(addr)) return 0;
START;
if(!SendByte(DEVICE_R)) return 0;
*pbuf = RecByte();
NOACK;
STOP;
return 1;
}
/***********************************************************
* Read more than one byte in at24c02 from random beginning address
* input parameter:1:address 2:point to data be read 3:size be read
* output parameter: 1:success 0:fail
***********************************************************/
unsigned char ReadSeq(unsigned int addr,unsigned char *pbuf,unsigned int num)
{
START;
if(!SendByte(DEVICE_W)) return 0;
if(!SendByte(addr)) return 0;
START;
if(!SendByte(DEVICE_R)) return 0;
for(;num>0;num--)
{
*pbuf = RecByte();
pbuf++;
if(num !=1)
ACK;
else
NOACK;
}
STOP;
return 1;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -