Problem linking?

Alex
2007-03-06
2013-03-12
  • Alex

    Alex - 2007-03-06

    I worte this simple code:

    #include<pic16f628a.h>
    main(void)
    {
        TRISB = 0;
        PORTB = 137;
        return 0;
    }

    I compile it and it works well.

    Compiling it for a 18F1220 the asm output seems perfect:

        list    p=18f1220
        radix dec
    ;--------------------------------------------------------
    ; public variables in this module
    ;--------------------------------------------------------
        global _stack
        global _stack_end
        global _main
    ;--------------------------------------------------------
    ; extern variables in this module
    ;--------------------------------------------------------
        extern _PORTAbits
        extern _PORTBbits
        extern _LATAbits
        extern _LATBbits
        extern _TRISAbits
        extern _TRISBbits
        extern _PIE1bits
        extern _PIR1bits
        extern _IPR1bits
        extern _PIE2bits
        extern _PIR2bits
        extern _IPR2bits
        extern _EECON1bits
        extern _RCSTAbits
        extern _TXSTAbits
        extern _T3CONbits
        extern _ECCPASbits
        extern _CCP1CONbits
        extern _ADCON2bits
        extern _ADCON1bits
        extern _ADCON0bits
        extern _T2CONbits
        extern _T1CONbits
        extern _RCONbits
        extern _WDTCONbits
        extern _LVDCONbits
        extern _OSCCONbits
        extern _STATUSbits
        extern _INTCON3bits
        extern _INTCON2bits
        extern _INTCONbits
        extern _STKPTRbits
        extern _PORTA
        extern _PORTB
        extern _LATA
        extern _LATB
        extern _TRISA
        extern _TRISB
        extern _PIE1
        extern _PIR1
        extern _IPR1
        extern _PIE2
        extern _PIR2
        extern _IPR2
        extern _EECON1
        extern _EECON2
        extern _EEDATA
        extern _EEADR
        extern _BAUDCTL
        extern _RCSTA
        extern _TXSTA
        extern _TXREG
        extern _RCREG
        extern _SPBRG
        extern _SPBRGH
        extern _T3CON
        extern _TMR3L
        extern _TMR3H
        extern _ECCPAS
        extern _CCP1CON
        extern _CCPR1L
        extern _CCPR1H
        extern _ADCON2
        extern _ADCON1
        extern _ADCON0
        extern _ADRESL
        extern _ADRESH
        extern _T2CON
        extern _PR2
        extern _TMR2
        extern _T1CON
        extern _TMR1L
        extern _TMR1H
        extern _RCON
        extern _WDTCON
        extern _LVDCON
        extern _OSCCON
        extern _T0CON
        extern _TMR0L
        extern _TMR0H
        extern _STATUS
        extern _FSR2L
        extern _FSR2H
        extern _PLUSW2
        extern _PREINC2
        extern _POSTDEC2
        extern _POSTINC2
        extern _INDF2
        extern _BSR
        extern _FSR1L
        extern _FSR1H
        extern _PLUSW1
        extern _PREINC1
        extern _POSTDEC1
        extern _POSTINC1
        extern _INDF1
        extern _WREG
        extern _FSR0L
        extern _FSR0H
        extern _PLUSW0
        extern _PREINC0
        extern _POSTDEC0
        extern _POSTINC0
        extern _INDF0
        extern _INTCON3
        extern _INTCON2
        extern _INTCON
        extern _PRODL
        extern _PRODH
        extern _TABLAT
        extern _TBLPTRL
        extern _TBLPTRH
        extern _TBLPTRU
        extern _PCL
        extern _PCLATH
        extern _PCLATU
        extern _STKPTR
        extern _TOSL
        extern _TOSH
        extern _TOSU
    ;--------------------------------------------------------
    ;    Equates to used internal registers
    ;--------------------------------------------------------
    WREG    equ    0xfe8
    PRODL    equ    0xff3
    ustat_csorgente_00    udata    0X0032
    _stack    res    63
    _stack_end    res    1
    ;--------------------------------------------------------
    ; interrupt vector
    ;--------------------------------------------------------
    ;--------------------------------------------------------
    ; global & static initialisations
    ;--------------------------------------------------------
    ; I code from now on!
    ; ; Starting pCode block
    S_csorgente__main    code
    _main:
    ;    .line    11; csorgente.c    TRISB = 0;        /* setta le porte B come uscite */
        CLRF    _TRISB
    ;    .line    12; csorgente.c    PORTB = 137;    // 10001001
        MOVLW    0x89
        MOVWF    _PORTB
    ;    .line    13; csorgente.c    return 0;
        CLRF    PRODL
        CLRF    WREG
        RETURN   
    end

    but disassembling the hex this is the source:

            #include <p18f1220.h>
            processor p18f1220

    ; memoryory code
            org 0x000000
            goto    0xca

            org 0x00002A
            movlw    0xe2
            movwf    0xf6, 0
            movlw    0
            movwf    0xf7, 0
            movlw    0
            movwf    0xf8, 0
            tblrd    *+
            movf    0xf5, 0, 0
            movwf    0x5, 0
            tblrd    *+
            movf    0xf5, 0, 0
            movwf    0x6, 0
            bnz    0x4c
            tstfsz    0x5, 0x1
            bra    0x4c
            goto    0xc8
            tblrd    *+
            movf    0xf5, 0, 0
            movwf    0, 0
            tblrd    *+
            movf    0xf5, 0, 0
            movwf    0x1, 0
            tblrd    *+
            movf    0xf5, 0, 0
            movwf    0x2, 0
            tblrd    *+
            tblrd    *+
            movf    0xf5, 0, 0
            movwf    0xe9, 0
            tblrd    *+
            movf    0xf5, 0, 0
            movwf    0xea, 0
            tblrd    *+
            tblrd    *+
            tblrd    *+
            movf    0xf5, 0, 0
            movwf    0x3, 0
            tblrd    *+
            movf    0xf5, 0, 0
            movwf    0x4, 0
            tblrd    *+
            tblrd    *+
            movff    0xff6, 0x7
            movff    0xff7, 0x8
            movff    0xff8, 0x9
            movff    0, 0xff6
            movff    0x1, 0xff7
            movff    0x2, 0xff8
            movf    0x3, 0, 0
            bnz    0xa0
            movf    0x4, 0, 0
            bz    0xb2
            tblrd    *+
            movf    0xf5, 0, 0
            movwf    0xee, 0
            movff    0xff5, 0xf7e
            decf    0x3, 0x1, 0
            bc    0x9a
            decf    0x4, 0x1, 0
            bra    0xa0
            movff    0x7, 0xff6
            movff    0x8, 0xff7
            movff    0x9, 0xff8
            decf    0x5, 0x1, 0
            bc    0xc4
            decf    0x6, 0x1, 0
            goto    0x42
            return    0
            lfsr    0x1, 0x71
            lfsr    0x2, 0x71
            clrf    0xf8, 0
            bsf    0xa6, 0x7, 0
            bcf    0xa6, 0x6, 0
            call    0x2a, 0
            call    0xf0, 0
            bra    0xe0
            dw    0x1  ;unknown opcode
            dw    0xfc  ;unknown opcode
            nop
            dw    0x80  ;unknown opcode
            nop
            dw    0x1  ;unknown opcode
            nop
            clrf    0x93, 0
            movlw    0x89
            movwf    0x81, 0
            clrf    0xf3, 0
            clrf    0xe8, 0
            return    0
            nop

            end

    And it does not work because to the "bsf 0xa6, 0x7, 0" line as gpsim reports:

    attempt read from invalid file register
    attempt write to invalid file register: address 0x0, value 0x80
    real time stop : 64
    real time clearing
    0x0000000000000007  p18f1220  0x006A  0x8EA6  bsf       invalid fr  0xfa6,7
       read: 0x00 from 0x00
      wrote: 0x00 to 0x00

    If I copy,paste and adjust the first asm output and compile it with gputils it works..
    Do you know where is the problem?

    Regards
    Alex

     
    • Alex

      Alex - 2007-03-07

      Ok i was using piklab and it compiles with a line like this:
      #"/usr/bin/gplink" -I"/usr/bin/../share/sdcc/lib/pic16" -I"/usr/share/sdcc/lib/pic16"  -ocsorgente.hex -m -ainhx32  -o csorgente csorgente.o  crt0i.o pic18f1220.lib libsdcc.lib
      I resolved the problem removing the crt01.o object file in the line.
      Regards
      Alex

       
    • Raphael Neider

      Raphael Neider - 2007-03-09

      Careful here, crt0i is used to to initialize global and/or static variables as well as to transfer control to _main. It also registers a RESET interrupt handler to do so. If you remove crt0i, you SHOULD probably declare main as interrupt 0 handler...
      Anyway, accessing 0xfa6 should be safe (even EECON1 is implemented on the 18f1220...), why do you suspect this to cause an error?!? What do you mean by `it does not work'? Did you test real hardware or do you rely on gpsim's warning?
      Also consider replacing the #include directive (for a 16f628a?!?) with
          #include <pic18fregs.h>
      instead, which selects the include file based on the selected -pPROCESSOR (pic16 port only).

      Regards,
      Raphael

       

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks