|
|
View previous topic :: View next topic |
Author |
Message |
YulL
Joined: 29 Sep 2004 Posts: 39 Location: Paris (France)
|
Include headers and source |
Posted: Wed Jan 05, 2005 10:24 am |
|
|
Hello,
Could you give me advices for exporting specific functions to an header file? I've tried to do it but my program doesn't work anymore...
Thanks by advance,
|
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Wed Jan 05, 2005 10:37 am |
|
|
Does your program have a compiler error? |
|
|
Guest
|
|
Posted: Wed Jan 05, 2005 1:52 pm |
|
|
no error during the compilation... |
|
|
rwyoung
Joined: 12 Nov 2003 Posts: 563 Location: Lawrence, KS USA
|
|
Posted: Wed Jan 05, 2005 2:31 pm |
|
|
Here is a sample header file, call it "myheader.h"
(By the way, I'm just typing this code in and not bothering to check it for 100% syntax correctness, it is just to give you ideas.)
Code: | #include <pic16f877a.h>
#case
#fuses WDT, HS, PUT, NOLVP
#use standard_io(A)
#use standard_io(B)
#use standard_io(C)
#use standard_io(D)
#use standard_io(E)
#define CONSTANT_A 99
#define CONSTANT_B 98
int8 globalvariable;
void InitPic(void);
// put other normal header stuff here
// now I'm going to create the actual void InitPic(void) function
void InitPic(void)
{
globalvariable = CONSTANT_A; // many more things would
// normally be done in an initi routine
}
|
Here is a sample of the one and only C module allowed in a CCS project, call it "mymodule.c"
Code: | #include "myheader.h"
void main(void)
{
InitPic(); // lives in the header file
while(1)
{
restart_wdt();
globalvariable += CONSTANT_B;
}
}
|
If you needed for example to control a 24C64 EEPROM, you could also include the header file from the device driver directory. I typically make a local copy of the appropriate device driver into the same directory as my project. That way I don't run the risk of editing the original device driver and accidentally breaking another project's code.
Typically you would add these device driver header files (which contain executable code) right after your module's header.
#include "myheader.h"
#include "my24C64.h" _________________ Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month! |
|
|
jds-pic
Joined: 17 Sep 2003 Posts: 205
|
|
Posted: Wed Jan 05, 2005 3:22 pm |
|
|
folks,
my experience with #include'ing header and source files using CCS C has been very good; in fact, besides using it for header files and similar, i really like the feature for it's ability to hide away code which would ordinarily clog up portions of your application's essentials. for example,
Code: | void main() {
int result=DELAY_COMPLETE;
int firstpass=TRUE;
internal_eeprom(INCREMENT16, EEPROM_RESET, DONT_CARE);
if (internal_eeprom(READ16, EEPROM_FW_VER, DONT_CARE) != (int16)FW_VERSION ) {
internal_eeprom(INCREMENT16, EEPROM_FLASH_UPD, DONT_CARE);
internal_eeprom(WRITE16, EEPROM_FW_VER, (int16)FW_VERSION);
}
#include "widget-reader-ioreg.h" // configure register and timing control defs
OUTPUT_LOW(PIN_PGM); // ensure LVP is disabled
lcd_preinit();
lcd_init();
while(TRUE) {
sleepnow: // that awful philw influence... :*)
pushbutton_flag=FALSE;
firstpass=TRUE;
// ...snip
|
as you can see from the above, i've used an #include to go and bring in all of my timing and control setup function calls. these hardly ever change once you have them right, and from then on you don't need dozens of lines clouding up the real work. note that the way the CCS application works, the "preprocessor" simply inlines the #include'd file at exactly the point that you've defined. using #include in this manner makes it possible to avoid having huge monolithic PIC source files.
to the original poster, please observe there is a difference between
Code: |
#include "lib-onewire.h"
|
and
Code: |
#include <lib-onewire.h>
|
the first one fetches the file from the current working directory, the other fetches the file from the system's defined search path. in the CCS IDE, you define the latter via the menu pull down Options->Include Dirs.
this disparity is a common cause of #include problems.
jds-pic |
|
|
YulL
Joined: 29 Sep 2004 Posts: 39 Location: Paris (France)
|
|
Posted: Mon Jan 10, 2005 4:42 am |
|
|
thanks for the answer, I didn't test it again, but I understand |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|