⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 24c02.c

📁 MSP430开发的使用PID算法温度控制程序 本程序通过485总线与上位机通信发送和接受命令
💻 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 + -