Hello all, 1) can any one help me to write function in keil c51, like " delay(int milli sec)" like in turbo c/c++. 2) for above i want to use present project's crystal value (like variable) in user defined functions how to get that crystal value while writing code in "c". thankyou, PADMANABHAM
"WHY KEIL DOES NOT HAVE DELAY FUNCTION LIKE TURBO C" Because Turbo 'C' (remember that?!) builds programs to run on a PC and, as such, has the services of an operating system to call upon. Turbo C's delay function simply provides access to the underlying system's timer services. Keil C51 builds programs to run on 8051-based embedded systems; it makes no assumptions about the target. Therefore, if you want a delay() you must provide it your self - because only you can do that in a way that is compatible with the requirements, limitations, restrictions, etc of your particular application. Here's a previous discussion on the subject: http://www.keil.com/forum/docs/thread2938.asp
"i want to use present project's crystal value (like variable)" Unfortunately, that's not possible. :-( I have said before that it'd be really useful if Keil did make the uVision Project parameters available to the compiler - maybe via predefined macro constants like the existing __FILE__, __LINE__, etc. After all, the selected memory model is available via __MODEL__ - so why not the rest? In the meantime, you will just have to define a symbol yourself - I suggest in the 'Define' box on the C51 options tab.
Sir, i have tried following void DelayMS(unsigned char ms) { unsigned long us = 1000*ms; while (us--) { _nop_(); } } but in above function i have doubt, i will sure the nop will take one mechen cycle, but for while() and other thakes extra time how will i write to get exact 500ms delay or a flexible delay routine to get delay in milli seconds 1 to 10000ms. please give me some example code in c PADMANABHAM
"...i have doubt, i will sure the nop will take one mechen cycle, but for while() and other thakes extra time..." You are quite right to have that doubt, and that was precisely the issue discussed in the thread I cited earlier. Have you read the thread I cited earlier? "please give me some example code in c" Read the thread I cited earlier!