Electronic – How to find MCU-specific macros

mplabxxc8

I'm trying to set the weak internal pull-up resistor for a GPIO, but can't seem to guess the right macro name that maps to whatever memory address in the PIC.

None of these seem to be recognized by the compiler. What is the proper way to look these up? All I include is <xc.h> so I have no idea where the actual header file is.

I have the datasheet with the register definition open for WPUB, but it does not map to code in any consistent way that I can find:

#include <xc.h>

void InitGpio(void) {
  TRISBbits.TRISB3 = 1; // compiler recognizes
  WPUBbits.WPUB3 = 1;   // 'undefined identifier' compiler error
  WPUB.WPUB3 = 1;       // 'undefined identifier' compiler error
  WPUB = 1;             // 'undefined identifier' compiler error
  WPUB3 = 1;            // 'undefined identifier' compiler error
  _WPUB = 1;            // 'undefined identifier' compiler error
  _WPUB3 = 1;           // 'undefined identifier' compiler error
}

Best Answer

Every PIC microcontroller has it's own specific header file which contains its register definitions. Look in the compiler's include directory for your own PIC. The include directory on my machine is located here:

c:\Program Files (x86)\Microchip\xc8\v1.31\include\

Here's the definitions related to the Weak Pull-up Registers for a random PIC (PIC16LF722):

    // Register: WPUB
