I2C 24LC02 C读写例程(PIC单片机)
=====================*/
uchar receive_byte()
{
uchar retc,bit_count;
retc=0;
SDA=1;
for (bit_count=0;bit_count<8;bit_count++)
{
nop();
SCL=0;
nop();nop();nop();nop();nop();
SCL=1;
nop();nop();
retc=retc<1;
if (RC4==1) retc=retc+1;
nop();nop();
}
SCL=0;
nop();nop();
return (retc);
}
/*================================================================
向有子地址器件发送多字节数据函数
函数原型: bit I_send_str(uchar sla,uchar suba,uchar *s,uchar no);
Function: 从启动总线到发送地址,数据,结束总线的全过程,从器件地址sla。如果
返回1表示操作成功,否则操作有误。
=================================================================*/
void I_send_str(uchar sla,uchar suba,uchar *s,uchar no)
{
uchar i;
start_i2c();
send_byte(sla);
if (ack==0) i2c_error();
send_byte(suba);
if (ack==0) i2c_error();
for (i=0;i { send_byte(*s); if (ack==0) i2c_error(); s++; } stop_i2c(); // return(1); } /***************************************************************** 延时函数 函数原型: void delay_250ms(); FUNCTION: 延明250ms *****************************************************************/ void delay_250ms() { unsigned int d=24999; while (--d); } /***************************************************************** 总线错误函数 函数原型: void i2c_error(); Function: 通过RD7闪动8次表示总线操作失败一次报警。 *****************************************************************/ void i2c_error () { uchar i; for (i=0;i<8;i++) { RD7=0; delay_250ms(); RD7=1; delay_250ms(); } } /**********END**************/
I2C24LC02PIC单片 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)
