~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
this delay(1000000) is around 5 seconds
i m using 20MHz crystal, can i know how is this 5seconds calculation?
If the delay is only half what you expected it to be, either you have told the software the clock is 10MHz or the value you passed to the delay() routine is too large for it to handle.
click on _delay_loop_1() or _delay_loop_2() in the above link to see the explanation.
But usually the number you enter for the delay is us or ms and in your case its not so i assume like said in the previous post that you have the wrong clock setting in your project (i assume 4MHz).
if the setting was correct you would probably use delay(5000000); if the delay is in us.
And where do you see that connection between the delay_time variable and the delay() function, your C code shows only a variable that is never used.
When we say that the crystal freq. is not set up correctly we don't mean your physical crystal but the clock define for the code.
We don't even know what microcontroller or application you are using, a simple look at the delay function will solve all questions.
alexan_e is right.
For some reason you are associating delay_time with the actual delay you are asking for. All you are actually doing is creating a new variable called 'delay_time' and assigning it a value of 5000, but you do not use that variable later!
In most compilers there is a 'delay(x)' function where x is a number of seconds, milliseconds or microseconds. Without telling us which compiler you are using we can't tell what the delay units are. Regardless of that, the 5 second delay you have does not match any of those units so one of two things can be wrong:
1. Your crystal is 20MHz but have you told the program that? If the program creates the delay in a software loop it needs to know how long each instruction takes to execute before it can calculate how to make the delay you want. Somewhere, either in your IDE or in the program you have to tell it you are using 20MHz as the clock source.
2. The value 1000000 you use for the delay may be out of range and not used correctly by the delay() routine. For example, if it only accepted unsigned ints as the delay parameter you would not be allowed to use a value greater than 65565.
I would question how you are detecting the delay. Assuming the missing '}' at the end of the program is there, 'out' is only low for a few cycles as the loop restarts.