user3177225
user3177225

Reputation: 1

Why does a simple delay routine produces error 116

I have a very simple delay routine to produce delay bigger that 0.5 sec; the idea is to use TMR2, PR2 and PIC12F683; but it produces an error 116

DELAY MACRO

    BANKSEL T2CON

    MOVLW 0x76  ; put register w=118

    MOVWF T2CON ; T2CON=W=1110111 Start TMR2 and set Postsacaler to 1110

    BANKSEL PR2

    MOVLW 0xC8

    MOVWF PR2 ; Put PR2 to 200

**Lazo

    BANKSEL T2CON

    BTFSS T2CON,TOUTPS0 ;when TMR2= PR2 bit 3 (post scaler) is incremented from 1110 to 1111 then jump next instruction and end macro

    GOTO Lazo****

    endm

Error[116]   C:\USERS\MUTANTE\MPLABXPROJECTS\CLAXON.X\MACROSDEF.INC 12 : Address label duplicated or different in second pass (Lazo)

Any idea why i got this error in the Lazo loop

Upvotes: -1

Views: 231

Answers (1)

Clifford
Clifford

Reputation: 93556

When a macro is instantiated, its content is inserted verbatim, and that is what the assembler sees. If you define a label inside of a macro and then call the macro more than once, the label is defined more than once, and you will get this error.

Labels in macros must use the LOCAL directive inside of the macro definition, thus:

DELAY MACRO
    LOCAL Lazo

    BANKSEL T2CON
    MOVLW 0x76  ; put register w=118
    MOVWF T2CON ; T2CON=W=1110111 Start TMR2 and set Postsacaler to 1110
    BANKSEL PR2
    MOVLW 0xC8
    MOVWF PR2 ; Put PR2 to 200

Lazo
    BANKSEL T2CON
    BTFSS T2CON,TOUTPS0 ; when TMR2= PR2 bit 3 (post scaler) is 
                        ; incremented from 1110 to 1111 then jump 
                        ; next instruction and end macro
    GOTO Lazo
    ENDM

Upvotes: 1

Related Questions