Embedded C realizes the difference of different variables of delayed program Several kinds of Linux embedded development environment is introduced briefly

In embedded systems, the delay is often a means to be used. The delay method can be achieved by using instructions similar to "NOP", but if the delay is long, if you use too many "NOPs" "The instruction will consume too much storage space. The best way is to use a subroutine (in assembly language) or a subroutine (in high-level language). Of course, this is not intended to discuss if you use timer interrupts to implement delays. The following is a discussion of the use of subfunctions to implement delays in the C language. Some discussion of the delays in high-level languages, of course, requires consideration of compilers and processors. For ease of discussion and without loss of generality, it is possible to use The standard 51 single-chip microcomputer is used as the compiling environment for the processor and uVision2, and the crystal oscillator is 12MHz. Such a standard machine cycle is 1uS. Other situations can be analogized.

Let's look at a delay program: where the type parameters of Delay1() and Delay2() are different.

The above Delay1 (100) (variables are of type unsigned int) or Delay2 (100) (variables of type unsigned char) are executed in two separate processes and the following execution results are obtained:

The time for the breakpoint B minus the breakpoint A is 810uS. This time is the time taken to execute Delay1 (100).

The time for the breakpoint B minus the breakpoint A is 608uS. This time is the time taken to execute Delay2 (100).

It can be seen that passing a parameter of the delay function as an unsigned int variable type will increase the delay time, and using the unsigned char variable type will result in a short delay time. We all know that after the C language is compiled to be translated into assembly language, only the assembly statement has the exact execution time, so to know the difference between the two results, the reason is that they are compiled after the different parts of the statement.

4G MIFI

Shenzhen MovingComm Technology Co., Ltd. , https://www.movingcommiot.com

This entry was posted in on