PIC Microcontoller Delay Method

Stack Recursive Delay

The name of the lable you call indicates the number of cycles (Convert cycles to time) that will be executed before returning. This uses an amazingly small number of bytes and is probably more effecient than inline loops or nop's if you are going a lot of little delays of varying times through out your code.


Delay131072     call Delay16384	; uses 6 stack levels
Delay114688     call Delay16384
Delay98304      call Delay16384
Delay81920      call Delay16384
Delay65536      call Delay16384
Delay49152      call Delay16384
Delay32768      call Delay16384
Delay16384      call Delay2048	;uses 5 stack levels
Delay14336      call Delay2048
Delay12288      call Delay2048
Delay10240      call Delay2048
Delay8192       call Delay2048
Delay6144       call Delay2048
Delay4096       call Delay2048
Delay2048       call Delay256	;uses 4 stack levels
Delay1792       call Delay256
Delay1536       call Delay256
Delay1280       call Delay256
Delay1024       call Delay256
Delay768        call Delay256
Delay512        call Delay256
Delay256        call Delay32	;uses 3 stack levels
Delay224        call Delay32
Delay192        call Delay32
Delay160        call Delay32
Delay128        call Delay32
Delay96         call Delay32
Delay64         call Delay32
Delay48         call Delay32	;Dean [effect at amaze.net.au] says this line should be deleted 
;"...a 128 instruction delay was taking 160 instructions to execute (32 extra)...[its just this]
;one line that needs to be deleted to fix it"
Delay32         call Delay4	;uses 2 stack levels
Delay28         call Delay4
Delay24         call Delay4
Delay20         call Delay4
Delay16         call Delay4
Delay12         call Delay4
Delay8          call Delay4
Delay4          return		;uses 1 stack level

Comments: