Black Book on MCU Program Debugging

Publisher:alpha12Latest update time:2012-08-06 Source: 51heiKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. The certainty of the program is greater than that of the hardware. Don't be afraid of program problems.
2. The most important thing for writing a program is not to learn a certain language, but to analyze the problem and propose a solution to the problem.
3. Programs with interrupts are more complicated. The programmer needs to know what I am doing and what others are doing at the same time. Only by thinking about the problem in a "concurrent" way can it be written well.
4. Program modularization is for writing rather than running. Modularization and function are two different concepts. Function is to unify the code that needs to be used multiple times in order to reduce the amount of program code and facilitate maintenance; modularization refers to the functional blocks that break down complex program functions into pieces. A module may consist of multiple functions, or it may be just one function, or it may just be a closely connected block of code.
Module---Open the refrigerator door
1. Raise your right hand and move it to 1cm to the right of the center of the refrigerator door handle
2. Bend your right fingers and build the refrigerator door
3. Pull back with a force of 2kg
4. Complete
5. Good modular design, the interface between modules is simple and clear. In general, a good program is a good program if it looks good and is easy to modify.
6. A good habit of writing programs is to write in modules, test while writing, and write the next module based on the tested module, which can reduce the possibility of program problems, quickly eliminate the modules related to the problem and locate the program statements.
7. Comments are not programs, but they can help the writer improve the possibility of writing while writing, and can also greatly improve the maintainability of the program. It is recommended that C language programs be annotated to functions, and some important operations should be annotated at least; assembly language programs, at least 70% of the statement lines should be annotated, and it is recommended to comment one line.
8. It is normal for a program to have bugs, and you must learn how to find bugs.
9. Faults are divided into soft and hard, and soft faults are the most difficult to find. Soft faults are mostly caused by design criticality and occur under certain starting conditions. When the conditions are destroyed, the fault may disappear without a trace.
The misleading nature of soft faults comes from the experience accumulated with hard faults. Because hard faults do not require starting conditions, people often use
Try---Judge--Try Again
10. Microcontroller software and hardware are inseparable. When finding problems, both types of troops should be used, and one side should not be identified.
11. The difference between debugging experts and novices is that experts know how to find the problem, while novices will be confused.
12. Pay attention to accumulation in daily life. Learning software and hardware is not just about knowing how to use them, but also about being familiar with your actual applications, including application conditions. Otherwise, you will turn a blind eye to the key phenomena that are extremely valuable for reasoning. You can use the "guess" method to find bugs, but after "guessing", you must infer all the phenomena to "verify". So we say "doubt---deny---doubt again---deny again, until you find the truth". The previous "try---judge---try again" is the basic method for finding bugs.
13. In front of bugs, the initialization states of novices and experts are the same, but experts consciously look for phenomena for analysis, while novices just stare at the phenomena in a daze.
14. There are two ways to obtain evidence---search and wait foolishly. Experts mainly search, while novices mainly wait foolishly.
15. The random-to-random method is an extreme confirmation method used when looking for low-probability soft faults. It requires the user to master the basic characteristics of the fault and understand the principle of "low-probability events rarely occur".
16. When a system consists of several parts, the part suspected of causing the fault can be replaced with other systems when looking for faults, and the BUG can be determined by observing whether the fault phenomenon migrates with the part.
17. Focus on the part that needs to be found, exclude the influence of other modules, and use the simplest method to judge. This is the value of the module isolation method.
18. When a time-related BUG occurs, its characteristics of being correct when tested separately and wrong when tested together often drive beginners crazy. When debugging a program with interrupts, you must have multiple ideas and suspect the time correlation of the program.
19. Because it only manifests itself during actual operation, time-related BUGs are more difficult to find. This is one of the reasons why we recommend debugging the program in an actual environment rather than a simulation environment. Complying with basic rules to write programs is the root cause of all BUGs to avoid time-related BUGs. Observing more phenomena and accumulating judgment basis is the magic weapon for finding time-related BUGs.

The above are some experiences summarized by Huqin, the webmaster of the MCU tutorial website http://www.51hei.com, in many years of program development. Although writing programs is tiring, as long as we continue to accumulate experience and keep learning, fun will naturally come with it. When we successfully develop a product, I think we will get more than just a product, but also pride and satisfaction. Being a programmer is a passionate job, and I hope we can all continue to write.

Keywords:MCU Reference address:Black Book on MCU Program Debugging

Previous article:A brief discussion on how to eliminate key jitter
Next article:SPI four modes IO simulation timing

Recommended ReadingLatest update time:2024-11-16 17:47

51 microcontroller simulation chip debugging
Experimental environment : Keil software, version: C51 V9.54 STC-ISP comprehensive download software, version: V6.88 Simulation chip : IAP15W4K58S4 51 microcontroller online simulation environment construction Step 1: Add the header files and simulation driver files of the STC microcontroller to the Keil software,
[Microcontroller]
51 microcontroller simulation chip debugging
Research on a Mobile Target Monitoring System Based on Single Chip Microcomputer
With the continuous development of IT industry, video surveillance is not only used in security systems, but also widely used in transportation systems, flood control systems, education systems and medical systems. However, in ordinary video surveillance systems, many monitoring systems only simply shoot and record ord
[Microcontroller]
Research on a Mobile Target Monitoring System Based on Single Chip Microcomputer
The use of CPLD devices in single chip controllers
The objects of automatic control are varied and of various types, requiring the controller to be modular, standardized, and flexibly configured; the era of commodity economy allows designers to have shorter development cycles, from several years or months to several months or days; sometimes, before the end of a con
[Microcontroller]
The use of CPLD devices in single chip controllers
Design of solar street light controller based on Atmega48 microcontroller
    The solar controller is the core part of the solar street light system. A solar street light controller based on Atmega48 single chip microcomputer is designed. The controller uses PWM pulse modulation control technology to detect battery voltage, charging current and other parameters, and controls the switch off
[Microcontroller]
Design of solar street light controller based on Atmega48 microcontroller
Using microcontroller and FPGA to realize the design of delay-adjustable module in the system
The signal delay module based on P89C51RD2 and FPGA is mainly used in point-to-point transmission systems that have high requirements on signal delay such as transmitting clock signals and digital synchronization signals. It can perform individual and appropriate delay adjustments for multiple signals. Reasons for sig
[Microcontroller]
Using microcontroller and FPGA to realize the design of delay-adjustable module in the system
Control two LEDs using one microcontroller port lead
A microcontroller's port pins can usually be driven high or low, or placed in an "input" or high impedance state. This circuit uses these three states to achieve the goal of driving two LEDs with a single port pin. This can be very useful in situations where no port pins are available (which often happens). A
[Power Management]
Activity monitor (high-end) application solution based on R8C/Lx Series and 78K0/Lx3 Series MCUs
  Summary An activity monitor is a device that monitors a person's various daily activities. Unlike a pedometer, it can also measure activities other than walking, such as sitting at a desk and sleeping. This allows the number of calories consumed per day to be calculated. Therefore, the use of activity monito
[Microcontroller]
Activity monitor (high-end) application solution based on R8C/Lx Series and 78K0/Lx3 Series MCUs
Proportional Electromagnet Control Technology Based on 51 Single Chip Microcomputer
introduction As an actuator, the proportional solenoid is one of the key products of mechatronics and is widely used in various automatic control systems. The proportional solenoid has a large thrust, simple structure, convenient maintenance, and low cost. It is a widely used electro-mechanical converter .
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号