#1187 how do i create a PORTD typedef?

closed-invalid
nobody
5
2013-05-25
2006-08-21
carterson3
No

#include <pic16f877a.h>

// ----- PORTD bits --------------------
typedef union {
struct {
unsigned char :1;
unsigned char :1;
unsigned char :1;
unsigned char :1;
unsigned char LED0:1;
unsigned char :1;
unsigned char :1;
unsigned char :1;
};
} __PORTD_bits_t;
extern volatile __PORTD_bits_t __at(PORTD_ADDR)
PORTD_bits;

#define LED0 PORTD_bits.LED0

void main()
{
TRISD = 0;
LED0 = 1; //this line doesnt work...

while(1) {};
}

sdcc:
mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51/
ds400/hc08 2.6.1 #4339 (Aug 18 2006) (MINGW32)

C:\SDCC>sdcc -mpic14 -p16f877a main.c
message: using default linker
script "C:\sdcc\gputils\lkr\16f877a.lkr"
error: missing definition for symbol "_PORTD_bits",
required by "main.o"

I am trying to get SDCC to work on SBC44B from
modtronix. I got it to work a little, but dont really
have a clue how to get a PORTD typedef to work...

Thanks so much for looking. I appreciate it.
-ebay3@readynote.com (jim pruett)

Discussion

  • Raphael Neider
    Raphael Neider
    2006-08-22

    • milestone: --> non_bugs
    • status: open --> closed-invalid
     
  • Raphael Neider
    Raphael Neider
    2006-08-22

    Logged In: YES
    user_id=1115835

    If PORTD is not declared in pic16f877a.h (and thus
    PORTD_bits defined in device/lib/pic/libdev/pic16f877a.c),
    you need not only declare PORT_bits (using "extern foo;")
    but also define it (leave out the extern keyword).
    Extern tells SDCC that the symbol PORTD_bits is defined in a
    different .o file and resolved by the linker. You want to
    tell SDCC that PORTD_bits resides at PORTD_ADDR and is
    (probably) not defined elsewhere. This is not SDCC specific,
    but a common C construct...

    To cut it short: delete extern, recompile, be happy.

    Regards,
    Raphael

     
  • carterson3
    carterson3
    2006-08-22

    Logged In: YES
    user_id=1325633

    I replaced:
    extern volatile __PORTD_bits_t __at(PORTD_ADDR) PORTD_bits;
    with
    volatile __PORTD_bits_t __at(PORTD_ADDR) PORTD_bits;
    and now it says:
    c:\sdcc> sdcc -mpic14 -p16f877a main.c
    message: using default linker
    script "C:\sdcc\gputils\lkr\16f877a.lkr
    error: multiple sections using address 0x8

    -thanks tecodev, for continued help, carterson2