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.

PORT and PIN C Macro

Guru 12050 points

Replies: 1

Views: 634

mspware does have functions to set up pins, but if you don't use that lib here is how I do it with a C macro (tested on IAR)
makes it easy to change at one location if pcb board change, with much less chance of a bug if you missed a change somewhere.
## in the macro is so "P1" "OUT" is one word

place this in common.h

#define read &
#define clear &= ~
#define set |=
#define toggle ^=
#define Button(y,x)     (P1 ##x y BIT3)     // active low
#define RedLED(y,x)     (P1 ##x y BIT0)     // active high
then in main when you set up button IRQ for example, you can do this:
 
  RedLED(clear,OUT);
  RedLED(set,DIR);
   
  Button(set,OUT);                               // Pull-up
  Button(set,REN);
  Button(set,IES);                               // falling edge
  Button(clear,IFG);               
  Button(set,IE);

1 Reply

  • Hey Tony,

    Very neat macro, I will contact someone in my team and ask if this can be included in the wiki or a document for future reference.

    Sincerely,
    Sean

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.