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

Creating and Using Libraries

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

Parents
  • 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?

Reply
  • 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?

Children