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
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.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Off topic, but GREAT sig there, Salem....
Mr. Blonde: You ever listen to K-Billy's "Super Sounds of the Seventies" weekend? It's my personal favorite.
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.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).
Last edited by siavoshkc; 03-13-2006 at 06:06 PM.
Learn C++ (C++ Books, C Books, FAQ, Forum Search)
Code painter latest version on sourceforge DOWNLOAD NOW!
Download FSB Data Integrity Tester.
Siavosh K C