Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How to define and use delay function in C language of 5 1 single chip microcomputer?
How to define and use delay function in C language of 5 1 single chip microcomputer?
Define a delay function that delays xms milliseconds.

Void delay(unsigned int xms) // xms indicates the number of milliseconds to be delayed.

{

Unsigned integers x, y;

for(x = xms; x》0; x -)

for(y = 1 10; y》0; y-);

}

Use:

Invalid delay 10us(uchar Ms)

{

Uchar data I;

for(; ms》0; Ms -)

for(I = 26; I "0; I-);

}

I = [(delay value-1.75) *12/ms-15]/4.

Extended data 1. When designing an accurate delay subroutine in C5 1, try not to define local variables in the delay subroutine, and all variables in the delay subroutine are passed through parameter functions.

2. When designing the delay subroutine, do…while is adopted, and the structure is better than for structure.

3. In the design of delay subroutine, it is better to use the inner loop first and then reduce it than to reduce it first and then the inner loop.