Hello!
In the Test.Lib Library I am creating a function, which set a specific port and pin. The port and pin must be defined in the project to which i have added Test.Lib
In Library Project, I have Test.C
Test.C ======= extern char Port; extern bit pin; void func(unsigned char ch, bit bt) { Port = ch; pin = bt; }
the Test.Lib is successfully compiled and generated the .Lib file. Now I added this .Lib file to my working project. The main file look like this.
main.c ======
#define Port P1 sbit pin = P0^0;
void func(unsigned char ch, bit bt); //Prototype
void main(void) { func(0x55,1); while(1); }
It doest not set the desired values to Port and Pin. Please help me in this regard.
Thanks. with regards. SAJJAD
Note that the processor doesn't support indexed addressing of bits.
So they only possibility of a library function to manage this is if the linker can create the assembler instruction based on the declaration in the program.
Are you sure that the Keil linker do support generating the processor instruction for the port pin during the linking stage?
If not, then you will just have to teach your library to figure out which port to set a bit for and perform a normal OR operation on the corresponding 8-bit register.
But the interesting question here is: Why do you think you have a need of having a library (which normally contains generic functions applicable to multiple projects) that is expected to perform target-specific actions? Don't you think it would be better if your project contains the code for setting the bit?
You are right. But think of developing Library for 8-bit Alpha Numeric LCB. One should have flexiblity of assigning D0-D7, Rs, Rw, E, to different pins of microcontroller. How to do that.
You say "one should have" as if talking about human rights.
But what is your view on the fact that the processor doesn't support indexed access to bit variables, and that the C language was designed for code generation by the compiler - not the linker? That Keil performs some of the code generation in the linker is a nice work-around to processor limitations but shouldn't be seen as any "right" you have.
I have already told you of possible workarounds - having the library function know the different port 8-bit registers and perform logic OR to set a bit or NOT + AND to clear a bit. Or have your program contain functions to set and clear the signals and have the library call these functions in your program. Since the displays are normally slow and requires delays, it shouldn't matter too much that the workarounds requires extra machine cycles compared to inlined operations.
You could always develop it as a source "library"...
"have your program contain functions to set and clear the signals and have the library call these functions"
For an example of this, see how the C51 implementation of the library function printff uses the basic IO funtions:
http://www.keil.com/support/man/docs/c51/c51_printf.htm http://www.keil.com/support/man/docs/c51/c51_ap_basicio.htm