View previous topic :: View next topic |
Author |
Message |
ljmnunes
Joined: 02 Sep 2004 Posts: 13 Location: Brazil
|
Multiple conditional compile |
Posted: Fri Jun 13, 2008 1:32 pm |
|
|
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!...
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 |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jun 13, 2008 4:33 pm |
|
|
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);
} |
|
|
![](templates/subSilver/images/spacer.gif) |
ljmnunes
Joined: 02 Sep 2004 Posts: 13 Location: Brazil
|
|
Posted: Fri Jun 13, 2008 5:35 pm |
|
|
Thanks,
I´ll try it tomorrow.
[]s |
|
![](templates/subSilver/images/spacer.gif) |
|