Can't run anything compiled with SDCC...

Help
Anonymous
2010-09-26
2013-03-12
  • Anonymous - 2010-09-26

    Hi guys, I'm having some problems trying to get even the simplest of programs running.
    I can't for the life of me figure out why this won't work:

    #define __16f627
    #include <pic/pic16f627.h>
    typedef unsigned int config;
    config at 0x2007 __CONFIG =
        _CP_OFF &
        _WDT_OFF &
        _BODEN_OFF &
        _PWRTE_OFF &
        _ER_OSC_CLKOUT &
        _MCLRE_ON &
        _LVP_OFF;
    void configure_pins() {
        _asm
        bsf status, rp0
        movlw b'11111111'
        movwf TRISA
        movlw b'00000000'
        movwf TRISB
        bcf status, rp0
        _endasm;
    }
    void main(void) {
        configure_pins();    
        _asm
        movlw 0xFF
        movwf PORTB
        _endasm;
    }
    

    It compiles perfectly well, but just doesn't do anything. I've looked at the ASM and the only problem that could possibly exist would be one in _sdcc_gsinit_startup, because when written in pure ASM, the code above works just fine.
    Here is the ASM output:

    ;--------------------------------------------------------
    ; File Created by SDCC : free open source ANSI-C Compiler
    ; Version 2.9.0 #5416 (Sep 25 2010) (UNIX)
    ; This file was generated Sun Sep 26 12:18:09 2010
    ;--------------------------------------------------------
    ; PIC port for the 14-bit core
    ;--------------------------------------------------------
        .file    "/home/chris/Documents/Electronics Projects/snake/central_processor.c"
        list    p=16f627
        radix dec
        include "p16f627.inc"
    ;--------------------------------------------------------
    ; config word 
    ;--------------------------------------------------------
        __config 0x3f3b
    ;--------------------------------------------------------
    ; external declarations
    ;--------------------------------------------------------
        extern    _CCP1CON_bits
        extern    _CMCON_bits
        extern    _EECON1_bits
        extern    _INTCON_bits
        extern    _OPTION_REG_bits
        extern    _PCON_bits
        extern    _PIE1_bits
        extern    _PIR1_bits
        extern    _PORTA_bits
        extern    _PORTB_bits
        extern    _RCSTA_bits
        extern    _STATUS_bits
        extern    _T1CON_bits
        extern    _T2CON_bits
        extern    _TRISA_bits
        extern    _TRISB_bits
        extern    _TXSTA_bits
        extern    _VRCON_bits
        extern    _INDF
        extern    _TMR0
        extern    _PCL
        extern    _STATUS
        extern    _FSR
        extern    _PORTA
        extern    _PORTB
        extern    _PCLATH
        extern    _INTCON
        extern    _PIR1
        extern    _TMR1L
        extern    _TMR1H
        extern    _T1CON
        extern    _TMR2
        extern    _T2CON
        extern    _CCPR1L
        extern    _CCPR1H
        extern    _CCP1CON
        extern    _RCSTA
        extern    _TXREG
        extern    _RCREG
        extern    _CMCON
        extern    _OPTION_REG
        extern    _TRISA
        extern    _TRISB
        extern    _PIE1
        extern    _PCON
        extern    _PR2
        extern    _TXSTA
        extern    _SPBRG
        extern    _EEDATA
        extern    _EEADR
        extern    _EECON1
        extern    _EECON2
        extern    _VRCON
        extern    __sdcc_gsinit_startup
    ;--------------------------------------------------------
    ; global declarations
    ;--------------------------------------------------------
        global    _configure_pins
        global    _main
        global PSAVE
        global SSAVE
        global WSAVE
        global STK12
        global STK11
        global STK10
        global STK09
        global STK08
        global STK07
        global STK06
        global STK05
        global STK04
        global STK03
        global STK02
        global STK01
        global STK00
    sharebank udata_ovr 0x0070
    PSAVE    res 1
    SSAVE    res 1
    WSAVE    res 1
    STK12    res 1
    STK11    res 1
    STK10    res 1
    STK09    res 1
    STK08    res 1
    STK07    res 1
    STK06    res 1
    STK05    res 1
    STK04    res 1
    STK03    res 1
    STK02    res 1
    STK01    res 1
    STK00    res 1
    ;--------------------------------------------------------
    ; global definitions
    ;--------------------------------------------------------
    ;--------------------------------------------------------
    ; absolute symbol definitions
    ;--------------------------------------------------------
    ;--------------------------------------------------------
    ; compiler-defined variables
    ;--------------------------------------------------------
    ;--------------------------------------------------------
    ; initialized data
    ;--------------------------------------------------------
    ;--------------------------------------------------------
    ; overlayable items in internal ram 
    ;--------------------------------------------------------
    ;    udata_ovr
    ;--------------------------------------------------------
    ; reset vector 
    ;--------------------------------------------------------
    STARTUP    code 0x0000
        nop
        pagesel __sdcc_gsinit_startup
        goto    __sdcc_gsinit_startup
    ;--------------------------------------------------------
    ; code
    ;--------------------------------------------------------
    code_central_processor    code
    ;***
    ;  pBlock Stats: dbName = M
    ;***
    ;entry:  _main    ;Function start
    ; 2 exit points
    ;has an exit
    ;functions called:
    ;   _configure_pins
    ;   _configure_pins
    ;; Starting pCode block
    ;; gen.c:2261:resultRemat *{*
    ;; gen.c:2597:genLabel *{*
    ;; ***    genLabel  2600
    ;; gen.c:2261:resultRemat *{*
    ;; gen.c:2283:genFunction *{*
    ;; ***    genFunction  2285 curr label offset=4previous max_key=0 
    _main    ;Function start
    ; 2 exit points
    ;; gen.c:2261:resultRemat *{*
    ;; gen.c:2030:genCall *{*
    ;; ***    genCall  2032
    ;; gen.c:1765:saveRegisters *{*
    ;; ***    saveRegisters  1767
    ; >>> gen.c:2118:genCall
        .line    26; "/home/chris/Documents/Electronics Projects/snake/central_processor.c"    configure_pins();    
        CALL    _configure_pins
    ;; gen.c:1809:unsaveRegisters *{*
    ;; ***    unsaveRegisters  1811
    ;; gen.c:2261:resultRemat *{*
    ;; gen.c:4425:genInline *{*
    ;; ***    genInline  4426
        movlw 0xFF
        movwf PORTB
        
    ;; gen.c:2261:resultRemat *{*
    ;; gen.c:2597:genLabel *{*
    ;; ***    genLabel  2600
    ;; gen.c:2261:resultRemat *{*
    ;; gen.c:2435:genEndFunction *{*
    ;; ***    genEndFunction  2437
        RETURN    
    ; exit point of _main
    ;***
    ;  pBlock Stats: dbName = C
    ;***
    ;entry:  _configure_pins    ;Function start
    ; 2 exit points
    ;has an exit
    ;; Starting pCode block
    ;; gen.c:2261:resultRemat *{*
    ;; gen.c:2597:genLabel *{*
    ;; ***    genLabel  2600
    ;; gen.c:2261:resultRemat *{*
    ;; gen.c:2283:genFunction *{*
    ;; ***    genFunction  2285 curr label offset=0previous max_key=0 
    _configure_pins    ;Function start
    ; 2 exit points
    ;; gen.c:2261:resultRemat *{*
    ;; gen.c:4425:genInline *{*
    ;; ***    genInline  4426
        bsf status, rp0
        movlw b'11111111'
        movwf TRISA
        movlw b'00000000'
        movwf TRISB
        bcf status, rp0
        
    ;; gen.c:2261:resultRemat *{*
    ;; gen.c:2597:genLabel *{*
    ;; ***    genLabel  2600
    ;; gen.c:2261:resultRemat *{*
    ;; gen.c:2435:genEndFunction *{*
    ;; ***    genEndFunction  2437
        RETURN    
    ; exit point of _configure_pins
    ;; gen.c:6803:genpic14Code *{*
    ;    code size estimation:
    ;        3+    0 =     3 instructions (    6 byte)
        end
    

    Thanks for any help

     
  • Raphael Neider

    Raphael Neider - 2010-09-26

    How do you compile/assemble/link your project?

    Do you link against libsdcc.lib (when linking manually)?
    __sdcc_gsinit_startup is the library routine that INITializes Global as well as Static variables (not needed in your case, but should the symbol be undefined and assumed 0, you won't get to main). As a workaround, you can add your own gsinit routine:

    /* Note: only one leading underscore here! */
    void _sdcc_gsinit_startup(void) {
      __asm
        pagesel _main
        goto _main
      __endasm;
    }

    When I compile you code using sdcc 2.9.7 #5948 and gputils 0.13.7 beta, I get errors from the assembler:
    >> Symbol not previously defined (status).
    >> Symbol not previously defined (rp0).

    Why not use

    >> TRISA = 0xff;
    >> TRISB = 0x00;
    and
    >> PORTB = 0xff;

    instead of manually fiddling around with inline assembler?

    Good luck,

    Raphael

     
  • Anonymous - 2010-09-26

    Thanks for replying,

    I put in the inline assembler as a test (which obviously didn't work), because the proper C notation wasn't working either.
    I am using KTechLab's toolchain, so I'm not entirely sure what arguments it drops onto the end. I'll try and find out.
    I'll give that custom _sdcc_gsinit_startup function a go as well - thanks.

     
  • Anonymous - 2010-09-27

    Brilliant! Replacing _sdcc_gsinit_startup works perfectly!
    I'm not entirely sure why that's happening but thanks anyway :D

    Chris

     

Log in to post a comment.

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

Sign up for the SourceForge newsletter:





No, thanks