📄 iee1.c
字号:
** Returns :
** --- - Error code
** ===================================================================
*/
byte IEE1_GetWord(word Addr,word *Data)
{
if ((Addr < EEPROMStart)||(Addr > (EEPROMEnd - 1))) /* Is given address out of EEPROM area array ? */
return ERR_RANGE; /* If yes then error */
*Data = *(volatile word *) Addr; /* Return data from given address */
return ERR_OK; /* OK */
}
/*
** ===================================================================
** Method : IEE1_SetWait (bean IntEEPROM)
**
** Description :
** Method changes wait status of methods SetByte, SetActByte
** and SetPage.
** Parameters :
** NAME - DESCRIPTION
** Wait - TRUE - methods wait till the write
** operation to EEPROM is finished,
** FALSE - methods do not wait for the end
** of write operation
** Returns : Nothing
** ===================================================================
*/
/*
void IEE1_SetWait(bool Wait)
** This method is implemented as macro. See IEE1.h file. **
*/
/*
** ===================================================================
** Method : IEE1_Busy (bean IntEEPROM)
**
** Description :
** Method return status of EEPROM device
** Parameters : None
** Returns :
** --- - TRUE/FALSE - EEPROM is busy/ready
** ===================================================================
*/
/*
bool IEE1_Busy(void)
** This method is implemented as macro. See IEE1.h file. **
*/
/*
** ===================================================================
** Method : IEE1_Init (bean IntEEPROM)
**
** Description :
** This method is internal. It is used by Processor Expert
** only.
** ===================================================================
*/
void IEE1_Init(void)
{
ECLKDIV = 74; /* Set up Clock Divider Register */
IEE1_Wait = TRUE; /* No wait in loop to command complete */
}
/* END IEE1. */
/*
** ###################################################################
**
** This file was created by UNIS Processor Expert 03.33 for
** the Motorola HCS12 series of microcontrollers.
**
** ###################################################################
*/
/*****************************************************
* 在Eeprom的Addr位置写入word类型的数据Data
*****************************************************/
void WriteEepromWord(word Addr, word Data)
{
word tmpWord;
while (IEE1_Busy());
IEE1_GetWord(Addr, &tmpWord);
if (Data != tmpWord)
{
while (IEE1_Busy());
IEE1_SetWord(Addr, Data);
}
}
/*****************************************************
* 在Eeprom的Addr位置读取word类型的数据
*****************************************************/
word ReadEepromWord(word Addr)
{
word tmpWord;
while (IEE1_Busy());
IEE1_GetWord(Addr, &tmpWord);
return tmpWord;
}
/*****************************************************
* 在Eeprom的Addr位置写入byte类型的数据Data
*****************************************************/
void WriteEepromByte(word Addr, byte Data)
{
byte tmpByte;
while (IEE1_Busy());
IEE1_GetByte(Addr, &tmpByte);
if (Data != tmpByte)
{
while (IEE1_Busy());
IEE1_SetByte(Addr, Data);
}
}
/*****************************************************
* 在Eeprom的Addr位置读取byte类型的数据
*****************************************************/
byte ReadEepromByte(word Addr)
{
byte tmpByte;
while (IEE1_Busy());
IEE1_GetByte(Addr, &tmpByte);
return tmpByte;
}
/*
** ===================================================================
** Method : IEE2_SetLong (bean IntEEPROM)
**
** Description :
** Method writes given long word to the given address in
** EEPROM.
** Parameters :
** NAME - DESCRIPTION
** Addr - Address to EEPROM
** Data - Data to write
** Returns :
** --- - Error code
** ===================================================================
*/
byte IEE2_SetLong(word Addr,dword Data)
{
if ((Addr < EEPROMStart)||(Addr > (EEPROMEnd - 3))) /* Is given address out of EEPROM area array ? */
return ERR_RANGE; /* If yes then error */
if (Addr & 0x0003) /* Aligned address ? */
return ERR_NOTAVAIL;
return (WriteSector(Addr,Data)); /* Write new content of given sector */
}
/*
** ===================================================================
** Method : IEE2_GetLong (bean IntEEPROM)
**
** Description :
** Method reads long word from the given EEPROM address
** Parameters :
** NAME - DESCRIPTION
** Addr - Address to EEPROM
** * Data - Pointer to returned 32-bit data
** Returns :
** --- - Error code
** ===================================================================
*/
byte IEE2_GetLong(word Addr,dword *Data)
{
if ((Addr < EEPROMStart)||(Addr > (EEPROMEnd - 3))) /* Is given address out of EEPROM area array ? */
return ERR_RANGE; /* If yes then error */
*Data = *(volatile dword *) Addr; /* Return data from given address */
return ERR_OK; /* OK */
}
/*****************************************************
* 在Eeprom的Addr位置写入lonh类型的数据Data
*****************************************************/
void WriteEepromDword(word Addr, dword Data)
{
dword tmpDword;
while (IEE1_Busy());
IEE2_GetLong(Addr, &tmpDword);
if (Data != tmpDword)
{
while (IEE1_Busy());
IEE2_SetLong(Addr, Data);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -