Menu

#IF statement in macro problem

2015-06-06
2015-06-06
  • Jacques Nilo

    Jacques Nilo - 2015-06-06

    Hi all
    I am wondering why the following test program returns 5 and not 6...
    Any suggestion/workaround are welcome !
    Jacques

    ;Chip Settings
    #chip 16F1509, 8
    
    'Config UART
    #define USART_BLOCKING true
    #define USART_BAUD_RATE 19200
    
    ;Defines (Constants)
    #define LCD_IO 4
    #define LCD_RS PORTC.5
    #define LCD_NO_RW
    #define LCD_Enable PORTC.4
    #define LCD_DB4 PORTC.0
    #define LCD_DB5 PORTC.1
    #define LCD_DB6 PORTC.2
    #define LCD_DB7 PORTC.3
    
    macro PPSMapIn(in Periph_Input,in inPPS)
    #define Periph_Input
    #define xxxPPS inPPS
    #ifdef Periph_Input "RB5"
     xxxPPS=5
    #endif
    #ifdef Periph_Input "RB6"
     xxxPPS=6
    #endif
    end macro
    
    cls
    PPSMapIn("RB5",RXPPS)
    print RXPPS
    
     

    Last edit: Jacques Nilo 2015-06-06
  • Anobium

    Anobium - 2015-06-06

    This is because of the process order of GCB- ifdefs are processed first then are resolved then processing continues. (I stand to be totally correctly by Hugh). :-)

    I would change to a sub with parameters - macros will also create more inline code, again recommend using subs unless speed is your real issue. change the ifdef to if then.

    Evan

     
  • Jacques Nilo

    Jacques Nilo - 2015-06-06

    I was trying the macro route because I was trying to generate a variable name dynamically and then assign a value to it according to the pin input.
    I am thinking about the most efficient way to create a pps library that is missing today.
    PPSMapIn(pin,fn) would assign function fn (CCP1,CCP2,RX,...) to the pin given as parameter (RA0,RA1,...)
    Likewise for PPSMapOut

     

    Last edit: Jacques Nilo 2015-06-06

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.