Loop within a loop

Thread Starter

PIC GUY TREVOR

Joined Mar 8, 2009
28
Hello

I have written a small diagnostic program using MPLab to test the LEDs on my prototype board. However I am having trouble creating a delay between instructions, approx. 200,000 cycles otherwise I cant see my LEDs flash. I need to create a loop within a loop to make this delay but am having trouble with it. Can anyone assist me ?
 

Attachments

thatoneguy

Joined Feb 19, 2009
6,359
Online Delay Code Generator

Rich (BB code):
; Delay = 0.2 seconds
; Clock frequency = 20 MHz

; Actual delay = 0.2 seconds = 1000000 cycles
; Error = 0 %

	cblock
	tmp1
	tmp2
	tmp3
	endc

Delay_02sec
			;999990 cycles
	movlw	0x07
	movwf	tmp1
	movlw	0x2F
	movwf	tmp2
	movlw	0x03
	movwf	tmp3
Delay_02sec_0
	decfsz	tmp1, f
	goto	$+2
	decfsz	tmp2, f
	goto	$+2
	decfsz	tmp3, f
	goto	Delay_02sec_0

			;6 cycles
	goto	$+1
	goto	$+1
	goto	$+1

			;4 cycles (including call)

	return
 
Top