while (1) the role

Source: Internet
Author: User
while (1) is used in single chip microcomputer,
while (1);
Meaning: This is a dead loop, and the code no longer executes downward.
Use:
1. Generally in debugging code, in order to detect a part of the code is OK, to prevent the subsequent code interference execution results, will be in the observation point plus while (1);
2. Some code detects a run error, throws an error (printing, setting the error code), and then enters while (1);
3. When the machine needs to be reset, stop feeding the watchdog and enter while (1); Force watchdog timeout to generate hardware reset

while (1) {code}
Meaning: The code in {} will be repeated here
Use:
1. The main program generally uses this architecture when the MCU is not using the operating system.
2. Processes in the operating system, when performing tasks, some also use this architecture
The code in 3.{} constantly detects a condition and, when the condition is met, jumps out of the loop and continues down
4. Stay here and wait for interruption

We use while (1) in the microcontroller, mostly to prevent the program from running, because a lot of time after the execution of a program on the microcontroller's program pointer PC (that is, the program pointer) will not stop, still will continue to read the instructions from ROM and execution, which may appear program running flight, Then the result of uncertainty, we add a while (1) can let the program after the execution in situ cycle, equivalent to stop in situ, to prevent running.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.