Jump to content
Sparky1039

Conditional Compile Explanation

Recommended Posts

Simple question. I do I go about performing a conditional compile to code within “void main ()” ?

For code development I’m switching between two processors, one real hardware, other in Proteus simulation i.e. F67J11 and F67K22 respectively. Proteus lacks a 67J11 model so I’m using the 67K22 as a close substitute for my testing. The biggest difference between the two in my application is how the ADC registers are set up. The “J” part requires writing to a secondary SFR to set the ANCONx registers, where as the “K” part has no secondary SFR but has a 3rd ANCONx register.

I know #ifdef is applied for things like “pragmas” and such outside void main for conditional compilation, but I’m unsure how to apply a similar process to SFR register config’s within in void main (or other functions). Any explanation would be appreciated.

thx

Edited by Sparky1039

Share this post


Link to post
Share on other sites

Sparky1039,

Simple question. I do I go about performing a conditional compile to code within “void main ()” ?

For code development I’m switching between two processors, one real hardware, other in Proteus simulation i.e. F67J11 and F67K22 respectively. Proteus lacks a 67J11 model so I’m using the 67K22 as a close substitute for my testing. The biggest difference between the two in my application is how the ADC registers are set up. The “J” part requires writing to a secondary SFR to set the ANCONx registers, where as the “K” part has no secondary SFR but has a 3rd ANCONx register.

I know #ifdef is applied for things like “pragmas” and such outside void main for conditional compilation, but I’m unsure how to apply a similar process to SFR register config’s within in void main (or other functions). Any explanation would be appreciated.

thx

In you code make sure you use #include<system.h> in your source files, this will then include the appropriate header file for the device you select.

 

You can conditionally compile code for each target using the following:

void foo()
{

#ifdef _PIC18F67J11
// code and register use specific to PIC18F67J11
.....
#else
// code and register use specific to the other device
.....

#endif

}

 

or

 

 

void foo()
{

#ifdef _PIC18F67J11
// code and register use specific to PIC18F67J11
.....
#endif

#ifdef _PIC18F67K22 
// code and register use specific to PIC18F67K22 
.....
#endif

}

 

or

 

#ifdef _PIC18F67J11

// function when using PIC18F67J11
void foo()
{
...
}

#endif

#ifdef _PIC18F67K22 

// function when using PIC18F67J11
void foo()
{
...
}

#endif

 

I hope that helps.

 

Regards

Dave

Share this post


Link to post
Share on other sites

Thanks Dave, yes this helps clarify things greatly.

I suspected as much that it was only a matter of including the #ifdef’s - #endif's in the code body, and I tried that but it failed to work. What I didn’t realize was the need for an underscore in front of the target device name. Once added it worked like a champ.

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...