This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Syntax? "sbit * ptr2sbit;"

Is it possible using the C16x tools to create a variable that's a pointer
to an sbit? I'm trying to find a way to allow a function in a custom
library to not need to know where an I/O pin is until the user of the
library informs it via a library initialization function call.

For example, if there was a blink LED function, where that LED was on a
different I/O port pin on different pcbs, the user of the library could
inform the library function where the I/O pin was, by passing it the
address of the sfr bit. It seems to me that in order to be able to make
this work, I need to be able to create a "pointer to sbit" type of variable
in my library.

Help,
Dave.

Parents
  • As it is said in C166 compiler description, pointers to bits are not supported (which is easy to understand: there are no such instructions in C166/C167 instruction set). It seems that the only way to do what you want is to pass to the library function address of I/O port and bit number. For example:

    void SetPortBit(int* PortAddress, int BitNumber)
    {
    *PortAddress |= (1 << BitNumber);
    }

    void main(void)
    {
    DP2 = 0xFFFF;
    SetPortBit(&P2, 15);
    }

Reply
  • As it is said in C166 compiler description, pointers to bits are not supported (which is easy to understand: there are no such instructions in C166/C167 instruction set). It seems that the only way to do what you want is to pass to the library function address of I/O port and bit number. For example:

    void SetPortBit(int* PortAddress, int BitNumber)
    {
    *PortAddress |= (1 << BitNumber);
    }

    void main(void)
    {
    DP2 = 0xFFFF;
    SetPortBit(&P2, 15);
    }

Children