ISP_CONTR = ISP_EN; //Allow ISP/IAP operation
IAP_TPS = (u8)(MAIN_Fosc / 1000000L); //Working frequency setting
ISP_READ(); //Send byte read command, when the command does not need to be
changed, there is no need to send the command again
do
{
ISP_ADDRH = EE_address / 256; //Send the high byte of the address (the address needs to be re-sent when
the address needs to be changed)
ISP_ADDRL = EE_address % 256; //Send the low byte of the address
if(PassWord == D_PASSWORD) // If the password is correct, trigger the operation
{
ISP_TRIG = 0x5A; //Send 5AH firstly, then send A5H to the ISP/IAP trigger register,
//Do this every time
ISP_TRIG = 0xA5; //After sending A5H, the ISP/IAP command is triggered to start
immediately
} //The CPU waits for the IAP to complete before continuing to execute
the program.
_nop_();
_nop_();
_nop_();
*DataAddress = ISP_DATA; //Data be read
EE_address++;
DataAddress++;
}while(--number);
DisableEEPROM();
EA = 1; //re-enable interrupt
}
PassWord = 0; //clear password
}
/******************** Sector Erase Function *****************/
//========================================================================
// Function: void EEPROM_SectorErase(u16 EE_address)
// Description: Erase the EEPROM sector at the specified address.
// Parameters:EE_address: The address of the sector EEPROM to be erased.
// Return: non.
// Version: V1.0, 2013-5-10
//========================================================================
void EEPROM_SectorErase(u16 EE_address)
{
if(PassWord == D_PASSWORD) // Only the password is correct, the EEPROM will be operated
{
EA = 0; //Disable interrupts
//Only sector erase, no byte erase, 512 bytes per sector.
//Any byte address in a sector is sector address.
ISP_ADDRH = EE_address / 256; //Send the high byte of the sector address (the address needs to be re-sent
when the address needs to be changed)
ISP_ADDRL = EE_address % 256; //Send the low byte of the sector address
ISP_CONTR = ISP_EN; //Allow ISP/IAP operation
IAP_TPS = (u8)(MAIN_Fosc / 1000000L); //Working frequency setting
ISP_ERASE(); //Send sector erase command. When the command does not need to be
changed, it is not necessary to send the command again
if(PassWord == D_PASSWORD) // If the password is correct, trigger the operation
{
ISP_TRIG = 0x5A; //Send 5AH firstly, then send A5H to the ISP/IAP trigger register,
//Do this every time
ISP_TRIG = 0xA5; //After sending A5H, the ISP/IAP command is triggered to start