1
\$\begingroup\$

I am using the HI-TECH C compiler for the PIC16 Microcontroller, and I would like to conditionally compile different chunks of code depending on which specific microcontroller has been selected.

I know you can conditionally compile code with something like:

#if defined(MACRO1)  
    ... compile this code ... 
#elif defined(MACRO2) 
    ... compile this code ...
#endif

What I need to know is what pre-defined macros are available in the HI-TECH C compiler that will let me select on the specific microcontroller?

\$\endgroup\$
  • \$\begingroup\$ That depends on which toolchain you're using. \$\endgroup\$ – Majenko Sep 12 '11 at 18:02
  • \$\begingroup\$ I am using HI Tech C compiler. \$\endgroup\$ – rashid Sep 12 '11 at 18:06
4
\$\begingroup\$

Page 98 of the HITEC C Manual lists all the pre-defined macros.

One of the entries is:

_CHIPNAME To indicate the specific chip type selected, e.g., _16F877

so you have, as other examples:

  • _16F88
  • _16F84A
  • _16F505
  • _16F777
  • _16F1823
  • ...

etc.

\$\endgroup\$
1
\$\begingroup\$

If you asking about conditionally compiling code for different PICs using the defined name, you can use the predefined _CHIPNAME macro mentioned on page 106 of the 9.81 manual.
Or you can use the family (e.g _PIC12, _PIC14, _PIC14E as mentioned in the same table) or simply define your own.

\$\endgroup\$
0
\$\begingroup\$

It seems like you want conditional assembly (or compilation) depending on the target chip, although your example is somewhat unclear. I don't think you can put DEFINE in the target of a #IF as in your first case, and you appear to be testing for the same thing in both cases.

In any case, there is a symbol defined for the specific PIC model number as specified on the MPASMWIN command line or with the LIST directive. The model-specific include files have a check in them to make sure the right model is selected to match the include file. You can therefore write:

#ifdef __18f2520
     ;code here is only included when target is PIC 18F2520
  #endif
\$\endgroup\$
  • 1
    \$\begingroup\$ I think that's a typo. If you read the entire code snippet you'll see the second one is defined(...) which is perfectly valid. \$\endgroup\$ – Majenko Sep 12 '11 at 18:30
  • 1
    \$\begingroup\$ And the "pic16macro" is a placeholder for the target of the question: "what should the OP be putting in there?" \$\endgroup\$ – Majenko Sep 12 '11 at 18:34
  • \$\begingroup\$ @Majenko: The original question was very poorly written so that it was a bit confusing. I see Kevin has now fixed this, and added the very important information that HITECH C is being asked about. I am not familiar with that compiler, so I thought there might have been relevance to DEFINE in one place and DEFINED in another. You really don't expect two errors in a 4 line example specifically written to illustrate your question. Couldn't the OP have bothered to proofread what he wrote!? \$\endgroup\$ – Olin Lathrop Sep 12 '11 at 19:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.