Application of Ram Extension in Single Chip Microcomputer

Source: Internet
Author: User

Ram is the data space used to store random variables in the program running. The default internal RAM of 51 single-chip microcomputer is only 128 bytes, and the number of 52 single-chip microcomputer is increased to 256 bytes, and the number of 52 single-chip microcomputer is increased to 512 bytes, for programmers, the more ram a chip has, the easier it is to write programs, I don't always think that Ram is not enough, but I am worried that too many variables cannot be defined.
As we mentioned before when writing a program, if a variable is not initialized after it is defined, the default initial value of the variable is 0. In fact, this conclusion requires certain conditions, when you write a program using Keil, the sum of the bytes occupied by all variables in the program is less than 128 bytes, and the memory mode is small mode. If you do not initialize the Defined variables, the compiler sets the variable value to 0 by default. Once the total variable in the program exceeds 128 bytes, all variables must be initialized. Otherwise, the default value of the variable not initialized will be uncertain. When the total number of variables exceeds 128 bytes, you must reset the storage mode in the compiler. There are three storage modes: small, compact, and large, you can select options in the Keil compiler, as shown in table 4.4.1. It determines the default storage region where data such as variables and function parameters of the storage type are not explicitly specified. If you need to use a non-default storage mode in some functions, you can also directly describe using the word "Guan. The following describes the three modes.
1. Small Mode
In small mode, all default variable parameters are loaded into the 128-byte RAM of the microcontroller. When variables such as uchar A and float B are defined, these variables are loaded into the internal 128-byte RAM. The advantage of this mode is that the access speed is fast, and the disadvantage is that the space is limited. In addition, the space allocated to the stack is relatively small and difficult to grasp. Be careful when calling the stack recursively. Therefore, this mode applies only to small programs.
2. Compact Mode
In compact mode, all the default variables are in the 256-byte RAM of the microcontroller, which is the same as the variables defined by using the pdata in small mode. For example, uchar pdata A [100]; in this mode, the total program variables cannot exceed 256 bytes. For single-chip microcomputer with only 128 bytes, when this mode is used to define variables greater than 128 bytes, the program will fail. The advantage is that the space is wider than the small mode, and the speed is slower than the small mode, but it is faster than the large mode, which is an intermediate state.
3. Large Mode
In large mode, all default variables can be placed in a ram zone of up to 64 KB, including internal RAM and external Ram, which have the same effect as the variables defined using the xdata. The advantage of this mode is that there is a large space and many variables can be stored. The disadvantage is that the access speed is slow, especially for the access speed of more than two multibyte variables.
For convenience, to access extended RAM, the STC microcontroller can directly use the following method: first, set the memory mode to large mode in the compiler.
Secondly, for the sake of security, when other variables with more than 128 bytes are defined in the program, it is best to declare them as xdata type, such as uchar xdata table [100]; defines an array of 100 bytes and allocates storage space in the extended RAM. In large mode, when writing a program, the total number of variables defined must not exceed the maximum internal RAM bytes of the corresponding single-chip microcomputer, the compiler will not prompt an error, but the program will surely make an error.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.