methods setting up Projects under Hi-Tech C and MPLab (advanced
When it comes to compiling files under Hi-Tech C, there are two methods of doing it. One method is to have a single main.c file, and use #include for all the .c files in the project. Call this the 'one file with multiple #include of c files' method.
The second method, also the one usually recommended by C programmers, is to have lots of individual .obj files, and link them at the end. Call this the 'lots of .obj files' method.
For the 'one giant file' method, in MPLab under 'node properties', select 'PIC C compiler' for the root node. For the 'lots of .obj files' method, select 'PIC C linker' for the root node.
The advantages of the 'one file with multiple #include of c files' method
Produces smaller .hex file for a large compiled program. For the 16F876/7, there is 8k of program, divided into 4 pages. A psect cannot cross a page boundary. Sometimes there is wasted space before the end of each page boundary. Because the linker has access to all the functions at once, it does a really good job of fitting them in. Try it yourself - get a large (~8k, ~5000 line) program, and it will be smaller using this method.
advantages of the 'lots of .obj files' method
What do you think? email email@example.com.
I think that one giant file should be used when there is space problems only. I prefer 'lots of obj files' method. This makes my life easier. I can distribute my functions in different files depending on their purpose. And if something is lost, the rest is still available.
There is a third method between 'giant file' and 'lots of obj files': One main file which #includes lots of source files. This method serves good input to the linker while the programmer still has the opportunity to divide source code by the purpose.
But there is no good things without bad things. Try to simulate that code in MPLAB. MPLAB does not want to switch to the included sources. It traces only main #including file.
We welcome any suggesions or comments! Send them to Shane Tolmie on firstname.lastname@example.org. This site is a completely separate site to www.microchip.com, and is maintained independently of Microchip Ltd., manufacturers of the PIC micro. All code on this site is free for non-commercial use, unless stated otherwise. Commercial use normally free, however, it is prohibited without contacting email@example.com for permission. All content on this site created by Shane Tolmie is copyrighted by Shane Tolmie 1999-2009. Click to advertise on this website - $29.90 for a banner ad which will reach 55,000 user sessions per month. One months free trial!