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

📄 x24c44.h

📁 这个是一个用Keil C51编写的带SRAM的EEPROM芯片X24C44的驱动程序示例
💻 H
字号:
/************************************************************/
/*********         X24C44.H C51 driver          *************/
/**********  Written by WangBiao---20060825  ****************/
/************************************************************/
//16 word * 16 bit=32 Byte * 8 bit
//-----------------------------------------------------------------------
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//-----------------------------------------------------------------------
sbit CE=P2^4;
sbit SK=P2^5;
sbit DI=P2^6;
sbit DO=P2^7;
//-----------------------外部函数----------------------------------------
//Attantion!!!when after Recall_Ram ,you must Write_Enable to WriteChar or WriteWord
//-----------------------------------------------------------------
unsigned char ReadChar_X24C44(unsigned char Dummy_Address);
void WriteChar_X24C44(unsigned char Dummy_Address,unsigned char InData);
//---------------------
void WriteWord_X24C44(unsigned char Address,unsigned int InData);
unsigned int ReadWord_X24C44(unsigned char Address);
void Write_Disable(void);
void Write_Enable(void);
void Store_Ram(void);
void Recall_Ram(void);
//-----------------------------------------------------------------------
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//-----------------------------------------------------------------------
//-----------------------内部函数----------------------------------------
void Send_CMD_Byte(unsigned char InData);
void Send_DAT_Word(unsigned int InData);
unsigned int Rece_DAT_Word(void);
//-----------------------------------------------------------------------
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//-----------------------------------------------------------------------
//----------------------具体子函数---------------------------------------
//---------------------
void Send_CMD_Byte(unsigned char InData)
{
	unsigned char i;

	for(i=0;i<8;i++)
	{
		if(InData&0x80) DI=1;
		else DI=0;
		SK=1;
		InData<<=1;
		SK=0;
	}
}
//---------------------
void Send_DAT_Word(unsigned int InData)
{
	unsigned char i;

	for(i=0;i<16;i++)
	{
		if(InData&0x8000) DI=1;
		else DI=0;
		SK=1;
		InData<<=1;
		SK=0;
	}
}
//---------------------
unsigned int Rece_DAT_Word(void)
{
	unsigned char i;
	unsigned int OutData=0;

	for(i=0;i<16;i++)
	{
		OutData<<=1;
		if(DO) OutData|=1;
		SK=1;
		SK=0;
	}
	return OutData;
}
//----------------------
void WriteWord_X24C44(unsigned char Address,unsigned int InData)
{	
	unsigned char t;

	CE=1;

	t=(Address<<3)|0x83;
	Send_CMD_Byte(t);
	Send_DAT_Word(InData);

	CE=0;
}
//----------------------
unsigned int ReadWord_X24C44(unsigned char Address)
{
	unsigned char t;
	unsigned int n;

	CE=1;

	t=(Address<<3)|0x86;
	Send_CMD_Byte(t);
	n=Rece_DAT_Word();

	CE=0;

	return n;
}
//----------------------
void Write_Disable(void)
{
	CE=1;
	Send_CMD_Byte(0x80);
	CE=0;
}
//----------------------
void Write_Enable(void)
{
	CE=1;
	Send_CMD_Byte(0x84);
	CE=0;
}
//----------------------
void Store_Ram(void)
{
	CE=1;
	Send_CMD_Byte(0x81);
	CE=0;
}
//----------------------
void Recall_Ram(void)
{
	CE=1;
	Send_CMD_Byte(0x85);
	CE=0;
}
//--------------------------------------------------------------
//----------------------
void WriteChar_X24C44(unsigned char Dummy_Address,unsigned char InData)
{	
	unsigned char Address;
	unsigned int t,n;

	n=InData;

	Address=Dummy_Address>>1;
	t=ReadWord_X24C44(Address);

	if(Dummy_Address&0x01) 
	{
		t=(t&0xff00)|n;
		WriteWord_X24C44(Address,t);
	}//Dummy_Address 1 store low bit
	else
	{
		t=(t&0x00ff)|(n<<8);
		WriteWord_X24C44(Address,t);
	}//Dummy_Address 0 store high bit

}
//----------------------
unsigned char ReadChar_X24C44(unsigned char Dummy_Address)
{
	unsigned char Address,n;
	unsigned int t;

	Address=Dummy_Address>>1;
	t=ReadWord_X24C44(Address);

	if(Dummy_Address&0x01) n=t&0x00ff;//Dummy_Address 1 store low bit
	else n=(t&0xff00)>>8;//Dummy_Address 0 store high bit

	return n;
}
//-------------------End X24C44.H-----------------------------------------

⌨️ 快捷键说明

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