On Mon, Aug 27, 2012 at 11:50 AM, David wrote: > I have a bunch of .c/.h files which make up libraries for different > devices. So in my main code, I can #include "widgit.h". > > To allow changing pins around easily I #define WIDGIT_OUT LATC1 in the > header file. Right now I just include copies of the .c/.h in the > project and modify the widgit header file to move pins. > > I am trying to get to a point where I can store all libraries in one > folder and change pins in my main code. This allows easier source > control and sharing of libraries between projects. > > I thought this should work: > > // In main.c > #define WIDGIT_OUT LATC1 > #include "widgit.h" > > // In widgit.h > #ifndef WIDGIT_OUT > #warning Output pin not defined! > #endif > /* #define WIDGIT_OUT LATC1 <-- Now in main.c */ > > But it appears that this doesn't work. I get errors from widgit.c about > WIDGIT_OUT being an undefined identifier, using #ifndef/#warning in > widgit.h also prints the message. > > So I'd like to know if: > > 1) The above should work, but I'm doing something wrong. > > 2) What ways people use to write reusable code. > > You have the right idea, header files are the way to go. Make sure they're being found by your compiler, and make sure that they're the FIRST header found (as in, make sure that another header file with the same name isn't overriding the one you want). Always use #ifndef/#define/#endif to wrap your headers to prevent them from being defined more than once. Post your full source so we can see if its correct or not. --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .