Menu

#Define Problem

jackjames
2016-08-05
2016-08-08
  • jackjames

    jackjames - 2016-08-05

    Hi,
    I have the following problem with #Define:
    I have to define a pin depending on the configuration of the program.
    Let me explain helping me with the sample program I have attached.
    This pin changes depending on whether the program should work in a serial configuration or I2C.
    So I create some #define that assemble me the required program sections.
    In the attached program, the compiler always recognizes PORTB.0 instead of PORTB.2 that should be recognized with #define setup.
    The compiler is the last version.
    Ciao.

    Giacomo

    '       Definizione micro e clock
            #Chip 16F628A, 4
    
    '       Configurazione fuses
            #Config INTRC_OSC_NOCLKOUT, BODEN_OFF, MCLRE_OFF
    '
    
            #Define LED1     PORTA.6  ' Pin led
    '       ------------------------------------------------------------------------
            #Define MOD_I2C  ' Modalita I2C.    
    '       #Define MOD_SER  ' Modalita seriale.
    '       ========================================================================
    
            #IfDef MOD_SER
               #Define T_PR PORTB.0
            #EndIf
    
            #IfDef MOD_I2C
               #Define T_PR PORTB.2
            #EndIf
    
            TRISA = 0
            TRISB = 0
    
            Do ForEver
               Set T_PR On
               Set LED1 On
               Wait 1 s
               Set T_PR Off
               Set LED1 Off
               Wait 500 ms
            Loop
    
     
  • Anobium

    Anobium - 2016-08-05

    Hi. Define cannot be used within the #ifdef. Use script instead and this will work as expected. Remember, to a constant use use T_PR = Portb.0. Look at glcd.h for extensive use of script in the same context.

     

    Last edit: Anobium 2016-08-06
  • jackjames

    jackjames - 2016-08-08

    You are always polite and helpful.
    Thank you.

     

Log in to post a comment.