Ports Peripheral Library

This library allows you to:

  • Read input pins on I/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 interrupt on mismatch condition (Change Notification)
  • Control operation during CPU Sleep and Idle modes
  • Configure port slew rate
  • Configure remappable pins using Peripheral Pin Select (PPS)

Example Library Functions

Configure an analog capable pin as digital
PLIB_PORTS_PinModeSelect (PORTS_ID_0, PORTS_ANALOG_PIN_0, PORTS_PIN_MODE_DIGITAL)
AN0 pin is digital
Data direction (Inputs vs Outputs)
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
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
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 use PLIB_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 use PLIB_PORTS_DirectionOutputSet() ).
  • Remappable pins (Peripheral Pin Select) can be configured only after unlocking the Device 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 >
© 2016 Microchip Technology, Inc.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.