The "Soul" of the Microcontroller - The Use of Data Memory

Publisher:逍遥游侠Latest update time:2015-01-20 Keywords:Memory Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
We can say that the program memory stores the soul of the microcontroller, which is the working program. The smallest one may be only 1KB (it can only hold 1024 8-bit data at most, because there are many 2-byte and 3-byte instructions in the actual instructions, so it cannot hold 1024 instructions) and the largest one may be 128KB. These 8-bit data are either photolithographed in the factory, or burned in at one time, or... use a special tool called a programmer to load the successfully debugged machine code into it, or spend a few dollars to make a download cable like the AVR microcontroller and load these things from the computer into it (perhaps the most attractive feature of AVR). Once it enters the computer's program memory, it cannot be freely rewritten except with the help of the above-mentioned device. When the microcontroller is running, it only reads instructions or fixed data from it, so the program memory is given an alias of "read-only memory", abbreviated as ROM, including EPROM that uses a programmer to write ultraviolet erase content, electrically erased EEPROM and the emerging FLASH ROM; ROM that is written once is only used in batch products with fixed circuits and programs, and they are all the same in actual work.

In actual use, in order to locate the data in the ROM when the microcontroller is running, each 8-bit storage unit actually has a fixed "address", usually expressed in hexadecimal: for example, for a so-called 4K ROM, the address is from 0000H to 0FFFH (that is, from 0000, 0001...4095). The address from which the microcontroller takes data when it is running is completely determined by the program itself, and we do not need to intervene. Remember, when the microcontroller is powered on, it goes through a short reset process and immediately turns to the lowest address 0000H of the ROM. There is often a "jump" instruction placed in it, which jumps from here to another address in one step: the real starting address of the program, such as 0080H for a 51 machine. Is there only instructions in the ROM and nothing else? ROM is a program memory, which includes certain fixed data required to run the program in addition to instructions. Suppose, we want to output a value from 00H to FFH (255) that changes according to a half-sine wave at a certain port of the microcontroller, 10,000 times per second. If we force it to calculate one by one according to the formula, it will be beyond its ability. However, we can store the pre-calculated values ​​in ROM and retrieve them directly when the time comes.

When it comes to data storage, it is actually a piece of storage that can access data at any time, that is, a storage that can be read (accessed) or written (stored), referred to as RAM. The RAM used in the current single-chip microcomputer belongs to static RAM or SRAM, which is different from the memory stick used in computers. As long as you write data into SRAM, as long as the power is not turned off or it is not cleared, the data will be kept there. Computers use dynamic RAM, which needs to be refreshed continuously to save data. Because the amount of information processed by the single-chip microcomputer is much smaller than that of the computer, it has less RAM: from no, 128, 256, ... 1K, 2K to 4K, much less than ROM. Because in fact, RAM is only used as a temporary storage place for data, unless image processing requires the storage of a large amount of data, generally for single-chip microcomputers that perform simpler tasks, so much is enough. If it is really not enough, it can only be expanded by adding external SRAM such as 6116, 6264, etc. In order to access 8-bit binary numbers in RAM units, of course, the specific location is marked with "address" like ROM. If a single-chip microcomputer has 1K (1024) RAM, its address is also from 0000 to 1024, or 0000H to 03FFH in hexadecimal. It can be seen that the address is the same as the ROM address. Will it be confused? No, because reading ROM is performed by the program pointer or transfer instruction or table lookup instruction of the single-chip microcomputer, and these instructions will not enter the RAM area. Reading and writing RAM is another data transfer instruction, and it will not enter the ROM area. This is also different from the computer. The latter program and data are in the memory bar, with different addresses. If the position is moved, it will cause unpredictable consequences. This memory structure of the single-chip microcomputer is also called Harvard structure.

The RAM mentioned in this article is mainly used to store temporary data in the microcontroller. For example, when measuring temperature with a microcontroller, it measures once per second and displays the average value of one minute (updated once per minute). First, we use sensors, amplifier circuits, and A/D conversion to convert the analog temperature into a proportional binary number. Then, we store the digital values ​​in the RAM of the microcontroller through the input port once per second. Then, we sum and average them in pairs (off topic: it is troublesome for the microcontroller to perform "division" operations. The exception is division by 2, 4, 8... which is very simple. Just use the "right shift" instruction 1, 2, or 3 times). The final value is displayed, and then all 60 storage units are written with 0 to clear the old data, and the cycle will be repeated again next time. In addition, there are several registers in the microcontroller. The number is small but the functions are very important. In addition to temporarily storing data, they can also exchange, process, transmit, etc., as well as record the current state of the microcontroller at any time. The input and output ports also exist as registers with special functions. The specific functions are different, so you can't figure them out by just talking about them. You need to read relevant books.

Keywords:Memory Reference address:The "Soul" of the Microcontroller - The Use of Data Memory

Previous article:FPGA slave and fast loading solution based on CPLD
Next article:Two-wheeled self-balancing electric vehicle designed with ATMEGA16 microcontroller

Latest Power Management Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号