This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

WHY KEIL DOES NOT HAVE DELAY FUNCTION LIKE TURBO C

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

Parents
  • 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

Reply
  • 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

Children
  • "...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!