This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Conditional compilation

Hi,

I am currently trying to get my code support two different type of LCD display, the only difference is the hardware level driver, so condional compilation directive has to be introduced.

#ifdef DISPLAY_1
void display_driver()
{
// do one thing
}
#else
void display_driver()
{
// do another thing
}
#endif

However I don't want change the directive in the code, I would like to do it in the IDE,
I guess it should be under project\option\C51, any one know how to do it ? Thanks in advance.

Daniel

Parents
  • "It's often useful to have a positive check to be sure that someone actually selected a driver option, rather than just falling into an else clause due to lack of a choice."

    Very good advice.

    #define LCD_TYPE_0 0
    #define LCD_TYPE_1 1


    While we're on the subject of Defensive Programming, values 0 and 1 are best avoided - as these are prime candidates for default values if something is just defined without actually being assigned a proper value (eg, on a command line).

Reply
  • "It's often useful to have a positive check to be sure that someone actually selected a driver option, rather than just falling into an else clause due to lack of a choice."

    Very good advice.

    #define LCD_TYPE_0 0
    #define LCD_TYPE_1 1


    While we're on the subject of Defensive Programming, values 0 and 1 are best avoided - as these are prime candidates for default values if something is just defined without actually being assigned a proper value (eg, on a command line).

Children