I want to give a particular portbit a name, that I can use across multiple sourcefiles. To make portable code, I prefer to avoiding physical addresses. The only a approach I have been able to think of, is this:
foo.c: #include <C8051F120.h> // register definition file #include <foo.h> bdata unsigned char test; sbit bit1 = test^3; sbit bit2 = 0xB3; // P3 has address 0xB0, ie. it is bitaddressable sbit bit3 = P3^3; foo.h: extern bit bit1; extern bit bit2; extern bit bit2; bar.c #include <C8051F120.h> // register definition file #include <foo.h> void myfunc(void) { bit1 = 1; bit2 = 1; bit3 = 1; }
It works fine for bit1 and bit2, but bit3 results in a linker warning “Reference made to unresolved external”. As sfr addresses, ending with 0 or 8 are byte- and bit addressable, I wonder why Keil complains about this, when the sbit in test can be handled.
Any alternative solutions?
Thanks, Glenn