immediately
} //The CPU waits for the IAP to complete before continuing to execute
the program.
_nop_();
_nop_();
_nop_();
DisableEEPROM();
EA = 1; //re-enable interrupt
}
PassWord = 0; //Clear password
}
//========================================================================
// Function: void EEPROM_write_n(u16 EE_address,u8 *DataAddress,u16 number)
// Description: Write the buffered n bytes into the EEPROM of the specified first address.
// Parameters:EE_address: Write the first address of the EEPROM.
// DataAddress: The first address of the buffer where the source data is written.
// number: The length of bytes written.
// Return: non.
// Version: V1.0, 2012-10-22
//========================================================================
void EEPROM_write_n(u16 EE_address,u8 *DataAddress,u16 number)
{
if(PassWord == D_PASSWORD) // Only the password is correct, the EEPROM will be operated
{
EA = 0; //Disable interrupts
ISP_CONTR = ISP_EN; //Allow ISP/IAP operation
IAP_TPS = (u8)(MAIN_Fosc / 1000000L); //Working frequency setting
ISP_WRITE(); //Send byte write command. When the command does not need to be
changed, 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
ISP_DATA = *DataAddress; //Send data to ISP_DATA, and only need to send it again when the data
changes.
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_();
EE_address++;
DataAddress++;
}while(--number);
DisableEEPROM();
EA = 1; //re-enable interrupt
}
PassWord = 0; // Clear password