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

📄 e93lc46.c

📁 对合泰单片机的内部EEPROGRAM读写的例程
💻 C
字号:
/*******************************************************************************
*                                                                            
*	Filename:E93LC46.c
*
*  	Author:			maggie
*  	Company:    	Holtek
*	Case:
*	Device:			HT48F06E, HT48F10E, HT48F30E
*   Date:       	2007/01/18
*	Modifier:
*	Modify Date:
*   Visions:   		1.0
*   Compiler:		HT-IDE3000 V6.5 SP2 
*	Clock:			4MHz Cystral 
*	
********************************************************************************
*
*	Function:
*		93LC46 Command Subroutine, 2 Stack.
*
********************************************************************************
*
*	Pin assignemt:
*
*******************************************************************************/
#include "E93LC46.h"

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

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

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

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

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

//==============================================================================
//Subroutine:	ERAL
//Function:		Erase all command
//==============================================================================
void ERAL(void)
{
	_cs = 1;
	
	Shift(cERAL,3);				//OP Code
	Shift(0x80,7);				//Address

	_cs = 0;
	
	ChkBusy();
}

//==============================================================================
//Subroutine:	WRITE
//Function:		Write one byte command
//==============================================================================
void WRAL(UC EEDATA)
{
	_cs = 1;
	
	Shift(cWRAL,3);				//OP Code
	Shift(0x40,7);
	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 + -