; Delay = 1 seconds
; Clock frequency = 4 MHz
; Actual delay = 1 seconds = 1000000 cycles
; Error = 0 %
cblock
d1
d2
d3
endc
;999997 cycles
movlw 0x08
movwf d1
movlw 0x2F
movwf d2
movlw 0x03
movwf d3
Delay_0
decfsz d1, f
goto $+2
decfsz d2, f
goto $+2
decfsz d3, f
goto Delay_0
;3 cycles
goto $+1
nop
; Generated by http://www.golovchenko.org/cgi-bin/delay (December 7, 2005 version)
; Sat Jan 22 09:25:39 2011 GMT
If you intend to use delay several times, will waste microcontroller processing.
The best alternative is to use delay under interrupt conception.
+++
It's a blocking routine, what Andre_teprom means is that while in the delay loop you are wasting time that could be used more profitably.
If you use one of the hardware timers to generate periodic interrupts, you can create almost any delay you want and still run other tasks at the same time.
Looking at it from the opposite angle, if you use software loops to create delays and you also use interrupts for something else, every interrupt will make to delay longer than you want it to be.
Brian.
u can also use built in function in mikro c pro compiler
Delay_ms(2000);
ms=milli seconds... just calculate and insert it in the function ..............
visit
compizspec.blogspot.com
may be helpful
void main(void)
{
while(1)
{
if (TIMER1_Overflow)
{
ResetFlagTimer1();
prescall++;
if (prescall > TIME1000ms)
{
prescall=0;
//--------- here we pass every 1000ms
DoSomething();
}
DoTask1();
DoTask2();
.....
}
} // endless loop
}
The best RTOS for PIC uP is SALVO
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?