How does an led flash 1,100000 seconds with PIC?

Asked

Viewed 77 times

1

I’m using the MPLAB IDE to simulate a flashing led for 1,100000 seconds.

But I’m not getting it. It always goes for more or less.

I wish you could give me a hint. Or some formula on how to calculate the Nop and loop 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

1 answer

0

I haven’t worked with Assembly in a while PIC. When I worked and needed one delay i resorted to a site that generated the code I needed. To my surprise this site still exists. And it’s this one: Microchip PIC Delay Code Generator.

I put the setting below:

Configuração utilizada no Pic Delay Code Generator

And the generated code 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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.