1. Configuration problem: Is the configuration word of the microcontroller in the actual burn-in the same as in the simulation? Is the configuration correct during burn-in?
Second, the problem of resources: the size of the ROM and RAM of the microcontroller is different from the size of the ROM and RAM of the emulator!
Third, the problem of driving ability: usually the driving ability of the emulator is stronger than that of the single-chip microcomputer; it can be checked in two steps, one is to compare the corresponding IO port waveforms when the emulator and the single-chip microcomputer are used, and the other is when the emulator and peripherals are connected or not. Time waveform comparison;
Basic element analysis should be carried out: Is the power supply of the single-chip microcomputer normal? Does the start-up vibrate? The reset circuit is normal? The chip is damaged?
[Analysis of the situation that the single-chip microcomputer does not run when it is powered on]
1. Is the microcontroller not running, or is it running incorrectly?
2. If it is not running, check whether the basic parameters of the single-chip microcomputer have met .
3. If the operation is not correct, check
【Single chip debugging method】
Using LED for status indication and serial port for data indication is more reliable than other peripherals indication;
Add breakpoints. When programming, add WHILE(1) after different statements;
Sub-module debugging, debug each small function first, and then combine.
Keil C itself is a combination of compilation and simulation. It is very convenient when external data is not required. When external input is required (such as using a timer as a counter), it provides several debug input windows that can be used to simulate input. At the same time, Keil C C itself provides a debug function to configure the function of simulating external input. This is what I read in a book when I was studying. For example, using a timer to count external events, the debug function can be configured by itself in a specific format as needed. Edit and then press KEIL C requirements to transfer. This method can be used when learning, and it is best to use an emulator to debug when making a product. Below I give a debug function that I have tried to simulate external input when using a timer as external event count, and write out the steps to call Keil C as follows:
1. Write the following signal function:
single void t0_singal(void)
PORT3|=0x10;//pull INT0(P3.4) high again
PORT3&=~0x10;//pull INT0(P3.4) low and generate interrupt
PORT3|=0x10;//pull INT0(P3.4) high again
twatch(CLOCK);//wait for 1 second
2. In the DEBUG state, click the DEBUG menu and click the “Function Editor(Open Ini File)…” option in the drop-down menu. After a new screen pops up, close the “Open” window, and there is a Function Edito window on the screen;
3. Enter the above function in the Function Editor window;
4. Save (note: the extension is .ini), compile the program, and close the Function Editor window after success;
5. Execute the user program (must be executed continuously);
6. In the command window at the bottom left of the screen, after typing t0_singl() (you must press Enter), you can continuously provide pulse signals to P3.4.
Some experience we have accumulated when debugging a system with Keil C
1. Since Keil C does not support Chinese very well, the displayed cursor may be inconsistent with the actual cursor position, which will affect the modification of Chinese comments. Under Windows2000, we can set the font to Courier, so that it can be displayed normally.
2. When using an MCU with off-chip memory (such as W77E58, which has 1K off-chip memory), the flag must be set, and the compilation mode must be selected in large mode, otherwise an error will occur.
3. When using Keil C to track the running state of the program, the statement that causes the Warning should be shielded, otherwise there may be an error when tracking the statement.
4. When calling an array, Keil C first loads the array into memory. If we want to use a long array in C, we can use the code keyword, which realizes the function of the compiled DB. Keil C will not load the array marked with code into the memory, it will directly read the Rom.
5. When programming involves communication, timing is important. Pulling a pin is performed much faster than checking the pin level.
6. When waiting for the pin level to change, we need to set the timeout processing, otherwise the program will deadlock due to an unexpected error.
7. Where it can be implemented in C language, try not to use assembly, especially in the implementation of algorithms, using assembly is obscure and difficult to understand.
8. Several parameter arrays of the program occupy a large space. Among them, the LCD background array is the longest, with 4,000 bytes. Therefore, those initialization arrays are placed in another C file, and the keyword extern is used in the main file to define, This will not interfere with the writing of the main file.
9. The lower the correlation between all functions, the more conducive to the expansion of future functions.
10. When compiling an array with the code keyword in version 6.20, the compilation passed, but the running result of the single-chip microcomputer was wrong, and it was normal after using version 6.14.