Dear friend, can anybody explain me why this kind of Static function used and when it should be used?
static void delay (unsigned long cnt) { while (cnt--); }
First of all, please read the instructions on how to post source code: www.danlhenry.com/.../keil_code.png
Did you not notice in the preview that the presentation had gone wrong? Didn't you expect to see:
static void delay( unsigned long cnt ) { while( cnt-- ); }
Note that 'static' is a standard 'C' keyword that has nothing specifically to do Keil, nor ARM, nor with "this kind of function".
You can look up the meaning of the 'static' keyword in any good 'C' textbook...
See also: http://c-faq.com/index.html
The second part of the question: You should almost never perform a delay by busy-looping a fixed number of iterations. The compiler may completely optimize away the loop, since it doesn't have any side effect.
Configure a timer and either busy-loop reading the timer register, or (for longer delays) configure the timer to generate an interrupt.
The use of static functions touches the concept of implementation hiding: en.wikipedia.org/.../Implementation_Hiding Basically, if nobody should need to call the function, the function should be excluded from the global name space using the static keyword. Reducing the number of identifiers in the global name space is a good thing.
Thank-you for directly answering the posted question instead of getting off on a tangent.