Dear Friends, How to create a delay loop in C51.Say for example I need a delay loop for 35mS.How to do this.I tried a code taken from this forum.It is void delay(void) { unsigned long msdl; msdl = 35L * 1000L; while(--msdl) { _nop_(); } } Logically I think it should produce a 35mS delay code.But When I see in the Performance Analyzer window the delay produced is 0.547275 seconds. Can anybody help me in solving this problem. Thanx in Advance
It is very difficult to achieve accurate delay loops in 'C'. I've no idea why you think the code you have posted would produce a 35ms delay. You really need to use a timer if you need an accurate delay.
It is very difficult to achieve accurate delay loops in 'C'. I've no idea why you think the code you have posted would produce a 35ms delay. You really need to use a timer if you need an accurate delay. It is impossible to achieve version, release, optimization independent accurate delay loops in 'C'. You really need to use a timer or a routine in assembler if you need an accurate delay Erik
Also, just think of the 35mS that your program would be doing nothing (except maybe interupts). Andy
Also, just think of the 35mS that your program would be doing nothing (except maybe interupts). Andy Sorry, ment controller, not program
View all questions in Keil forum