# How to read a port by a label in Mplab Harmony?

I'm more familiarized with MCC and with that framework is really easy to read a port we just need to give a custom name in pin module:

and after that in code:

DATA_IN_GetValue()

My question is how the same can be done in the Harmony framework because the label/name matters to me. I know we can read the ports with the overcomplicated function it has, but is there a way using the names?

I gave a name to the port here:

If you give the port a name and a function and generate code... example...

You'll noticed that in system_config.h harmony only creates the following

/*** Functions for MY_TEST_PIN pin ***/
#define MY_TEST_PIN_PORT PORT_CHANNEL_E
#define MY_TEST_PIN_PIN PORTS_BIT_POS_6
#define MY_TEST_PIN_PIN_MASK (0x1 << 6)


which can be used as your parameters for PLIB_PORTS_PinGet, i.e.

PLIB_PORTS_PinGet (PORTS_ID_0, MY_TEST_PIN_PORT, MY_TEST_PIN_PIN)

You should probably define that in your application app.h to make it simpler

#define GET_MY_TEST_PIN() PLIB_PORTS_PinGet (PORTS_ID_0, MY_TEST_PIN_PORT, MY_TEST_PIN_PIN)

then somewhere where you want to get the pin value...

unsigned char MY_TEST_PIN_VALUE = GET_MY_TEST_PIN();

• This is what i was looking. I searched for "DATA_IN" and no result was found. Its clear now why... Thanks. Jun 13 '19 at 13:09

Why not use this:

#define   DATA_IN   RE6

value = DATA_IN;


otherwise you could use this with harmony:

PLIB_PORTS_PinGet (PORTS_ID_0, PORT_CHANNEL_E, PORTS_BIT_POS_6)


or

PLIB_PORTS_PinGet (PORTS_ID_0, PORT_CHANNEL_E, DATA_IN)


but I guess it's much more complicated.

• Hi @Mike, you mean PORTEbits.RE6? In Pin Settings of Harmony, i define the name DATA_IN but is it not used anywhere? what's the point of defining that name then (in pin settings)? I can manually do the define in the code, but was hoping harmony did some kind of define for me. Jun 13 '19 at 11:43