how do you take code out of the main file, and make it a library? In assembler, it would be a simple include directive, and nothing special need be done to the code that was snipped and exported, but this seems not to be the case in C. I developed a complete chip init as a series of procedures, and put that in a file called init.c, and used: include "init.c" in the main file, but the compiler is telling me that within init.c, the port names are undefined. For the equivilent of the Assembler "include" directive (a source-level "library", so to speak), the #include in C is the correct equivilent. However, you must make sure that this happens AFTER all the symbols that are referenced in the inlcude file are already defined. Your code probably contains something like: #include "init.c" #include cpu_pic16f84.h contains all the processor specific port names and such, and since it is included AFTER init.c, init.c doesn't get to use them. (Assemblers can be a bit more relaxed about this because they're used to using multiple passes to resolve defintion issue like this.) The easiest solution is to make sure your own "library" files come after the "main" definition files: #include #include "init.c" A BETTER solution is to make sure that all included files are "self compiling", meaning that they always include all the definitions that they need, so init.c would look like: #include init() { /* * initialization */ } In order for this to work well, all the ".h" files should be self-compiling and automatically able to handle multiple inclusions as well. This is usually done using a construct like the following: init.c: #idndef INIT_C_INCLUDED /* If we haven't been included yet */ #define INIT_C_INCLUDED 1 /* mark us as included */ #include /* get processor specifics */ init() { /* etc */ } /* the code */ : #endif /* INIT_C_INCLUDED */ cpu_pic16f84.h: #ifndef CPU_PIC16F84_INCLUDED /* included yet ? */ #define CPU_PIC16F84_INCLUDED 1 /* nope - do it! */ #define PORTA .... #endif /* CPU_PIC16F84_INCLUDED */ Chances are that the .h files supplied with your compiler already do something like this, and you should probably copy their style for the sake of consistancy. Note the DISADVANTAGES of the self-compilable option. I can imagine an includable init.c that is carefully processor-independent and relies on a previous inclusion of the appropriate CPU_whatever file to generate correct code for the actual target processor. In that case, you just have to be careful of your include file ordering (which tends to quickly become a pain) and document the issue. The include hierarchy of a large system can be mind-boggling, and large system utilities (compilers, make utilities, etc) can contain special case code to optimize the self-compilable include files so that the preprocessor doesn't actually have to read the file a dozen times if it ends up included a dozen times... There are also LINK time libraries commonly used with high level languages (and sometimes with assemblers, as well.) In this case, you can compile a bunch of C files (usually containing not much more than one "externally visible) function per file) to produce object (.o, usually) files, and use a library utility of some kind to merge these into a searchable library file(s) (.a, perhaps) Something like: cc -c init.c -o init.o cc -c rs232.c -o rs232.o ar -s init.o rs232.o -o picutils.lib This way you can avoid the (CPU intensive, not that it's likely to be a big issue for microcontroller sized applications) compile of your (known good) utilities each time you compile your (new, unproven) program: cc seriallcd.c picutils.o Exact details depend on the compiler, linker, and library utilities in use. (the above examples are highly "native unix" biased, probably.) BillW -- http://www.piclist.com hint: PICList Posts must start with ONE topic: "[PIC]:","[SX]:","[AVR]:" =uP ONLY! "[EE]:","[OT]:" =Other "[BUY]:","[AD]:" =Ads