SCM programming software is a common topic. In previous articles, the editor mainly explained the tutorial of IAR SCM programming software. This time, we will bring the Keil MCU programming software tutorial, the main content is the C51 variable method in the Keil MCU programming software, so as to help you better master the Keil MCU programming software.

SCM programming software is a common topic. In previous articles, the editor mainly explained the tutorial of IAR SCM programming software. This time, we will bring the Keil MCU programming software tutorial, the main content is the C51 variable method in the Keil MCU programming software, so as to help you better master the Keil MCU programming software.

The 8051 core single-chip microcomputer is a general-purpose single-chip computer, which occupies a large market share in China. In the research of using C language for 51 core microcontrollers, Keil has done the most successful. Due to the particularity of the storage structure of the 51-core microcontroller, the use of variables in Keil C51 is different from that of standard C. Correct use of variables is conducive to obtaining efficient object code. The following describes the use of variables in Keil C51 in detail.

First, the relationship between CPU storage structure and variables

Variables all need storage space, and the difference in storage space makes the work efficiency of variables different.

The typical operating environment of standard C is the 8086 (including IA-32 series) kernel, and its storage structure is that there are registers inside the CPU and memory outside, and the access speed of the registers is much higher than the access speed of the memory. In standard C, variables that are not specially defined are placed in memory. Using register can force variables to be stored in registers. This storage mode can be selected for variables that are used very frequently and in small numbers to obtain higher work efficiency.

In contrast, the storage structure of the 51-core microcontroller is a bit weird. It has three storage spaces: program memory space (64 KB including on-chip and off-chip), off-chip data memory space (64KB), on-chip data memory and special function register space. It does not have a register in the real sense, and its registers are actually part of the on-chip data memory (such as R0~R7) and special function registers (such as A, B, etc.). Therefore, using variables in Keil C51 is very different from standard C.

Second, Keil C51 variable analysis

Keil C51 supports most of the original variable types of standard C, but adds a variety of storage types for these variables, and also adds some variables that standard C does not have.

2.1 The new variable storage type of Keil C51

The format for defining variables in Keil C51 is as follows:

[存储种类]type of data[存储类型]variable name table;

in,[存储类型]is not in standard C,[存储类型]There are a total of 6 types, which are described as follows:

①data. Store variables in on-chip directly addressable data memory. Using this storage mode, access to variables in object code is fastest.

②bdata. Store variables in on-chip bit-addressable data memory. Variables can be easily bit-processed in object code, the same as data when not bit-processed.

③ idata. Store variables in on-chip indirect addressing data memory. In the 52 core, when the on-chip direct addressing data memory is not enough, the 128-byte indirect addressing data memory can be used. The access speed is generally slower than data, but it has the largest on-chip data memory space; in the 51 core Since there is no separate indirect addressing data memory area, idata is indistinguishable from data.

④xdata. Store variables in off-chip data memory. Only “MOVX A, @DPTR” and “[email protected]

"SCM programming software is a common topic. In previous articles, the…