This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Easy changeable pin definition

Hello,

I am writing some librarys to controll components connected to the MSP. Now I have configured the pins like this: P3OUT |= PIN4. This works fine, but it is not very comfortable. If someone decides to change the layout, I would have to go all over my code to correct the pins. Is there a easy solution how I could keep the pin mapping flexible?

Thank you.

Greetings

Reto

  • Hi Reto,

    you can always of course use the C-preprocessor and define the port and pin number as macro, for example:

    #define POUT_REG_OUTPUT    P3OUT

    #define PIN_OUTPUT         PIN4

    then in all your code you use

    POUT_REG_OUTPUT |= PIN_OUTPUT;

    then if you need to change the port and pin number, you can just change the macros above.

    Hope this helps.

**Attention** This is a public forum