EasyManua.ls Logo

STC micro STC8A8K64D4 Series - Page 486

Default Icon
901 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
STC8A8K64D4 Series Manual
- 470 -
C language code (EEPROM.c)
//Operating frequency for test is 11.0592MHz
// This program is the built-in EEPROM read and write program of STC series.
#include "config.h"
#include "eeprom.h"
//========================================================================
// Function: void ISP_Disable(void)
// Description: Disable access ISP/IAP.
// Parameters:non.
// Return: non.
// Version: V1.0, 2012-10-22
//========================================================================
void DisableEEPROM(void)
{
ISP_CONTR = 0; //Disable ISP/IAP operation
IAP_TPS = 0;
ISP_CMD = 0; //Remove ISP/IAP commands
ISP_TRIG = 0; //Prevent false triggering of ISP/IAP commands
ISP_ADDRH = 0xff; //Clear address high byte
ISP_ADDRL = 0xff; //Clear address low byte, point to non-EEPROM area to prevent
misoperation
}
//========================================================================
// Function: void EEPROM_read_n(u16 EE_address,u8 *DataAddress,u16 number)
// Description: Read n bytes from the specified EEPROM first address and put them in the specified buffer.
// Parameters:EE_address: The first address of the EEPROM to read.
// DataAddress: The first address of the data buffer.
// number: The length of bytes to read.
// Return: non.
// Version: V1.0, 2012-10-22
//========================================================================
void EEPROM_read_n(u16 EE_address,u8 *DataAddress,u16 number)
{
EA = 0; //Disable interrupts
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
ISP_TRIG(); //Send 5AH firstly, then send A5H to the ISP/IAP trigger register,
//Do this every time
//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_();

Table of Contents

Related product manuals