extern volatile unsigned char           WPUB                @ 0x095;
#ifndef _LIB_BUILD
asm("WPUB equ 095h");
#endif
// aliases
extern volatile unsigned char           WPU                 @ 0x095;
#ifndef _LIB_BUILD
asm("WPU equ 095h");
#endif
// bitfield definitions
typedef union {
    struct {
        unsigned WPUB                   :8;
    };
    struct {
        unsigned WPUB0                  :1;
        unsigned WPUB1                  :1;
        unsigned WPUB2                  :1;
        unsigned WPUB3                  :1;
        unsigned WPUB4                  :1;
        unsigned WPUB5                  :1;
        unsigned WPUB6                  :1;
        unsigned WPUB7                  :1;
    };
    struct {
        unsigned WPU0                   :1;
        unsigned WPU1                   :1;
        unsigned WPU2                   :1;
        unsigned WPU3                   :1;
        unsigned WPU4                   :1;
        unsigned WPU5                   :1;
        unsigned WPU6                   :1;
        unsigned WPU7                   :1;
    };
} WPUBbits_t;
extern volatile WPUBbits_t WPUBbits @ 0x095;
// bitfield macros
#define _WPUB_WPUB_POSN                                     0x0
#define _WPUB_WPUB_POSITION                                 0x0
#define _WPUB_WPUB_SIZE                                     0x8
#define _WPUB_WPUB_LENGTH                                   0x8
#define _WPUB_WPUB_MASK                                     0xFF
#define _WPUB_WPUB0_POSN                                    0x0
#define _WPUB_WPUB0_POSITION                                0x0
#define _WPUB_WPUB0_SIZE                                    0x1
#define _WPUB_WPUB0_LENGTH                                  0x1
#define _WPUB_WPUB0_MASK                                    0x1
#define _WPUB_WPUB1_POSN                                    0x1
#define _WPUB_WPUB1_POSITION                                0x1
#define _WPUB_WPUB1_SIZE                                    0x1
#define _WPUB_WPUB1_LENGTH                                  0x1
#define _WPUB_WPUB1_MASK                                    0x2
#define _WPUB_WPUB2_POSN                                    0x2
#define _WPUB_WPUB2_POSITION                                0x2
#define _WPUB_WPUB2_SIZE                                    0x1
#define _WPUB_WPUB2_LENGTH                                  0x1
#define _WPUB_WPUB2_MASK                                    0x4
#define _WPUB_WPUB3_POSN                                    0x3
#define _WPUB_WPUB3_POSITION                                0x3
#define _WPUB_WPUB3_SIZE                                    0x1
#define _WPUB_WPUB3_LENGTH                                  0x1
#define _WPUB_WPUB3_MASK                                    0x8
#define _WPUB_WPUB4_POSN                                    0x4
#define _WPUB_WPUB4_POSITION                                0x4
#define _WPUB_WPUB4_SIZE                                    0x1
#define _WPUB_WPUB4_LENGTH                                  0x1
#define _WPUB_WPUB4_MASK                                    0x10
#define _WPUB_WPUB5_POSN                                    0x5
#define _WPUB_WPUB5_POSITION                                0x5
#define _WPUB_WPUB5_SIZE                                    0x1
#define _WPUB_WPUB5_LENGTH                                  0x1
#define _WPUB_WPUB5_MASK                                    0x20
#define _WPUB_WPUB6_POSN                                    0x6
#define _WPUB_WPUB6_POSITION                                0x6
#define _WPUB_WPUB6_SIZE                                    0x1
#define _WPUB_WPUB6_LENGTH                                  0x1
#define _WPUB_WPUB6_MASK                                    0x40
#define _WPUB_WPUB7_POSN                                    0x7
#define _WPUB_WPUB7_POSITION                                0x7
#define _WPUB_WPUB7_SIZE                                    0x1
#define _WPUB_WPUB7_LENGTH                                  0x1
#define _WPUB_WPUB7_MASK                                    0x80
#define _WPUB_WPU0_POSN                                     0x0
#define _WPUB_WPU0_POSITION                                 0x0
#define _WPUB_WPU0_SIZE                                     0x1
#define _WPUB_WPU0_LENGTH                                   0x1
#define _WPUB_WPU0_MASK                                     0x1
#define _WPUB_WPU1_POSN                                     0x1
#define _WPUB_WPU1_POSITION                                 0x1
#define _WPUB_WPU1_SIZE                                     0x1
#define _WPUB_WPU1_LENGTH                                   0x1
#define _WPUB_WPU1_MASK                                     0x2
#define _WPUB_WPU2_POSN                                     0x2
#define _WPUB_WPU2_POSITION                                 0x2
#define _WPUB_WPU2_SIZE                                     0x1
#define _WPUB_WPU2_LENGTH                                   0x1
#define _WPUB_WPU2_MASK                                     0x4
#define _WPUB_WPU3_POSN                                     0x3
#define _WPUB_WPU3_POSITION                                 0x3
#define _WPUB_WPU3_SIZE                                     0x1
#define _WPUB_WPU3_LENGTH                                   0x1
#define _WPUB_WPU3_MASK                                     0x8
#define _WPUB_WPU4_POSN                                     0x4
#define _WPUB_WPU4_POSITION                                 0x4
#define _WPUB_WPU4_SIZE                                     0x1
#define _WPUB_WPU4_LENGTH                                   0x1
#define _WPUB_WPU4_MASK                                     0x10
#define _WPUB_WPU5_POSN                                     0x5
#define _WPUB_WPU5_POSITION                                 0x5
#define _WPUB_WPU5_SIZE                                     0x1
#define _WPUB_WPU5_LENGTH                                   0x1
#define _WPUB_WPU5_MASK                                     0x20
#define _WPUB_WPU6_POSN                                     0x6
#define _WPUB_WPU6_POSITION                                 0x6
#define _WPUB_WPU6_SIZE                                     0x1
#define _WPUB_WPU6_LENGTH                                   0x1
#define _WPUB_WPU6_MASK                                     0x40
#define _WPUB_WPU7_POSN                                     0x7
#define _WPUB_WPU7_POSITION                                 0x7
#define _WPUB_WPU7_SIZE                                     0x1
#define _WPUB_WPU7_LENGTH                                   0x1
#define _WPUB_WPU7_MASK                                     0x80
// alias bitfield definitions
typedef union {
    struct {
        unsigned WPUB                   :8;
    };
    struct {
        unsigned WPUB0                  :1;
        unsigned WPUB1                  :1;
        unsigned WPUB2                  :1;
        unsigned WPUB3                  :1;
        unsigned WPUB4                  :1;
        unsigned WPUB5                  :1;
        unsigned WPUB6                  :1;
        unsigned WPUB7                  :1;
    };
    struct {
        unsigned WPU0                   :1;
        unsigned WPU1                   :1;
        unsigned WPU2                   :1;
        unsigned WPU3                   :1;
        unsigned WPU4                   :1;
        unsigned WPU5                   :1;
        unsigned WPU6                   :1;
        unsigned WPU7                   :1;
    };
} WPUbits_t;
extern volatile WPUbits_t WPUbits @ 0x095;
// bitfield macros
#define _WPU_WPUB_POSN                                      0x0
#define _WPU_WPUB_POSITION                                  0x0
#define _WPU_WPUB_SIZE                                      0x8
#define _WPU_WPUB_LENGTH                                    0x8
#define _WPU_WPUB_MASK                                      0xFF
#define _WPU_WPUB0_POSN                                     0x0
#define _WPU_WPUB0_POSITION                                 0x0
#define _WPU_WPUB0_SIZE                                     0x1
#define _WPU_WPUB0_LENGTH                                   0x1
#define _WPU_WPUB0_MASK                                     0x1
#define _WPU_WPUB1_POSN                                     0x1
#define _WPU_WPUB1_POSITION                                 0x1
#define _WPU_WPUB1_SIZE                                     0x1
#define _WPU_WPUB1_LENGTH                                   0x1
#define _WPU_WPUB1_MASK                                     0x2
#define _WPU_WPUB2_POSN                                     0x2
#define _WPU_WPUB2_POSITION                                 0x2
#define _WPU_WPUB2_SIZE                                     0x1
#define _WPU_WPUB2_LENGTH                                   0x1
#define _WPU_WPUB2_MASK                                     0x4
#define _WPU_WPUB3_POSN                                     0x3
#define _WPU_WPUB3_POSITION                                 0x3
#define _WPU_WPUB3_SIZE                                     0x1
#define _WPU_WPUB3_LENGTH                                   0x1
#define _WPU_WPUB3_MASK                                     0x8
#define _WPU_WPUB4_POSN                                     0x4
#define _WPU_WPUB4_POSITION                                 0x4
#define _WPU_WPUB4_SIZE                                     0x1
#define _WPU_WPUB4_LENGTH                                   0x1
#define _WPU_WPUB4_MASK                                     0x10
#define _WPU_WPUB5_POSN                                     0x5
#define _WPU_WPUB5_POSITION                                 0x5
#define _WPU_WPUB5_SIZE                                     0x1
#define _WPU_WPUB5_LENGTH                                   0x1
#define _WPU_WPUB5_MASK                                     0x20
#define _WPU_WPUB6_POSN                                     0x6
#define _WPU_WPUB6_POSITION                                 0x6
#define _WPU_WPUB6_SIZE                                     0x1
#define _WPU_WPUB6_LENGTH                                   0x1
#define _WPU_WPUB6_MASK                                     0x40
#define _WPU_WPUB7_POSN                                     0x7
#define _WPU_WPUB7_POSITION                                 0x7
#define _WPU_WPUB7_SIZE                                     0x1
#define _WPU_WPUB7_LENGTH                                   0x1
#define _WPU_WPUB7_MASK                                     0x80
#define _WPU_WPU0_POSN                                      0x0
#define _WPU_WPU0_POSITION                                  0x0
#define _WPU_WPU0_SIZE                                      0x1
#define _WPU_WPU0_LENGTH                                    0x1
#define _WPU_WPU0_MASK                                      0x1
#define _WPU_WPU1_POSN                                      0x1
#define _WPU_WPU1_POSITION                                  0x1
#define _WPU_WPU1_SIZE                                      0x1
#define _WPU_WPU1_LENGTH                                    0x1
#define _WPU_WPU1_MASK                                      0x2
#define _WPU_WPU2_POSN                                      0x2
#define _WPU_WPU2_POSITION                                  0x2
#define _WPU_WPU2_SIZE                                      0x1
#define _WPU_WPU2_LENGTH                                    0x1
#define _WPU_WPU2_MASK                                      0x4
#define _WPU_WPU3_POSN                                      0x3
#define _WPU_WPU3_POSITION                                  0x3
#define _WPU_WPU3_SIZE                                      0x1
#define _WPU_WPU3_LENGTH                                    0x1
#define _WPU_WPU3_MASK                                      0x8
#define _WPU_WPU4_POSN                                      0x4
#define _WPU_WPU4_POSITION                                  0x4
#define _WPU_WPU4_SIZE                                      0x1
#define _WPU_WPU4_LENGTH                                    0x1
#define _WPU_WPU4_MASK                                      0x10
#define _WPU_WPU5_POSN                                      0x5
#define _WPU_WPU5_POSITION                                  0x5
#define _WPU_WPU5_SIZE                                      0x1
#define _WPU_WPU5_LENGTH                                    0x1
#define _WPU_WPU5_MASK                                      0x20
#define _WPU_WPU6_POSN                                      0x6
#define _WPU_WPU6_POSITION                                  0x6
#define _WPU_WPU6_SIZE                                      0x1
#define _WPU_WPU6_LENGTH                                    0x1
#define _WPU_WPU6_MASK                                      0x40
#define _WPU_WPU7_POSN                                      0x7
#define _WPU_WPU7_POSITION                                  0x7
#define _WPU_WPU7_SIZE                                      0x1
#define _WPU_WPU7_LENGTH                                    0x1
#define _WPU_WPU7_MASK                                      0x80