Peripheral Pin Select Library

Peripheral Pin Select Library allows remapping of peripherals on the following MCU's: 18F2xJ11, 18F4xJ11, 18F2xJ50 and 18F4xJ50.

A key difference between pin select and non-pin select peripherals is that pin select peripherals are not associated with a default I/O pin.
The peripheral must always be assigned to a specific I/O pin before it can be used. In contrast, non pin selectable peripherals are always available on a default pin, assuming that the peripheral is active and not conflicting with another peripheral.

Library Routines

Unlock_IOLOCK

Prototype

void Unlock_IOLOCK();

Returns

Nothing.

Description

Unlocks I/O pins for Peripheral Pin Mapping.

Requires

Nothing.

Example
Unlock_IOLOCK();

Lock_IOLOCK

Prototype

void Lock_IOLOCK();

Returns

Nothing.

Description

Locks I/O pins for Peripheral Pin Mapping.

Requires

Nothing.

Example
Lock_IOLOCK();

PPS_Mapping

Prototype

char PPS_Mapping(char rp_num, char input_output, char funct_name);

Returns
  • 0 - if peripheral pin mapping wasn't successful.
  • 255 - if peripheral pin mapping was successful.
Description

Sets desired internal MCU module to be mapped with the requested pins.

Parameters :

  • rp_num: Remappable pin number. Consult the appropriate datasheet for adequate values.
  • input_output: Sets requested pin to be used as an input or output.
  • funct_name: Selects internal MCU module for usage.

Requires

Nothing.

Example
PPS_Mapping(15, _INPUT, _RX2_DT2);   // Sets pin 15 to be Input, and maps RX2/DT2 Input to it
PPS_Mapping(5, _OUTPUT, _TX2_CK2);   // Sets pin 5 to be Output, and maps EUSART2 Asynchronous Transmit/Synchronous Clock Output to it

PPS_Mapping_NoLock

Prototype

char PPS_Mapping_NoLock(char rp_num, char input_output, char funct_name);

Returns
  • 0 - if peripheral pin mapping wasn't successful.
  • 255 - if peripheral pin mapping was successful.
Description

Sets desired internal MCU module to be mapped on the requested pins.

This function doesn't use Unlock_IOLOCK and Lock_IOLOCK routines, so the user must call them before and after this function call (very useful if IOL1WAY bit is set, when after one lock sequence it is not possible to unlock it).

Parameters :

  • rp_num: Remappable pin number. Consult the appropriate datasheet for adequate values.
  • input_output: Sets requested pin to be used as an input or output.
  • funct_name: Selects internal MCU module for usage.
Parameters
Requires

Nothing.

Example
Unlock_IOLOCK()

PPS_Mapping_NoLock(15, _INPUT, _RX2_DT2);   // Sets pin 15 to be Input, and maps RX2/DT2 Input to it
PPS_Mapping_NoLock(5, _OUTPUT, _TX2_CK2);   // Sets pin 5 to be Output, and maps EUSART2 Asynchronous Transmit/Synchronous Clock Output to it

Lock_IOLOCK()

Available Parameters

Function Name (Input) Description
_INT1 External Interrupt 1
_INT2 External Interrupt 2
_INT3 External Interrupt 3
_T0CKI Timer0 External Clock Input
_T3CKI Timer3 External Clock Input
_CCP1 Input Capture 1
_CCP2 Input Capture 2
_T1G Timer1 Gate Input
_T3G Timer3 Gate Input
_RX2_DT2 RX2/DT2 Input
_CK2 EUSART2 Synchronous Clock Input
_SDI2 SPI2 Data Input
_SCK2IN SPI2 Clock Input
_SS2IN SPI2 Slave Select Input
_FLT0 PWM Fault Input
Function Name (Output) Description
_NULL The NULL function is assigned to all RPn outputs at device Reset and disables the RPn output function.
_C1OUT Comparator 1 Output
_C2OUT Comparator 2 Output
_TX2_CK2 EUSART2 Asynchronous Transmit/Synchronous Clock Output
_DT2 EUSART2 Synchronous Transmit
_SDO2 SPI2 Data Output
_SCK2 SPI2 Clock Output
_SSDMA SPI DMA Slave Select
_ULPOUT Ultra Low-Power Wake-up Event
_CCP1_P1A ECCP1 Compare or PWM Output Channel A
_P1B ECCP1 Enhanced PWM Output, Channel B
_P1C ECCP1 Enhanced PWM Output, Channel C
_P1D ECCP1 Enhanced PWM Output, Channel D
_CCP2_P2A ECCP2 Compare or PWM Output
_P2B ECCP2 Enhanced PWM Output, Channel B
_P2C ECCP2 Enhanced PWM Output, Channel C
_P2D ECCP2 Enhanced PWM Output, Channel D
Input/Output Parameter Description
_INPUT Sets selected pin as input
_OUTPUT Sets selected pin as output
Copyright (c) 2002-2012 mikroElektronika. All rights reserved.
What do you think about this topic ? Send us feedback!
Want more examples and libraries? 
Find them on LibStock - A place for the code