- Mon Apr 18, 2011 8:22 am
#125652
Pretty simple requirement with same issue I keep coming across.
I create libraries in another shared folder for functions and libraries such as LCD screens, SPI, I2C etc... which contain .h and .c files in a library folder. These create the functions that are generic for use across projects, so for a simple example think of an SPI.c file that needs to know the pin to use as a CS pin. This would be done as
#define CS _LATB14
for example. Now if this was in the main.c file (main code file), and the main code file has an include to the SPI.h file, and then calls the SPI function within spi.c file that looks for a CS defined, then when you compile the spi.c file cannot find any definition for CS.
How would I get around it so I don't have to constantly copy/paste the library files and modify defines within those files directly.
spi.h
==============
void SPIFunction();
spi.c
==============
void SPIFunction()
{
CS = 1;
}
main.c
==============
#define CS _LATB14
#include "spi.h"
int main()
{
SPIFunction();
return 0;
}
I create libraries in another shared folder for functions and libraries such as LCD screens, SPI, I2C etc... which contain .h and .c files in a library folder. These create the functions that are generic for use across projects, so for a simple example think of an SPI.c file that needs to know the pin to use as a CS pin. This would be done as
#define CS _LATB14
for example. Now if this was in the main.c file (main code file), and the main code file has an include to the SPI.h file, and then calls the SPI function within spi.c file that looks for a CS defined, then when you compile the spi.c file cannot find any definition for CS.
How would I get around it so I don't have to constantly copy/paste the library files and modify defines within those files directly.
spi.h
==============
void SPIFunction();
spi.c
==============
void SPIFunction()
{
CS = 1;
}
main.c
==============
#define CS _LATB14
#include "spi.h"
int main()
{
SPIFunction();
return 0;
}