/*** Direct Hit to the Essence ***/ 1) A certain time delay is required when powering up the entire chip The main reason is that during the power-up process, the power supply is not stable enough, which may interfere with the internal initialization of the chip, causing abnormal operation of peripheral devices; at the same time, some complexly initialized peripherals also need a stable power supply for control, otherwise initialization may fail. 2) How to choose the delay for the main program Most beginners learning delay will choose the for statement to achieve delay, using the for statement mainly results in a dead loop to achieve the purpose of delay, which greatly affects the program efficiency of the MCU. Let’s briefly talk about system delays: 1. Dead Loop Delay This delay method mainly has a significant impact on program efficiency, and task-blocking delays will cause other tasks to also experience delays, leading to serious interference between tasks and low program efficiency (for tasks with operating systems that use non-dead loop delays). At the same time, the delay cannot be very precise, and the portability is not very good. Although there are many drawbacks, it must have its significance since it exists. Based on usual usage, the above-mentioned power-up delay is commonly done using dead loop delays; similarly, when initializing complex hardware driver programs, a certain delay is also required, in which case using a dead loop is more appropriate. 2. Accumulative Delay Accumulative delay mainly achieves a set value through the accumulation of counting variables in the task, allowing the real task processing to be executed. While one task is counting and waiting, the impact on other tasks that are also waiting is greatly reduced compared to dead loop delays. However, the delay time will be affected by the execution time of the task, and can be used when high precision in delay is not required, resulting in higher MCU utilization. 3. Timer-based Delay This method is also commonly used in MCU programming, but there are two main implementation methods. The timer generates interrupts and runs interrupt service functions. Some people place timed tasks in the main function, while others place the main tasks in the interrupt service function. Let’s briefly discuss the usage conditions of these two methods. First, for tasks placed in the interrupt service function, as long as the tasks do not exceed the timer period, each task can be executed in real-time, which is commonly used for real-time control. For tasks that may exceed the timer period, the program needs to analyze based on the actual application of the MCU; some MCUs may not run at all, while others may cause interrupt loss due to failure to clear the interrupt flag in time, preventing the next interrupt from occurring; for tasks executed in the main function, which is our front-and-back architecture, the precautions are generally consistent with the previous interrupt task method. However, once the total task execution exceeds the minimum timer period, the worst-case scenario is only causing the execution of tasks at that moment, or inaccurate delays. However, the system will not suffer from freezes or other hidden dangers, and this method can basically meet our usual applications. Alright, this is the WeChat public account“The Last Bug”, where I will share many useful programming tips and learning insights later. Thank you all for your attention!