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

📄 e93lc56.c

📁 HT48F MCU系列2K位EEPROM Data Memory的读写 - 使用C语言
💻 C
字号:
/*******************************************************************************
*                                                                            
*	Filename:E93LC56.c
*
*  	Company:    	Holtek
*	Case:
*	Device:			HT48F50E, HT48F70E
*	Clock:			4MHz Cystral 
*	
********************************************************************************
*
*	Function:
*		93LC56 Command Subroutine, 2 Stack.
*
********************************************************************************
*
*	Pin assignemt:
*
*******************************************************************************/
#include "E93LC56.h"

/******************************************************************************/
/*Sub program area		  													  */
/******************************************************************************/
//==============================================================================
//Subroutine:	READ
//Function:		Read one byte command
//==============================================================================
UC READ(UC EEADDR)
{
	UC EEDATA;
	
	_cs = 1;
	
	Shift(cREAD,4);				//OP Code
	Shift(EEADDR,8);			//Address
	EEDATA = Shift(0x00,8);
	
	_cs = 0;
	
	return EEDATA;
}

//==============================================================================
//Subroutine:	ERASE
//Function:		Erase one byte command
//==============================================================================
void ERASE(UC EEADDR)
{
	_cs = 1;
	
	Shift(cERASE,4);			//OP Code
	Shift(EEADDR,8);			//Address
	
	_cs = 0;
	
	ChkBusy();
}

//==============================================================================
//Subroutine:	WRITE
//Function:		Write one byte command
//==============================================================================
void WRITE(UC EEADDR, UC EEDATA)
{
	_cs = 1;
	
	Shift(cWRITE,4);			//OP Code
	Shift(EEADDR,8);			//Address
	Shift(EEDATA,8);			//Address	
	
	_cs = 0;
	
	ChkBusy();
}

//==============================================================================
//Subroutine:	EWEN
//Function:		Erase/Write Enable Command
//==============================================================================
void EWEN(void)
{
	_cs = 1;
	
	Shift(cEWEN,4);			//OP Code
	Shift(0x80,8);
	
	_cs = 0;
}

//==============================================================================
//Subroutine:	EWDS
//Function:		Erase/Write Disable Command
//==============================================================================
void EWDS(void)
{
	_cs = 1;
	
	Shift(cEWDS,4);			//OP Code
	Shift(0x00,8);
	
	_cs = 0;
}

//==============================================================================
//Subroutine:	ERAL
//Function:		Erase all command
//==============================================================================
void ERAL(void)
{
	_cs = 1;
	
	Shift(cERAL,4);				//OP Code
	Shift(0x00,8);				//Address

	_cs = 0;
	
	ChkBusy();
}

//==============================================================================
//Subroutine:	WRITE
//Function:		Write one byte command
//==============================================================================
void WRAL(UC EEDATA)
{
	_cs = 1;
	
	Shift(cWRAL,4);				//OP Code
	Shift(0x80,8);
	Shift(EEDATA,8);			//Address	
	
	_cs = 0;
	
	ChkBusy();
}

//==============================================================================
//Subroutine:	Shift
//Function:		
//==============================================================================
UC Shift(UC buf, UC cnt)
{
	do
	{
		if(buf & cTestb7)
			_di = 1;
		else
			_di = 0;
		
		_sk = 1;
	
		_rl(&buf);
		if(_do)
			buf |= cSetb0;
		else
			buf &= cClrb0;
		
		_sk = 0;
	
	}while(--cnt);
	
	return buf;
}

//==============================================================================
//Subroutine:	ChkBusy
//Function:		
//==============================================================================
void ChkBusy(void)
{
	_cs = 1;

	while(1)
	{
		_nop();
		_nop();
		_sk = 1;
		_nop();
		if(_do)
			break;
			
		_nop();
		_sk = 0;
	}
	
	_sk = 0;
	_cs = 0;
}	

⌨️ 快捷键说明

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