Hi Peter,

> If I allow the linker to assign the location:
> lcd_t lcd;
> everything compiles fine.  The lcd structure, is of course, not at the 
> port address. If I
> volatile lcd_t __at (PORTB_ADDR);
> I get an error saying "multiple sections using address 0x6"
> 
> But, I can declare:
> __sfr PORTB;
> _PORTB_bits_t PPORTB_bits;
> and use them as expected.
> 
> What I don't understand (among a quadzillion things) is why can I use 
> PORTB and PORTB_bits and not get that error, but if I use lcd to refer 
> to port b bits, I get the above error. ggggrrr!!

PORTB and PORTB_bits are declared in the same .c file (pic16fXXX.c), so 
they get allocated into the *same* section for the linker to place. If 
you add another object at the same address in your .c (myproject.c), it 
ends up in a *different* section that is to be placed at the same 
address already occupied by the section containing PORTB and PORTB_bits.


Preprocessor to the rescue: Use the beautiful and quite intuitive =:-]

#define lcd (*(volatile __data lcd_t *)(PORTB_ADDR))

void
main (void)
{
     lcd.rs = 1;
     if (lcd.e) {
         lcd.d = 1;
     } // if
}

to get where you want, though the code is considerable larger than when 
accessing PORTB_bits. There is still a lot of optimization potential.

Alternatively you could file a feature request with the gputils team to 
add an option to allow overlapping sections. SDCC cannot do anything 
about this problem.

Regards,
Raphael

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to