could any one pls tell me the coding to calculate 1 sec delay in embedded c for 8051 controller without using timer!!!
i.e using for loop and pls explain it
the idea is use interrupt timer for fixed period and then find out integral multiple of 1 sec by fixed time.... use loop to count for multiple factor will solve your problem
the idea is use interrupt timer for fixed period and then find out integral multiple of 1 sec by fixed time.... use loop to count for multiple factor will solve your problem
if you are using only this code in the polling mode and use proper constant and your crystal is 12 Mhz....but there is a catch as in case of micro-controller like 8051 the instruction clock is 1/12 of clock frequency .....mostly 1 Mhz in case of 12 Mhz.... so better way to exact delay better to use interrupt timer....
if you are using only this code in the polling mode and use proper constant and your crystal is 12 Mhz....but there is a catch as in case of micro-controller like 8051 the instruction clock is 1/12 of clock frequency .....mostly 1 Mhz in case of 12 Mhz.... so better way to exact delay better to use interrupt timer....
as jjeevan said it is possible but in polling mode please keep the loop for 1000 in case of 11.92 Mhz crystal to get 1ms delay i.e. for(i=0;i<1000;i++);
hi...
with 11.085MHz your instruction clock would be 1.085microsecond long. Take this into consideration and use a loop for generating the 1 sec delay. u will also have to consider the time taken by the increment/decrement instructions while setting the count for the loop.
hope that helps...
hi,
the for loop shown above will work but during conversion into assembly, the code will split into different ASM instructions having different execution/machine cycles. so the time dalay may not be exact.
if u are using keil, u can view the assembly code of FOR loop. from that u can calculate the time taken to execute one complete FOR loop. then u can multiply that delay(in for loop) to get 1 milisecond.with this delay will be more accurate. but the best way is to use software interrupt OR timer.
guys, correct me if something is wrong.
Use your compiler to measure the time the loop takes. That way, you can accurately measure the time your delay routine takes, and adjust it as required.
Also, check your compiler documentation/manual. It should provide library functions for generating delays. eg in mikroC, you have the delay_ms function. So, to generate a 1s delay, all you'd need would be:
Use your compiler to measure the time the loop takes. That way, you can accurately measure the time your delay routine takes, and adjust it as required.
Also, check your compiler documentation/manual. It should provide library functions for generating delays. eg in mikroC, you have the delay_ms function. So, to generate a 1s delay, all you'd need would be: