When using XC8 compiler, there is a file available for each type of PIC microcontroller,
with name for each register, field and bit, named as documented in the datasheet for the device,
When PIC microcontroller type have been selected in MPLAB,
then the 'device support file' is made available in your source code file by typing:
in the source file.
The "bit field" structs have this form: REGISTERbits.BIT or REGISTERbits.FIELD, where you replace the uppercase names with actual register and bit names, as documented in the datasheet.
LATC = 0; // Clear all bits of this register to zero.
LATCbits.LATC6 = 1; // Set a single bit.
ANSELC = 0; // Enable Digital Inputs for all pins on port C, only for microcontrollers that have Analog features on this port.
TRISCbits.TRISC3 = 1; // Set tristate control bit to input for pin RC3.
TRISCbits.TRISC4 = 1; // Set tristate control bit to input for pin RC4.
TRISCbits.TRISC6 = 0; // Clear tristate control bit for output on pin RC6.
There are bit macro definitions that may be used in mask and shift operations:
while ((SSPCON2 & ( _SSPCON2_SEN_MASK | _SSPCON2_RSEN_MASK | _SSPCON2_PEN_MASK | _SSPCON2_RCEN_MASK | _SSPCON2_ACKEN_MASK))
|| (SSPSTAT & _SSPSTAT_R_nW_MASK))
There also are shorthand macro definitions available for many register bits.
Some SFR bits are placed in different registers in different device families.
It may be easier to type:
SSP1IF = 0; // Clear interrupt flag
SSP1IE = 1; // Enable interrupt
BCL1IF = 0;
BCL1IE = 1;
#if defined _16F1718
PIR1bits.SSP1IF = 0; // Clear interrupt flag
PIE1bits.SSP1IE = 1; // Enable interrupt
PIR2bits.BCL1IF = 0;
PIE2bits.BCL1IE = 1;
#elif defined _16F18875 // Different device have different register layout:
PIR3bits.SSP1IF = 0; // Clear interrupt flag
PIE3bits.SSP1IE = 1; // Enable interrupt
PIR3bits.BCL1IF = 0;
PIE3bits.BCL1IE = 1;
If such symbolic register and field names are used in a systematic way,
and then use the code for a different device type,
then the compiler will either adapt to differences if it can,
or tell where attention is needed.