//************************************************ ****************
// STC MCU EEPROM reading and writing--the simplest one, just use it and it will work. ^_^ Simplicity comes first!
//------------------------------------------------ ----------------
//--------------------------------//------------- ------------------
//Note: The following are the addresses of the STC89 series
//--------------------------------//------------- ------------------
sfr isp_data = 0xe2; //Data register for ISP/IAP operation
sfr isp_addrh = 0xe3; //high address
sfr isp_addrl = 0xe4; //low address
sfr isp_cmd = 0xe5; // Command mode register
sfr isp_trig = 0xe6; // Command trigger register
sfr isp_contr = 0xe7; //ISP/IAP control register
*/
/*
//--------------------------------//------------- ------------------
//Note: The following is the address of the 1T new STC series
//--------------------------------//------------- ------------------
sfr isp_data = 0xc2; //Data register for ISP/IAP operation
sfr isp_addrh = 0xc3; //high address
sfr isp_addrl = 0xc4; //low address
sfr isp_cmd = 0xc5; // Command mode register
sfr isp_trig = 0xc6; // Command trigger register
sfr isp_contr = 0xc7; //ISP_IAP control register
//------------------------------------------------ ----------------
uchar eeprom_read(uint addres);//
void eeprom_write(uint address,uchar wdata);//
void eeprom_eares(uint addres); // sector erase
//************************************************ ****************
// sector erase
//------------------------------------------------ ----------------
void eeprom_eares(uint addres)
{
uchar i;
isp_addrl=addres; //low address
isp_addrh=addres>>8; //high address
isp_contr=0x01;
isp_contr=isp_contr|0x80; //Set time and charge ISP operation.
isp_cmd=0x03; //sector command
isp_trig=0x46; //trigger
isp_trig=0xb9; //Trigger start.
for(i=0;i<3;i++)
;
isp_addrl=0xff;
isp_addrh=0xff;
isp_contr=0x00;
isp_cmd=0x00;
isp_trig=0x00;
}
//************************************************ ****************
// Read data
//------------------------------------------------ ----------------
unsigned char eeprom_read(unsigned int addres)
{
unsigned char i,z;
isp_addrl=addres; //low address
isp_addrh=addres>>8; //high address
isp_contr=0x01;
isp_contr=isp_contr|0x80; //Set time and charge ISP operation.
isp_cmd=0x01; //write command
isp_trig=0x46; //trigger
isp_trig=0xb9; //Trigger start.
for(i=0;i<3;i++)
;
isp_addrl=0xff;
isp_addrh=0xff;
isp_contr=0x00;
isp_cmd=0x00;
isp_trig=0x00;
z=isp_data;
return(z);
}
//************************************************ ****************
// Write data
//------------------------------------------------ ----------------
void eeprom_write(unsigned int addres,unsigned char write_data)
{
unsigned char i;
isp_data=write_data; //Data to be written.
isp_addrl=addres; //low address
isp_addrh=addres>>8; //high address
isp_contr=0x01;
isp_contr=isp_contr|0x80; //Set time and charge ISP operation.
isp_cmd=0x02; //write command
isp_trig=0x46; //trigger
isp_trig=0xb9; //Trigger start.
for(i=0;i<3;i++)
;
isp_addrl=0xff;
isp_addrh=0xff;
isp_contr=0x00;
isp_cmd=0x00;
isp_trig=0x00;
}
Previous article:Application of SD card in microcontroller
Next article:STC89C58 serial port receives GPS signal
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- About the test of power supply Wenbo
- [N32L43x Review] 3. Using serial port receive interrupt and idle interrupt to realize variable length data reception
- EEWORLD University Hall----Live Replay: Melexis explains the implementation and technical support of semiconductor R&D functional safety
- MSP430F149 serial RS485 interface
- Optocoupler replacement
- Working principle of photoelectric encoder
- FPGA controls TMS320C6678 power-on reset program
- Lee Kun-hee, chairman of South Korea's Samsung, has passed away. How do you evaluate his life?
- RTT & Renesas high performance CPK-RA6M4 development board review - SPI driven OLED
- 【TGF4042 signal generator】+6th issue pwm modulation