Here is some of the misunderstandings and precautions to learn C51. The special application of the master is not included.
1) C is absolutely positioning.
Often see beginners asked to use _AT_, this is a fallacy, and the C is treated as ASM. The positioning of variables in C is the matter of the compiler, and beginners will only define variables and variables.
With the domain, the compiler gives a fixed address to this variable. How to get the address of this variable? To use a pointer. For example, Unsigned Char Data X; after the address is & X,
You only need to view this parameter, you can know the specific address in the program. So I saw a person who used absolute positioning, the first impression is: this is probably an initiator.
2) Set the problem of SP. The causes and 1 difference is not pair, the compiler will automatically start the last byte where the last byte is started, so the beginner is unnecessary to pay for the beginning of the SP. This reflects the superiority of C, many things C compile time.
3) Use C main program structure: #include
Void main (void) {while (1);
This is a minimal successful C program, including header files and program mains. The noun explanation of the header: Reference external resource files, this file includes a description of the functions and variables available for hardware information and external modules. You can open REG52.h with text, and you will have some experience of writing procedures.
4) This constitutes a C project in C, commonly used projects. The project is generally divided into two blocks: C file block and head file block. We often write different functions in different C files, rely on the management of the project, and finally connect all files, so you can get the HEX file or bin file that can be burned. In these C files, there is only the only C file that includes main () functions, and 3). Use the header to connect each different C to each other. A C file basically has a H header file, this H file contains the variables and functions that can be provided outside this C file, and the files listed in the h file can be regarded inside the C file. Functions and variables, external C cannot be used. Example: a.c:
UNSIGNED Char i; unsigned char mWork;
Void Test1 (void) {MWORK ;}
Void test2 (void) {i ;}
A.h file: extern unsigned char i; extern void test1 (void); this main program M.C: #include
#include "a.h" / * Custom H file, generally "" * /
Void main (void) {test1 (); / * Using a function * / while (1) {i ; / * using A.C module file * /}}
5) 51 The core is based on 8031, there are many of this core, and some put the program memory internally: 89c (s) 51.. Some increase RAM: 89C (s) 52 .. Some add some special hardware 80c552 ..., some change clock timing W77E58 .... The main use of Atmel's AT89X series, PHILIPS P87 (89) X, Taiwan W77 (78) X series, Cygnal's C8051FX series.
6) 51 C Description of the Single Chip Microcomputer The specific structure of 51 is not shown, just guiding the initiator to quickly understand the physical structure of the 51 single-chip microcomputer. The address name of the register and IO and other hardware devices can be found in the corresponding C header file. 51 is REG51.H, 52 is REG52.H, with secondary push, such as WinBond's 78E58 description in W78E58.h these H files: SRF, define an 8-bit device. SRF16 defines a 16-bit device. SBIT, define a bit of the device. After defining these statements, you can use these hardware devices as compilation in C-image, which is a single-chip application than standard C special places, and there are few different differences. 7) Data, IDATA, XDATA, PDATA in the 51 series DATA: fixed refers to 128 RAMs of 0x00-0x7f, can be read or written directly with ACC, the fastest speed, and the generated code is also minimized. IDATA: Fixed 256 RAMs in front of 0x00-0xFF, where the first 128 and DATA 128 are identical, but because of the way to access. iDATA is accessible with a pointer in similar C. The statement in the assembly is: Mox ACC, @ RX. (Not important addition: IDATA is very good access to the pointer)
XDATA: External extension RAM, generally refers to external 0x0000-0xffff, with DPTR access. PDATA: The external extension RAM is 256 bytes, and the address is read and written at the A0-A7, and writes and writes with Movx ACC, @ rx. This is special, and C51 seems to have this bug, it is recommended to use less. But there is also his advantage, and the specific usage is intermediate, not mentioned here.
8) STARTUP.A51 The role and assembly, the initialization of the variables and arrays defined in C is performed in Startup.a51, if you define a global variable, there is a value, such as unsigned charData XXX = 100; There will be related assignments in Startup.a51. If there is no = 100, Startup.a51 will clear him 0. (Startup.a51 == Initialization of variable). These initialization will also set the SP pointer. For non-variable regions, such as a stack area, will not be assigned or clear. Some people like to change Startup.a51, in order to meet some of them think about it, this is unnecessary, it is possible wrong. For example, when power-down protection, you want to save some variables, but change Startup.a51 to achieve a very stupid method, actually use the characteristics of the non-variable area to define a pointer variable to point the stack lower: 0xFF can be implemented. Why do you want to change? Can you say: You can don't need to change Startup.a51 at any time, if you understand its characteristics