The data of the microcontroller when it is running is stored in RAM (Random Access Memory). The data in RAM cannot be retained after power failure. So
how to prevent the data from being lost after power failure? This requires the use of memory such as EEPROM or FLASHROM.
In traditional single-chip microcomputer systems, external memory is usually used for expansion, and data communication between the single-chip microcomputer and the memory is carried out through interfaces such as IIC or SPI.
This will not only increase the development cost, but also require more effort in program development. The STC microcontroller has a built-in EEPROM (actually,
the ISP/IAP technology is used to read and write the internal FLASH to implement the EEPROM), which saves external resources and is more convenient to use. The following
is a detailed introduction to the STC microcontroller's built-in EEPROM and its usage
The built-in EEPROM capacity of each type of STC microcontroller is as small as 2K and as large as 16K, which basically meets the needs of the project very well. What is more
convenient is that it saves peripheral EEPROM devices, achieving the purpose of saving costs, and the speed of the internal EEPROM is
much faster than the external EEPROM. The
built-in EEPROM of each type of STC microcontroller is based on 512 bytes as a sector. The starting address of EEPROM = FALSH capacity value + 1,
so the starting address of STC89C52RC is 0x2000, the starting address and end address of the first sector are 0x2000~0x21FF, the starting address and end address of the second sector are
0x2200~0x23FF, and so on for other sectors.
In-depth focus:
Traditional EEPROM is an electrically erasable programmable read-only memory chip that does not lose data after power failure.
The EEPROM of STC89C52RC is implemented by reading and writing internal FLASH through ISP/IAP technology.
The starting address of the EEPROM of STC89C52RC is 0x2000, with 512 bytes as a sector, and the size of EEPROM is 2K bytes.
There are 6 registers implemented by STC89C52RC and EEPORM, namely ISP_DATA, ISP_ADDRH, ISP_ADDRL
ISP_TRIG, ISP_CMD, and ISP_CONTR.
1. ISP_DATA registerISP_DATA
register: data register for ISP/IAP operation. ISP/IAP reads
data from Flash here, and writes data to Flash here. Example 1: Read single byte UINT8 EEPROMRead(UINT16 addr) { …… return ISP_DATA; } Example 2: Write single byte void EEPROMWrite(UINT8 byte) { …… ISP_DATA=byte; }
2.ISP_ADDRH, ISP_ADDRL registers
ISP_ADDRH: The high eight bits of the address register during ISP/IAP operation
ISP_ADDRL: The low eight bits of the address register during ISP/IAP operation
Example 1: Set the address
void EEPROMSetAddress(UINT16 Addr)
{
……
ISP_ADDRH=(UINT8)(Addr>>8);
ISP_ADDRL=(UINT8) Addr;
}
3.ISP_CMD Register
ISP_CMD: Command mode register for ISP/IAP operation, which needs to be triggered by ISP_TRIG command to take effect.
4.ISP_TRIG register
ISP/IAP command must be triggered by ISP_TRIG command trigger register to take effect, that is, the command set by ISP_CMD must take effect.
The triggering process is very special. You only need to assign values to the ISP_TRIG register twice in a row. First write
0x46 to the ISP_TRIG register, and then write 0xB9 to complete the command triggering process.
Example 1: Command trigger
void EEPROMCmdTrig (void)
{
……
ISP_TRIG = 0x46;
ISP_TRIG = 0xB9;
}
5.ISP_CONTR register
ISP_CONTR: ISP/IAP control register
ISPEN: ISP/IAP function enable bit. 0: Disable ISP/IAP programming to change Flash.
SWBS: 0: Software selects to start from the user main program area 1: ISP program area starts
SWRST: 0: No operation 1: Generate software system reset, hardware automatically clears
WT2, WT1, WT0: Set waiting time
Assuming the operating frequency of STC89C52RC is 12MHz, the machine cycle is 1us. Referring to Table 12-, the time required for reading a single
byte is roughly as follows:
Reading a single byte: 11*1us=11us
Writing a single byte: 60*1us=60us
Sector erasing: 10942*1us=10.942ms
Regardless of the operating frequency of the microcontroller, the time required for the EEPROM read, write, and erase operations is approximately 10us, 60us, and
10ms, respectively.
In-depth focus:
There are 6 registers implemented by STC89C52RC and EEPORM, namely ISP_DATA, ISP_ADDRH,
ISP_ADDRL ISP_TRIG, ISP_CMD, and ISP_CONTR.
The command trigger of EEPROM must first write 0x46 to the ISP_TRIG register, and then write 0xB9.
Regardless of the operating frequency of the microcontroller, the time required for the read, write, and erase operations of EEPROM is
approximately 10us, 60us, and 10ms, respectively. Therefore, the waiting time must be set for ISP_CONTR, otherwise the data is prone to problems.
Previous article:STC12C5A16S2 internal Flash read and write
Next article:Using HyperTerminal to Realize Communication Between MCU and Computer
Recommended ReadingLatest update time:2024-11-16 18:01
- Popular Resources
- Popular amplifiers
- Wireless Sensor Network Technology and Applications (Edited by Mou Si, Yin Hong, and Su Xing)
- Modern Electronic Technology Training Course (Edited by Yao Youfeng)
- Modern arc welding power supply and its control
- Small AC Servo Motor Control Circuit Design (by Masaru Ishijima; translated by Xue Liang and Zhu Jianjun, by Masaru Ishijima, Xue Liang, and Zhu Jianjun)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- 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
- [RISC-V MCU CH32V103 Review] 5. Real breathing light
- Stamp holes for CircuitBrains boards
- Reliability and energy efficiency test design of LED driver power supply
- RISC-V MCU Development (Part 9): Project Template Management
- Anlu SparkRoad Development Board Unboxing Review
- Full Analysis of Air Conditioning Automatic Control System
- Overview of Phase-Locked Loops and Their Applications
- Pre-register to win a JD card! The most extensive optical sensing solution portfolio on the market - ams-osram optical technology forum
- 【RT-Thread Reading Notes】12. RT-Thread Study Chapters 21-23 Reading Notes
- Negative high voltage chip solution