CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Multiple conditional compile

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ljmnunes



Joined: 02 Sep 2004
Posts: 13
Location: Brazil

View user's profile Send private message

Multiple conditional compile
PostPosted: Fri Jun 13, 2008 1:32 pm     Reply with quote

Hello!

After many years programming PICs I need to join four source codes in one to equalize versions.

I have four separate sources with the same working core in four hardware, with tree PICs: 16F873A, 16F876A and 18F252. The main differences are in I/O numbers and types.
Every time I make a change, I wrote it in four different files to test and debug it four times!... Sad

So, I want to use conditional compile, but is a bit complex because I´ll need many #ifdef .

See this example:

Code:
#ifdef  TC1206
    #include    <16F873A.h>
    #include    "TControl_1206_Defines.h"
    #include    "PIC16F873_registers.h"
#endif

#ifdef  TC1200
    #include    <16F873A.h>
    #include    "TControl_1200_Defines.h"
    #include    "PIC16F873_registers.h"
#endif

#ifdef  TC1107
    #include    <16F876.h>
    #include    "PIC16F876_registers.h"
    #include    "TControl_1107_Defines.h"
#endif

#ifdef  TC1107A
    #include    <18F252.h>
    #include    "PIC18F252_registers.h"
    #include    "TControl_1107_Defines.h"
#endif


Can I this code instead?
Code:

#ifdef  (TC1107 + TC1107A)       // <<<<<<< To use with TC1107 e and TC1107A
    #include    "TControl_1107_Defines.h"
#endif

#ifdef  TC1107
    #include    <16F876.h>
    #include    "PIC16F876_registers.h"
#endif

#ifdef  TC1107A
    #include    <18F252.h>
    #include    "PIC18F252_registers.h"
#endif


If isn´t possible, there are an alternative?

Thanks in advance.

Laercio
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jun 13, 2008 4:33 pm     Reply with quote

Use the #if directive, and then use logical operators inside the expression.
Example:
Code:
#include <18F452.h>
#fuses XT,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=4000000)

#define TC1107 TRUE
#define TC1107A FALSE

// If either one of the "TC1107" values is true, then #include the file.
#if (TC1107 || TC1107A)     
  #include "TControl_1107_Defines.h"
#endif

//=============================
void main()
{



while(1);
}
ljmnunes



Joined: 02 Sep 2004
Posts: 13
Location: Brazil

View user's profile Send private message

PostPosted: Fri Jun 13, 2008 5:35 pm     Reply with quote

Thanks,

I´ll try it tomorrow.

[]s
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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