To setup the Virtual Port connection, the user must decide on the source peripheral, the destination peripheral, and whether the source peripheral output needs to be clocked through a flip-flop (data register). If the clocked option is selected, a flip-flop will be introduced into the input path.
// Enable flops and select appropriate clock
PORTWPDF = 0x0F;
PORTWCLK = 0x02;
// Point IN[0:3] to RW[n+1] for shift reg
PORTWIN0 = 1;
PORTWIN1 = 1;
PORTWIN2 = 1;
PORTWIN3 = 1;
// Write initial data
PORTW = 0b0110;
// Enable Virtual Port clock
VPORTCONbits.PWCLKEN = 1;
// Turn on the input clock
// and wait for the number of clocks to shift
// then stop the input clock
// Disable Virtual Port clock and read shifted data
VPORTCONbits.PWCLKEN = 0;
uint8_t shiftedData = PORTW;