A delay function is defined normally as:
void delay(int n) { int i; for (i= 0; i<n; i++) _nop_(); }
when delay() performed,ALU get in loop but do nothing.Can use a timer counting to delay and release ALU to do something ?For example ,after input commands to erase I28F128 flash,enable timer0 to counting and program go do something else,when counting to 5's(flash is erased ),program go back and begin to write data to flash.
Best regards
Actually, no. Delay functions are "normally" not defined or used at all, and for precisely the reason you just described: they hog the CPU and keep it from doing useful things in the meantime. The only exception are delays that are so short that a) it doesn't hurt to hog the CPU for their duration, and b) they can't be implemented other than by busy-waiting anyway.
Proper delays are implemented as timers. Either by polling a free-running timer to see when the requisite time has passed, or by setting a timer interrupt (think "alarm clock") that signals completion of the waiting time.
"Proper delays are implemented as timers."
Oh dear, please don't say that something as mundane as a delay must now be classified as proper or otherwise!
May have to put an "only academics permitted" warning on the forum if it continues.
"Oh dear, please don't say that something as mundane as a delay must now be classified as proper or otherwise!"
You can argue about whether "proper" is an appropriate term for it, but it is certainly a Really Bad Idea - for precisely the reasons given (and subject to the exceptions explained) by Hans-Bernhard Broeker.
In addition to the reasons to avoid delay loops already given by Hans-Bernhard Broeker, writing them in a high-level language (HLL) such as 'C' is also a Really Bad Idea - see: " href= "http://www.8052.com/forum/read.phtml?id=152076">www.8052.com/.../read.phtml
... and "Real Programmers Eat Quiche"