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

📄 eeprom_access.c

📁 64输入32输出单片机程序
💻 C
字号:
// Errorcode: 0x10  -- timeout error to write a byte into eeprom of 8252

#include <AT898252.h>
#include <absacc.h>
#include <intrins.h>
#include <stdio.h>
#include <RVT_03.h>
#include <LCDPANEL.h>

//extern func.
extern void	 Enable_Timer(char timer_name, unsigned int timer_count);
extern void	 Disable_Timer(char timer_name);
extern uchar STimerStillCounting(uchar idxStimer);

// WMCON (0x96) Bit Values
// EEMEN_   0x08   Internal EEPROM Access Enable: 1=Enabled */
// EEMWE_   0x10   Internal EEPROM Write Enable: 1=Enabled */
// EERDY_   0x02   Watchdog Timer Reset and EEPROM Ready,/Busy Flag */

uchar EEPROM_Write(uint xaddr, uchar byte);
uchar EEPROM_Read( uint xaddr);
uchar EEPROM_INT_Write(uint xaddr, uint integer);
uint  EEPROM_INT_Read( uint xaddr);

//********************************************************
uchar EEPROM_Write(uint xaddr, uchar byte)
{ //writing a <byte> into the EEPROM of 89s8252
  //require around 10ms to complete 1 writing
   
  WMCON = EEMEN_ | EEMWE_ | WDTRST_;	// WMCON = 0x1a
  Enable_Timer(2, 500);	//100ms time out

  while ( !(WMCON & EERDY_ ) )	//Wait until ready for writing
		if ( !STimerStillCounting(2) ) {
			WMCON &= ~EEMWE_;
			WMCON &= ~EEMEN_;
			return ( ~byte );	//timeout error of eeprom writing
     	} // end if
	
  XBYTE[xaddr] = byte;
  while ( !(WMCON & EERDY_ ) )	//Wait until ready for writing
		if ( !STimerStillCounting(2) ) {
			WMCON &= ~EEMWE_;
			WMCON &= ~EEMEN_;
			return ( ~byte );	//timeout error of eeprom writing
     	} // end if 

  WMCON &= ~EEMWE_;				//disable eeprom write
  WMCON &= ~EEMEN_;				//disable eeprom access
  
  return ( EEPROM_Read(xaddr) );	 
} // end func.

//********************************************************
uchar EEPROM_Read( uint xaddr)
{ //READ a <byte> into the EEPROM of 89s8252
  uchar i;

  WMCON = 0x0a;		 // set read eeprom enable
  i = XBYTE[xaddr];		 // read eeprom value
  WMCON = 0x02;		 // clear eeprom RDY/-BSY = 1

  return (i);
} // end func.

//********************************************************
uchar EEPROM_INT_Write(uint xaddr, uint integer)
{  
  uchar status;

  status = EEPROM_Write( xaddr,  (uchar) (integer / 256));
  return ( status | EEPROM_Write( xaddr+1,(uchar) (integer % 256))); 
} // end func.

//********************************************************
uint  EEPROM_INT_Read( uint xaddr)
{
  uint i;

  i = (uint) EEPROM_Read(xaddr) * 256;
  return(i + (uint) EEPROM_Read(xaddr+1));
} // end func.

⌨️ 快捷键说明

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