Hello frnz, i've designed a delay code that is as follows... for(i=0;i<40000;i++); The code has been designed for a NXP 89V51RD2 microcontroller similar to 8051 with a clock 11.0592MHz. How much delay could this line possibly generate?.. Time for single instruction is 1.085us. For 40000 counts, it may give upto 40 to 50 milliseconds. But in the development board the same code gives me nearly 0.7 to 1 second delay. Help me out please....
You have just created an extremely bad delay.
Which you would know if you did use the search function in this forum or maybe spent some time with Google.
The specifics of a high-level language is that it isn't intended to give you any (!) guarantees how long a specific loop takes to run. So you wanting to translate your loop into microseconds of delay is a fail.
Will you continue with this fail? Or do you have any plans to actually spend some time and see what hardware capabilities a microcontroller has for implementing delays? Isn't it way cooler to have the processor generate the delay and make use of the crystal frequency to make sure the delay is reasonably exact?
By the way:
for(i=0;i<40000;i++);
Do you really think this is enough code to be able to say you have actually "designed a code"? Is it enough that a carpenter uses a saw to split a piece of wood into two for him to talk about how he has created a building?
Start thinking bigger. And do that by do research before you start typing in the editor. Google has much useful resources available if you just decide to take the time.
i've designed a delay code
No, you haven't. At the non-existent level of understanding your target hardware that you demonstrate by asking those questions, you couldn't have. It's not design when you throw code together without actually knowing how it'll work.
The code has been designed
I'll take that to mean you didn't even write it; you just found it somewhere.
Not that whoever you took it from did much designing to begin with. That snippet is exactly the naive, first idea everybody has about how to do a delay. And like many naive ideas in technical design, it's just plain dumb wrong more than 95 percent of the time.
"i've designed (sic) a delay code ... How much delay could this line possibly generate?"
Surely, if you had really designed it, you would know how much delay it generated - by design...?!
"Time for single instruction is 1.085us"
And what, do you think, constitutes such a "single instruction"?
How many a "single instruction" do you think there are in your 'for' loop?