Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - Recently, eeprom was used in stc single chip microcomputer, hoping to save the changed data in eeprom during the operation of single chip microcomputer, and then call it from it when it is turned on n
Recently, eeprom was used in stc single chip microcomputer, hoping to save the changed data in eeprom during the operation of single chip microcomputer, and then call it from it when it is turned on n
Recently, eeprom was used in stc single chip microcomputer, hoping to save the changed data in eeprom during the operation of single chip microcomputer, and then call it from it when it is turned on next time. # include & ltreg52.h & gt

# include & ltintrins.h & gt

/* The following registers are used to configure the STC microcontroller */

/* Relevant information starts from page 35 of STC89C5 1RC PDF */

sfr ISP _ DATA = 0xE2

sfr ISP _ ADDRH = 0xE3

sfr ISP _ ADDRL = 0xE4

sfr ISP _ CMD = 0xE5

sfr ISP _ TRIG = 0xE6

sfr ISP _ CONTR = 0xE7

# Define uint unsigned integer

# Define uchar unsigned characters

# Define ISP _ byte _ read1/ISP byte reading.

# Define ISP _ byte _ program2//ISP direct programming

# Define ISP _ sector _ erase3//ISP Sector Erase

Uchar code table [10] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f };;

/********************************************************************

* Name: Delay ()

* function: delay, the delay time is 10ms * del.

* input: del

* Output: None

***********************************************************************/

Invalid delay _ 1 ms (uint i)

{

uchar x,j;

for(j = 0; J< me; j++)

for(x = 0; x & lt= 148; x++);

}

/********************************************************************

* Name: ISP_ERASE ()

* Function: Erase EEPROM sector.

* Input: Address (address of erased sector)

* Output: None

***********************************************************************/

Void ISP_ERASE (address)

{

ISP_ADDRL = address;

ISP _ ADDRH = Address & gt& gt8;

ISP _ CONTR = 0x 8 1;

ISP _ CMD = ISP _ SECTOR _ ERASE

ISP_TRIG = 0x46//The PDF manual says to write 0x46 in ISP _ trig first, and then 0xb9.

ISP _ TRIG = 0xb9

_ nop _();

_ nop _();

}

/********************************************************************

* Name: ISP_READ ()

* Function: Read the value from the corresponding address of EEPROM.

* input: address (address to read EEPROM)

* output: Read_Data (value read from EEPROM)

*********************************************************************/

Uint ISP_READ (address)

{

uchar Read _ Data

ISP_ADDRL = address;

ISP _ ADDRH = Address & gt& gt8;

EA = 0;

ISP _ CONTR = 0x 8 1;

ISP _ CMD = ISP _ BYTE _ READ

ISP _ TRIG = 0x46

ISP _ TRIG = 0xb9

_ nop _();

_ nop _();

Read _ Data = ISP _ DATA

Return Read _ Data

}

/********************************************************************

* Name: ISP_PROGRAM ()

* Function: realize byte programming of EEPROM.

* Input: Address is the programmed address, and Data_temp is the value to be programmed.

* Output: None

***********************************************************************/

Void ISP_PROGRAM (address, data _ temporary)

{

ISP _ DATA = Data _ temp

ISP_ADDRL = address;

ISP _ ADDRH = Address & gt& gt8;

ISP _ CONTR = 0x 8 1;

ISP _ CMD = ISP _ BYTE _ PROGRAM

ISP _ TRIG = 0x46

ISP _ TRIG = 0xb9

_ nop _();

_ nop _();

}

/********************************************************************

* Name: Main ()

* Function: Main function

* Input: None

* Output: None

***********************************************************************/

void Main()

{

uint I;

uchar LED _ Buffer = 0;

while( 1)

{

for(I = 0; I & lt50; i++)

{

LED _ Buffer = ISP _ READ(0x2c 00);

P0 = table[LED _ Buffer % 10];

P2 = 1;

delay _ 1 ms(6);

P0 = table[LED _ Buffer/ 10% 10];

P2 = 0;

delay _ 1 ms(6);

}

LED _ buffer++;

ISP _ ERASE(0x2c 00); //Note: The whole sector must be erased before byte programming.

ISP_PROGRAM(0x2c00,LED _ Buffer);

}

}