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

📄 24c01.h

📁 织带机产量检测系统的监测终端。RS-485总线
💻 H
字号:
#ifndef _24C01_H_
#define _24C01_H_

#include "i2c.h"

//I2C地址
#define SLA_24C01 0xA0
//页大小
#define BYTE_PER_PAGE_24C01 16

void C24SetBuf (unsigned int addr,unsigned char *buf,unsigned char len) reentrant;
void C24GetBuf (unsigned int addr,unsigned char *buf,unsigned char len) reentrant;
//write byte,integer,long
/*void C24SetByte (unsigned int addr,unsigned char val);
void C24SetInteger (unsigned int addr,unsigned int val);
void C24SetLong (unsigned int addr,unsigned long val);*/
//read byte,integer,long
//unsigned char C24GetByte (unsigned int addr);
//unsigned int C24GetInteger (unsigned int addr);
//unsigned long C24GetLong (unsigned int addr);

void C24SetBuf (unsigned int addr,unsigned char *buf,unsigned char len)	reentrant
{
	unsigned char data alen;
	unsigned char data cTime;

	addr &= 0x07FF;
	do
	{
		alen = BYTE_PER_PAGE_24C01 - (addr % BYTE_PER_PAGE_24C01);
		if (alen > len)
			alen = len;

		if (I2CSendBuf (SLA_24C01 | (addr >> 8),addr & 0xFF,buf,alen) == FALSE)
			return;
	
		cTime = 0;
		do
		{
			I2CStart ();
			SendByte (SLA_24C01);
			cTime ++;

			if (cTime >= 100)
				return;

		} while (ack == FALSE);//cTime为超时时间,12M时一般cTime==6

		buf += alen;
		len -= alen;
		addr += alen;
	} while (len > 0);
}

void C24GetBuf (unsigned int addr,unsigned char *buf,unsigned char len)	reentrant
{
	I2CRcvBuf (SLA_24C01 | (addr >> 8),addr & 0xFF,buf,len);
}

/*void C24SetByte (unsigned int addr,unsigned char val)
{
	C24SetBuf (addr,(unsigned char *)&val,sizeof (unsigned char));
}

void C24SetInteger (unsigned int addr,unsigned int val)
{
	C24SetBuf (addr,(unsigned char *)&val,sizeof (unsigned int));
}

void C24SetLong (unsigned int addr,unsigned long val)
{
	C24SetBuf (addr,(unsigned char *)&val,sizeof (unsigned long));
}*/

/*unsigned char C24GetByte (unsigned int addr)
{
	unsigned char val;
	C24GetBuf (addr,(unsigned char *)&val,sizeof (unsigned char));
	return val;
}

unsigned int C24GetInteger (unsigned int addr)
{
	unsigned int val;
	C24GetBuf (addr,(unsigned char *)&val,sizeof (unsigned int));
	return val;
}*/

/*unsigned long C24GetLong (unsigned int addr)
{
	unsigned long val;
	C24GetBuf (addr,(unsigned char *)&val,sizeof (unsigned long));
	return val;
}*/

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -