Loop within a loop

Discussion in 'Embedded Systems and Microcontrollers' started by PIC GUY TREVOR, Mar 30, 2009.

  1. PIC GUY TREVOR

    Thread Starter Member

    Mar 8, 2009
    28
    0
    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 ?
     
  2. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    Online Delay Code Generator

    Code ( (Unknown Language)):
    1.  
    2. ; Delay = 0.2 seconds
    3. ; Clock frequency = 20 MHz
    4.  
    5. ; Actual delay = 0.2 seconds = 1000000 cycles
    6. ; Error = 0 %
    7.  
    8.     cblock
    9.     tmp1
    10.     tmp2
    11.     tmp3
    12.     endc
    13.  
    14. Delay_02sec
    15.             ;999990 cycles
    16.     movlw   0x07
    17.     movwf   tmp1
    18.     movlw   0x2F
    19.     movwf   tmp2
    20.     movlw   0x03
    21.     movwf   tmp3
    22. Delay_02sec_0
    23.     decfsz  tmp1, f
    24.     goto    $+2
    25.     decfsz  tmp2, f
    26.     goto    $+2
    27.     decfsz  tmp3, f
    28.     goto    Delay_02sec_0
    29.  
    30.             ;6 cycles
    31.     goto    $+1
    32.     goto    $+1
    33.     goto    $+1
    34.  
    35.             ;4 cycles (including call)
    36.  
    37.     return
    38.  
    39.  
     
  3. PIC GUY TREVOR

    Thread Starter Member

    Mar 8, 2009
    28
    0
    I will give it a try thanks for the quick response :)
     
Loading...