📄 flash_api.c
字号:
*****************************************************************************/
#ifdef __API_WR_CODE_PAGE_FIX
Uchar __api_wr_code_page_fix (Uchar xdata * pt_code, Uchar xdata * pt_xram, Uchar nb_data)
{
bit ea_save;
Uint16 add_xram;
data Uint16 add_code;
add_xram = DPTR; // save the DPTR
add_code = pt_code;
ea_save = EA;
EA = 0;
add_xram = pt_xram;
api_command =0x01;
api_value = nb_data;
api_dpl = LOW(add_xram);
api_dph = ((Uchar)((add_xram)>>8));
AUXR1++;
// add_xram = DPTR; // save the DPTR
// DPTR = pt_code;
DPTR = add_code;
AUXR1++;
MAP_BOOT;
__API_FLASH_ENTRY_POINT();
UNMAP_BOOT;
AUXR1++;
DPTR = add_xram; // restore the DPTR
AUXR1++;
EA = ea_save; // restore interrupt state
return(api_value);
}
#endif
/*F**************************************************************************
* NAME: __api_wr_fuse
*----------------------------------------------------------------------------
* PARAMS:
*----------------------------------------------------------------------------
* PURPOSE:
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
Uchar __api_wr_fuse (Uchar mask, Uchar filter)
{
Uchar value;
bit ea_save;
ea_save = EA;
EA = 0;
value = __api_rd_HSB();
value &= ~mask;
api_value = value | filter;
api_command = _COMMAND_WR_FUSE_BIT;
MAP_BOOT;
__API_FLASH_ENTRY_POINT();
UNMAP_BOOT;
EA = ea_save; // restore interrupt state
return(1);
}
/*F**************************************************************************
* NAME: api_erase_block
*----------------------------------------------------------------------------
* PARAMS:
* block_t num_block
* num_block = BLOCK_0 (erase Flash between 0x0000-0x1FFF)
* num_block = BLOCK_1 (erase Flash between 0x2000-0x3FFF)
* num_block = BLOCK_2 (erase Flash between 0x3000-0x7FFF)
* num_block = BLOCK_3 (erase Flash between 0x8000-0xBFFF)
* num_block = BLOCK_4 (erase Flash between 0xC000-0xFFFF)
* return:
*----------------------------------------------------------------------------
* PURPOSE:
* This function allows to erase Block in Flash.
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
* To use this function the constante __API_ERASE_BLOCK must be define in
* C header file flash_api.h.
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
#ifdef __API_ERASE_BLOCK
Uchar __api_erase_block (block_t num_block)
{
bit ea_save;
ea_save = EA;
EA = 0;
api_command = _COMMAND_ER_BLOCK;
api_dph = num_block;
MAP_BOOT;
__API_FLASH_ENTRY_POINT();
UNMAP_BOOT;
EA = ea_save; // restore interrupt state
return(1);
}
#endif
/*F**************************************************************************
* NAME: api_eeprom_busy
*----------------------------------------------------------------------------
* PARAMS:
* return:
* eeprom_t eep :
* eep = EEPROM_NOT_BUSY
* eep = EEPROM_BUSY
*----------------------------------------------------------------------------
* PURPOSE:
* This function allows to check if eeprom is busy or not.
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
* To use this function the constante __API_EEPROM_BUSY must be define in
* C header file flash_api.h.
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
#ifdef __API_EEPROM_BUSY
eeprom_t __api_eeprom_busy (void)
{
return(EECON & 0x01);
}
#endif
/*F**************************************************************************
* NAME: api_rd_eeprom
*----------------------------------------------------------------------------
* PARAMS:
* Uchar xdata *address : address to read
* return:
*----------------------------------------------------------------------------
* PURPOSE:
* This function allows to read a byte in Eeprom.
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
* To use this function the constante __API_RD_EEPROM must be define in
* C header file flash_api.h.
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
#ifdef __API_RD_EEPROM_BYTE
Uchar __api_rd_eeprom_byte(Uchar xdata *address)
{
Uchar val;
EECON = 0x02;
val = *address;
EECON = 0x00;
return (val);
}
#endif
/*F**************************************************************************
* NAME: api_wr_eeprom_byte
*----------------------------------------------------------------------------
* PARAMS:
* Uchar xdata* address : address to read
* Uchar value : data to write
* return:
*----------------------------------------------------------------------------
* PURPOSE:
* This function allows to program a byte in Eeprom.
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
* To use this function the constante __API_WR_EEPROM_BYTE must be define in
* C header file flash_api.h.
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
#ifdef __API_WR_EEPROM_BYTE
Uchar __api_wr_eeprom_byte (Uchar xdata *address, Uchar value)
{
bit ea_save;
ea_save = EA;
EA = 0;
EECON = 0x02;
*address = value;/* addr is a pointer to external data mem */
EECON = 0x50;
EECON = 0xA0;
EA = ea_save;
return (1);
}
#endif
/*F**************************************************************************
* NAME: api_start_isp
*----------------------------------------------------------------------------
* PARAMS:
* return:
*----------------------------------------------------------------------------
* PURPOSE:
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
* To use this function the constante __API_START_ISP must be define in
* C header file flash_api.h.
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
#ifdef __API_START_ISP
void __api_start_isp (void)
{
EA = 0;
MAP_BOOT;
__API_JMP_ISP_START();
}
#endif
/*F**************************************************************************
* NAME: api_start_bootloader
*----------------------------------------------------------------------------
* PARAMS:
* return:
*----------------------------------------------------------------------------
* PURPOSE:
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
* To use this function the constante __API_START_BOOTLOADER must be define in
* C header file flash_api.h.
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
#ifdef __API_START_BOOTLOADER
void __api_start_bootloader (void)
{
EA = 0;
MAP_BOOT;
__API_JMP_BOOTLOADER();
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -