Dudes: The following QuickBASIC program generates PIC source code for precise delays of from 1 to over 12,918,587,911 cycles. For a delay of 600,000,000 cycles (10 minutes at 4 MHz), the output looks like this: list r=dec r1 equ [any file register] r2 equ r1+1 r3 equ r2+1 r4 equ r3+1 ___________________ delay: movlw 213 | | movwf r1 | V movlw 205 | loop: decfsz r1 movwf r2 | goto loop movlw 228 | decfsz r2 movwf r3 | goto loop movlw 12 | decfsz r3 movwf r4 | goto loop | | decfsz r4 |_______| goto loop Here's the program: ' =================================================================== ' ' Four-Variable PIC Delay Calculator ' Written by Andy Warren, 31 Jan 1995 ' ' (C) 1995 Fast Forward Engineering ' ' Permission is hereby granted for all ' non-commercial use. ' defdbl a-z x = 0 input "Number of cycles to delay:",delay delay = int(delay) if delay < 32 then goto inline x = delay-16 d = int(x/50463234) x = x - d * 50463234: c = int (x/197122) x = x - c * 197122: b = int (x/770) x = x - b * 770: a = int (x/3) a = a + 1: b = b + 1: c = c + 1: d = d + 1 if a > 256 then a = 256 if b > 256 then b = 256 if c > 256 then c = 256 if d > 256 then d = 256 x = 3*a + 770*b + 197122*c + 50463234*d - 50661121 + 8 a$=right$(" "+str$(a),3): if a$ = "256" then a$ = " 0" b$=right$(" "+str$(b),3): if b$ = "256" then b$ = " 0" c$=right$(" "+str$(c),3): if c$ = "256" then c$ = " 0" d$=right$(" "+str$(d),3): if d$ = "256" then d$ = " 0" print print" list r=dec" print print"r1 equ [any file register]" print"r2 equ r1+1" print"r3 equ r2+1" print"r4 equ r3+1" print" ___________________ print"delay: movlw ";a$;" | |" print" movwf r1 | V" print" movlw ";b$;" | loop: decfsz r1" print" movwf r2 | goto loop" print" movlw ";c$;" | decfsz r2" print" movwf r3 | goto loop" print" movlw ";d$;" | decfsz r3" print" movwf r4 | goto loop" print" | | decfsz r4" print" |_______| goto loop" inline: x = delay - x g = int(x/2): if g = 0 then goto inline1 for y = 1 to g print" goto $+1" next inline1: if x/2 = int(x/2) then goto finis print" nop" finis: end '==================================================================== Enjoy... -Andy -- Andrew Warren - fastfwd@ix.netcom.com Fast Forward Engineering, Vista, California