How does a LED flash 1,100,000 seconds with the PIC?

1

I'm using MPLAB IDE to simulate a flashing LED for 1,100,000 seconds.

But I can not. It always goes more or less.

I wish you could give me a tip. Or some formula on how to calculate the nop and loop that I should put.

    LIST   P=PIC16F628A
    RADIX DEC   
    #INCLUDE <P16F628A.INC>
    __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_ON & _BODEN_OFF & _LVP_OFF & _CP_OFF & _MCLRE_OFF  
    ;ou __CONFIG H'3F10'

    CBLOCK  0x20    ;ENDEREÇO INICIAL DA MEMÓRIA DE
                    ;USUÃRIO
    CONTADOR1
    CONTADOR2
    ENDC            ;FIM DO BLOCO DE MEMÓRIA       

    ORG 0x00        ;ENDEREÇO INICIAL DE PROCESSAMENTO

    INICIO
    CLRF    PORTA       ;LIMPA O PORTA
    CLRF    PORTB       ;LIMPA O PORTB
    BSF STATUS, RP0
    CLRF TRISB
    BCF STATUS, RP0

    REPETE
    BSF PORTB, 1
    BSF PORTB, 1
    CALL ATRASO0
    BCF PORTB, 1
    CALL ATRASO2
    GOTO REPETE


    ATRASO0

    NOP
    NOP
    NOP
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    CALL ATRASO1
    ATRASO1     
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP

    ;   

    RETURN


    ATRASO2

    NOP
    NOP
    NOP
    NOP
    NOP
    NOP
    NOP
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3
    CALL ATRASO3

    ATRASO3     
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP

    ;   

    RETURN






    ;
    RETURN              


    END











    END
    
asked by anonymous 07.11.2016 / 00:56

1 answer

0

It's been a while since I worked with assembly on PIC . When I worked and needed delay I used a site that generated the code I needed. To my surprise this site still exists. And this is it: Microchip PIC Delay Code Generator .

I've put the configuration below:

And the code generated was as follows:

; Delay = 1.1 seconds
; Clock frequency = 4 MHz

; Actual delay = 1.1 seconds = 1100000 cycles
; Error = 0 %

    cblock
    d1
    d2
    d3
    endc

Delay_1_dot_1_second
            ;1099992 cycles
    movlw   0xD5
    movwf   d1
    movlw   0x66
    movwf   d2
    movlw   0x03
    movwf   d3
Delay_1_dot_1_second_0
    decfsz  d1, f
    goto    $+2
    decfsz  d2, f
    goto    $+2
    decfsz  d3, f
    goto    Delay_1_dot_1_second_0

            ;4 cycles
    goto    $+1
    goto    $+1

            ;4 cycles (including call)
    return
    
02.12.2016 / 12:30