Any way to put a delay into this.:
my code is this:
Code:HR1 = 92160/pulseperiod; ADDR1 = 1; if(HR1 < 40) { } else { TXBUF0 = ADDR1; <---------------------------------// i want to put a delay of 0.1sec here. TXBUF0 = HR1; }
Any way to put a delay into this.:
my code is this:
Code:HR1 = 92160/pulseperiod; ADDR1 = 1; if(HR1 < 40) { } else { TXBUF0 = ADDR1; <---------------------------------// i want to put a delay of 0.1sec here. TXBUF0 = HR1; }
What platform/OS are you using?
For windows there is Sleep(). For linux usleep() (maybe and others). In both you enter the milliseconds of the delay.
Otherwise you can use a for-loop. Just make sure you add an instruction, because if you do something like this
your compiler might see that it does nothing and not run it at all. You could do something likeCode:for(i=0; i < 10000; ++i) ;
But of course you don't know exactly how much time needed for it to execute, you would have to estimate by measuring it.Code:for(i=0; i < 10000; ++i) a++;
im using window.ya if i use sleep();
what do i need to use for the header? is it conio.h? or some other thing?because i try putting in the sleep(); bu they prompt me with warning.
"function sleep declared implicitly"...
For DOS it's sleep(seconds you want), and include dos.h
For Windows it's Sleep(milliseconds you want), and include windows.h
It's confusing sometimes!
thank guy for the help once again.i will try it out and let u get know. im not using visual c to program it im using IAR workbench to program my code.so i do not know it will work not. so will update you guy again. thank anyway.
I do not want to be a pain, but for me the code looks like asking for problems. You want to write a value in variable, sleep, and write another value to same variable. Do not tell me you're planning to read this value during the sleep from some other process? If you do, then i hope you have real good realtime os underneath. Else this sounds like asking for problems. I suggest you to forget the sleep, and build some proper synchronization, where the reader tells when new value can be written.
Obsession to networking and protocols made me cook up these:
NSN - Network Status Notifier
epb - Ethernet Packet Bombardier
T.H.O.N.G.S - Textmode Helper On Network Getting Sniffed
Nibbles - console UDP print listener/filter + something else
Feel free to try, comment and improve =)