I am writing a C programme to blast into a PIC micorcontroller and i need a 1 millisecond delay. Could anyone provide me code for a 1 miollisecond delay
Printable View
I am writing a C programme to blast into a PIC micorcontroller and i need a 1 millisecond delay. Could anyone provide me code for a 1 miollisecond delay
sleep(1); But I doubt many platforms would be able to perform a 1 millisecond delay precisely.
Not mentioning which OS/Compiler you're actually using makes for vague answers.
Using the Microsoft based package Visual C++
Software delay can be done using "for" loops
for( a=0;a<8; a++ )
for( b=0; b<80; b++ );
or
by using assembly lang delay routines can be written
Delay routines depend on Clock frequency/Time each instruction takes.
http://faq.cprogramming.com/cgi-bin/...&id=1043284392
Even though Sleep() is in milliseconds, you're not likely to get consistent 1mS delays out of it.
I would suggest you need another approach to the problem, one which doesn't need precise time delays.
Off topic, but GREAT sig there, Salem....
It needs someone to know the design of the machine. There is a timer interrupt in PCs (int0). I think it should be used for making delays at the highest precise that that machine can make, without consuming CPU time.Quote:
Originally Posted by pprabhakar
I don't know, but that micorcontroller may has a special type library included, to handle such things (ex special sleep() function).