The commonly used debugging methods in single-chip microcomputer debugging include printf and simulation. printf is flexible but not easy to use.ProgramWill die badly;
A simple example:
Main Program Main. c
The key initialization is called in Main. C, and the actual operations are commented out, leaving an empty shell,
It is set as software simulation in the project. TheoreticallyCodeThere is no problem, and there is actually no problem
The compilation result is shown in the first figure. There is no warning and no error. During simulation, the program should run an endless loop:
Of course, the above is a normal situation, but the actual simulation effect is:
Point programs cannot run, let alone a single step. It's no wonder:
. S Startup File-> main. C-> call keyinit ()-> return-> endless loop
This logic does not have any problems. Why cannot it be run?
Analysis:
Key. c
Key. h
From the above, stdio is referenced. h printf, while printf () needs to call putchar (). This module needs to be implemented externally, but it is not implemented in the program and there is no alarm during compilation, resulting in an implicit call.
Therefore, the program cannot run. We recommend that you implement it yourself when using printf. If problems do not occur, set the debugging switch before.
Solution:
1. Implement putchar ();
2. Implement printf ();
3. Do not use printf ();