Ralph Doncaster schreef op 2021-03-06 18:47:
On Sat, Mar 6, 2021 at 1:12 PM Maarten Brock <sourceforge.br...@dse.nl> wrote:

Ralph Doncaster schreef op 2021-02-18 16:33:
> If I have an sbit defined as follows:
> __sbit __at (0x90) LED;
>
> How can I get the address?  When I try &LED, I get an error:
> error 35: '&' illegal operand, address of bit variable
>
> I need the address for a function that will configure the GPIO to
> push-pull mode.  I can hack it with some inline assembler:
> __asm
> mov dpl, #_LED
> lcall _pushPull
> __endasm;
>
> Is there a way to do it in C?

On which MCU are you trying to do this? And what will pushPull do with
that address?
On most mcs51 derivatives all SFRs are in direct space only and cannot
be accessed indirectly.

Maarten

This is for mcs51, and the specific MCU is a CH552.

Here's my pushPull function:

// set GPIO to push-pull mode
inline void pushPull(uint8_t pinaddr)
{
    if (pinaddr >= 0xB0 && pinaddr < 0xB8)
        P3_MOD_OC &= ~(1 << (pinaddr - 0xB0));
    else if (pinaddr >= 0x90 && pinaddr < 0x98)
        P1_MOD_OC &= ~(1 << (pinaddr - 0x90));
}

Ok, I understand your wish. Maybe we could allow taking the address of an
sbit and performing pointer arithmetic on it. Your code as-is would not
suffice.
But until we support __bit / __sbit generic pointers, we should not support
casting it to a generic pointer (or even to an integer).

For now SDCC just does not support pointers to sbit.

It might be easier for you to write to P1_MOD_OC and P3_MOD_OC directly. It
will give smaller code as well.

Maarten


_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to