Differences between ROM, RAM and FLASH

1. ROM

       ROM (Read Only Memory) read-only memory. It is a semiconductor memory whose characteristic is that once data is stored, it cannot be changed or deleted. Usually used in electronic or computer systems that do not need to change data frequently, and the data will not disappear when the power is turned off. Solid-state semiconductor memory that can only read previously stored data. The data stored in ROM is generally written in advance before being installed into the whole machine. It can only be read out during the operation of the whole machine, and cannot be rewritten quickly and conveniently like random access memory. The data stored in ROM is stable and will not change after a power outage. Its structure is relatively simple and easy to read, so it is often used to store various fixed programs and data. Except for a few types of read-only memories (such as character generators) that can be used universally, the contents of the read-only memories required by different users are different. ROM classification:

  • PROM: Programmable one-time (ROM that cannot be modified).
  • EPROM: UV erasable programmable ROM.
  • EEPROM: Electronically Erasable Programmable ROM.

2. RAM

       RAM (Random Access Memory) random access memory. It is an internal memory that directly exchanges data with the CPU; the contents of the storage unit can be taken out or stored at will as needed, and the access speed has nothing to do with the location of the storage unit. This kind of memory will lose its storage content when the power is turned off, so it is mainly used to store programs that are used for a short period of time. The biggest feature of RAM is that the storage and reading speed is very fast, which is much higher than that of ROM. When the CPU (Central Processing Unit) executes a program, it needs to first transfer instructions and data into RAM to ensure calculation speed. RAM classification:

  • SRAM: Static RAM. SRAM is very fast and can save data without refreshing the circuit. It is currently the fastest storage device.
  • DRAM: Dynamic RAM. DRAM retains data for a very short time and requires a memory refresh circuit to refresh and recharge it every once in a while, otherwise the data will disappear.

ROM can still retain data when the system is powered off, while RAM usually loses data after a power outage.

3. FLASH

       FLASH EEPROM , flash memory. It is a type of EEPROM. It combines the strengths of ROM and RAM. Not only does it have the performance of electronically erasable and programmable (EEPROM), it will not lose data due to power outage and can read data quickly. The biggest difference between it and EEPROM is that FLASH operates on a sector (block) basis, while EEPROM operates on a byte basis. The circuit structure of FLASH is relatively simple, the same capacity occupies a smaller chip area, and the cost is naturally lower than that of EEPROM, so it is suitable for use as program memory.

4. Calculation of microcontroller program size

       The FLASH of the microcontroller is either 4K or 8K. After the microcontroller program is written and compiled, a hex file is generated. This hex file is the file to be downloaded to the microcontroller. The size of this file cannot exceed the FLASH size of the microcontroller, otherwise the program must be optimized. Or choose a microcontroller with larger FLASH.
Insert image description here

       The size of the hex file is not the actual size of the FLASH space occupied by the microcontroller program. After the compilation is successful using the compilation tool, there will usually be a prompt.

1、Wedge/MDK

       After successfully compiling the microcontroller program through Keil, the following prompt will appear:
Insert image description here

  • Code: Indicates the code to be executed and all functions in the program.
  • RO-data: (Read Only Data) represents read-only data, global constant data defined in the program.
  • RW-data: (Read And Write Data) represents initialized read and write data, global variables and static variables defined and initialized in the program.
  • ZI-data: (Zero Initial Data) represents read-write data that is defined but not initialized, global variables and static variables that are defined but not initialized in the program (variables used in the program and initialized to 0 by the system, The Keil compiler defaults to assigning a value of 0 to all uninitialized variables, and these variables are stored in RAM when the program is running).

It can be seen from the above description:

  • The program downloaded to the microcontroller FLASH is: Code + RO-data + RW-data
  • The data running in RAM is: RW-data + ZI-data

Guess you like

Origin blog.csdn.net/hezhanran/article/details/130601225