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.
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); }
Thanks...! I was pretty sure I remembered reading that somewhere in the C166 manual, but I didn't find that text when I went back and looked for it. Your suggestion will probably work just fine for what I want to do. Thanks again, Dave.