Ports Peripheral Library for MPLAB® Harmony v2

This library allows you to:

  • Read input pins onI/O ports
  • Control output pins on I/O ports
  • Configure analog capable pins as digital
  • Configure output pin open-drain
  • Configure input pin pull-up and pull-down resistors
  • Monitor select inputs and generate an interrupt on mismatch condition(change notification)
  • Control operation during CPU Sleep and Idle modes
  • Configure port slew rate
  • Configure remappable pins usingPeripheral Pin Select (PPS)

Example Library Functions

Configure an Analog Capable Pin as Digital

Function NameDescription
PLIB_PORTS_PinModeSelect (PORTS_ID_0,PORTS_ANALOG_PIN_0,PORTS_PIN_MODE_DIGITAL)AN0 pin is digital

Data Direction (Inputs vs Outputs)

Function NameDescription
PLIB_PORTS_DirectionOutputSet (PORTS_ID_0,PORT_CHANNEL_C, 0x0007)RC0, RC1 and RC2 pins are outputs (the 0x0007 parameter is a mask)
PLIB_PORTS_DirectionInputSet (PORTS_ID_0, PORT_CHANNEL_B, 0x0003)RB0 and RB1 pins are inputs
PLIB_PORTS_PinDirectionOutputSet (PORTS_ID_0,PORT_CHANNEL_C,PORTS_BIT_POS_4)RC4 pin is an output

Read an Input

Function NameDescription
PLIB_PORTS_Read (PORTS_ID_0,PORT_CHANNEL_C)Returns a 32 bit value for PORTC
PLIB_PORTS_PinGet (PORTS_ID_0,PORT_CHANNEL_C,PORTS_BIT_POS_4)Returns the value on PIN RC4 (PORTC, bit 4)

Control an Output

Function NameDescription
PLIB_PORTS_Write (PORTS_ID_0,PORT_CHANNEL_C, 0x3)Write a 0x3 to PORTC (RC0 and RC1 pins are set, all other pins are cleared)
PLIB_PORTS_PinWrite (PORTS_ID_0,PORT_CHANNEL_C,PORTS_BIT_POS_4, 1)Writes a "1" to RC4
PLIB_PORTS_PinSet (PORTS_ID_0,PORT_CHANNEL_A,PORTS_BIT_POS_2)Sets RA2 pin high
PLIB_PORTS_PinToggle (PORTS_ID_0,PORT_CHANNEL_C,PORTS_BIT_POS_5)Invert value on RC5 pin

Important notes on using this library:

  • Analog capable pins are configured as analog inputs after Reset. If you want to use an analog capable pin in digital mode, you must configure it as a digital pin (can usePLIB_PORTS_PinModeSelect()).
  • Digital pins are configured as inputs after Reset. If you want to use a digital pin as an output, you must configure it as an output (can usePLIB_PORTS_DirectionOutputSet()).
  • Remappable pins (Peripheral Pin Select) can be configured only after unlocking theDevice Configuration registers. See the "Device Control Peripheral Library" for more details.

 Learn More

 
Harmony Ports Tutorial
Learn more >
 
Example Code and Projects
Learn more >
 
Entire Ports PLIB Interface
Learn more >
 
Ports Hardware Description
Learn more >