Topic : define port from my project

Forum : 8051

Original Post
Post Information Post
August 15, 2012 - 5:59pm
Guest

I created the LIB file with define PORT
Then, I created a project and i add the LIB file to project
and it work

How can I define the PORT from my project
When the PORT run from the LIB file

Replies
Post Information Post
+1
0
-1
August 16, 2012 - 6:05pm
Raisonance Support Team

Hello,

Could you please clarify what you mean by "define the PORT"?

I imagine several possible things it could mean. (#define, global variable, symbol for peripheral register, etc.)

Best Regards,

Vincent

+1
0
-1
August 17, 2012 - 4:20pm
Guest

example
sbit X=P1^1;

+1
0
-1
August 20, 2012 - 1:57pm
Raisonance Support Team

Hello,

Just put this in the header (.h) file, not in the C (.c) file.

And of course include the header file in the other files of the project, not just in the files of the library.

Best Regards,

Vincent

+1
0
-1
October 7, 2012 - 5:50pm
Guest

A little late, but if i create lib example

c file
#include

void fun1(void)
{
x=0;
}

h file
#include
void fun1(void);
sbit x=P1^7;

and i had the file.lib in my project

c file
#include

#include

void main(void)
{

while(1)
fun1();
}

and h file with another define P1.0
#include
void fun1(void);
sbit x=P1^0;

I get P1.7 when I want change from my project P1.0

+1
0
-1
October 7, 2012 - 6:14pm
Guest

A little late, but if i create lib example

c file
#include

void fun1(void)
{
x=0;
}

h file
#include
void fun1(void);
sbit x=P1^7;

and i had the file.lib in my project

c file
#include

#include

void main(void)
{

while(1)
fun1();
}

and h file with another define P1.0
#include
void fun1(void);
sbit x=P1^0;

I get P1.7 when I want change from my project P1.0

+1
0
-1
October 8, 2012 - 10:31am
Raisonance Support Team

Hello,

If you get P1.7 for sbit x rather than P1.0, it means that the last definition reached by the compiler while reading the include files defines x as P1.7
To resolve your problem, be careful with the include file order.

Regards,

St├ęphane

+1
0
-1
October 8, 2012 - 6:21pm
Guest

I get definition from lib file only
when I want from my project

+1
0
-1
October 9, 2012 - 10:06am
Raisonance Support Team

.lib files are used on link, not on compilation.

So there is probably a .h file (likely related to the lib) that you include in your project's files and that contains the lib's definition of x.

You should place the lib's definition in a h file that is included in the sources of the lib but _not_ in the sources of the calling project.