Nested #if defined error in MPLAB C18

Status
Not open for further replies.

deweyusa

Member
Here's a weird error that perhaps is just my misunderstanding of the MPLAB C18 compiler. When I try to put a Nop() between two nested "#if defined" instructions, I get a syntax error on the line of the Nop(). However, if I put the Nop() after the second "#if defined", everything compiles fine. Why? I tried to add curly brackets around the second "#if defined", but it didn't help.


#if defined(__18CXX)
Nop(); //error
#if defined(HI_TECH_C)​



#if defined(__18CXX)
#if defined(HI_TECH_C)
Nop(); //okay
 
Last edited:
Your not using that right

Code:
#include p16f877a.inc
  #define AlternateASM  ;Comment out with ; if extra
                        ;features not desired.
  #ifdef AlternateASM
MyPort equ PORTC        ;Use Port C if AlternateASM defined.
MyTris equ TRISC        ;TRISC must be used to set data
                        ;direction for PORTC.

  #else
MyPort equ PORTB        ;Use Port B if AlternateASM not defined.
MyTris equ TRISB        ;TRISB must be used to set data
                        ;direction for PORTB.

  #endif

  banksel MyTris
  clrf    MyTris        ;Set port to all outputs.
  banksel MyPort        ;Return to bank used for port.
  movlw   55h           ;Move arbitrary value to W reg.
  movwf   MyPort        ;Load port selected with 55h.
end

Or this
Code:
  #include p16f877a.inc   ;Include standard header file
                          ;for the selected device.

  area  set  0            ;The label 'area' is assigned 
                          ;the value 0.
  #define lngth  50H      ;Label 'lngth' is assigned
                          ;the value 50H.
  #define wdth   25H      ;Label 'wdth' is assigned
                          ;the value 25H
  area  set  lngth*wdth   ;Reassignment of label 'area'.
                          ;So 'area' will be reassigned a
                          ;value equal to 50H*25H.

  #undefine  lngth        ;Undefine label 'lngth'.
  #undefine  wdth         ;Undefine label 'wdth'
  #define    lngth  0     ;Define label 'lngth' to '0'.

end
 
Thanks for the reply Burt. I'm afraid I'm confused though. What do you mean? The compiler won't allow another statement before a "#if defined" nested inside another one?
 
Think of this like this, A define is before code because your defining the code that to be used.

A "nop" is the smallest line of code you can write. The compiler uses defines to make name changes to code it has no need of a nop in there.
Code:
define  Big_chip (18Fxxx) // these are for the compiler  

define Little_chip (16Fxxx)  // not the pic 

// I want a little chip

if Little_chip;  //this would use Little_chip
nop;            // this is used for timing in code space
//more code here
 
Last edited:
My first thought is that if you're using MPLAB C18 compiler that the reason this isn't working is because HI_TECH_C probably isn't defined, so it isn't even trying to compile the Nop();

What do you get if you try
Code:
Nop();
#ifdef __18CXX
     #warning __18CXX is defined
  #ifdef HI_TECH_C
     #warning HI_TECH_C is defined
  #endif
#endif
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…