MC32MX64GP C32 Header

This page introduces the Plug & Program MC32MX64GP definitions for use in your own firmware projects

Background

Without the MC32MX64GP.h file, if you want to turn set IO direction, turn on/off or read pins on the MC32MX64GP, you need to look at how the onboard PIC32MX340F512H pin Special Function Registers (SFR) are mapped out to the MC32MX64GP IO sockets, and then use the Microchip PIC32MX340F512H include file defines.

General Pin alias’s

Whilst the standard defines are still available MC32MX64GP.h defines additional alias’s for each of the MC32MX64GP 48 IO socket pins

  • Set pin direction (TRIS): IO j _ p TRIS
  • Set pin state (LAT): IO j _ p LAT
  • Read pin: IO j _ p

(where j = IO socket number 1-12, p = IO socket pin number 1-4)

Example: Pin MC32MX64GP.IO1.1

maps to pin Pic32MX340F512H.RE4

For this Pins TRIS, LAT & Port SFR bits you could use _TRISE4, _LATE4, _RE4 respectively.

MC32MX64GP.h also provides also  IO1_1,  IO1_1LAT , IO1_1TRIS

Example: MC32MX64GP.IO1

//IO1 General use

 #define IO1_1         _RE4
 #define IO1_2         _RE5
 #define IO1_3         _RE6
 #define IO1_4         _RE7
 #define IO1_1LAT     _LATE4
 #define IO1_2LAT     _LATE5
 #define IO1_3LAT     _LATE6
 #define IO1_4LAT     _LATE7
 #define IO1_1TRIS    _TRISE4
 #define IO1_2TRIS     _TRISE5
 #define IO1_3TRIS     _TRISE6
 #define IO1_4TRIS     _TRISE7

IO Socket Functions

MC32MX64GP.h also allows us to do operations on an IO socket as a whole via IOj_GET(), IOj_PUT(a), IOj_TRIS(a)
(j = IO number 1-12)

This is the equivalent is using PORTn, TRISn and LATn in standard MPLab C32 definitions.

Example:

int a;
a = IO1_GET();
IO1_PUT(a);
IO1_TRIS(a);

Example: MC32MX64GP.h IO1:

#define IO1_GET() (IO1_4<<3) | (IO1_3<<2) | (IO1_2<<1) | IO1_1)
#define IO1_PUT(a) do{BYTE vTemp = (a); IO1_4LAT = vTemp&0x8; IO1_3LAT = vTemp&0x1; IO1_2LAT = vTemp&0x2; IO1_1LAT = vTemp&0x1} while(0)
#define IO1_TRIS(a) do{BYTE vTemp = (a); IO1_4TRIS = vTemp&0x8; IO1_3TRIS = vTemp&0x1; IO1_2TRIS = vTemp&0x2; IO1_1TRIS = vTemp&0x1} while(0)

Processor Peripheral Specific Alias’s

MC32MX64GP.h also includes pin alias’s and function alias’s for the processor peripheral specific pins on each IO as appliable to that IO.

Example: SPI2 is connected to IO1.  Note that each pin alias is defined twice, once prefixed by IO Port and once without, eg IO1_SCK2 & SCK2.   Both are interchangeable depending on the developers preference

Example: MC32MX64GP.h for SPI2:

//SPI2
#define IO1_SCK2        IO1_1
#define IO1_SDI2        IO1_2
#define IO1_SDO2        IO1_3
#define IO1_SS2            IO1_4
#define IO1_SCK2LAT        IO1_1LAT
#define IO1_SDI2LAT        IO1_2LAT
#define IO1_SDO2LAT        IO1_3LAT
#define IO1_SS2LAT        IO1_4LAT
#define IO1_SCK2TRIS    IO1_1TRIS
#define IO1_SDI2TRIS    IO1_2TRIS
#define IO1_SDO2TRIS    IO1_3TRIS
#define IO1_SS2TRIS        IO1_4TRIS

#define SCK2        IO1_1
#define SDI2        IO1_2
#define SDO2        IO1_3
#define SS2            IO1_4
#define SCK2LAT        IO1_1LAT
#define SDI2LAT        IO1_2LAT
#define SDO2LAT        IO1_3LAT
#define SS2LAT        IO1_4LAT
#define SCK2TRIS    IO1_1TRIS
#define SDI2TRIS    IO1_2TRIS
#define SDO2TRIS    IO1_3TRIS
#define SS2TRIS        IO1_4TRIS

IO2 has Analogue to Digital inputs, its definitions are:

//IO2 General use

#define IO2_1         _RG6
#define IO2_2         _RG7
#define IO2_3         _RG8
#define IO2_4         _RG9
#define IO2_1LAT     _LATG6
#define IO2_2LAT     _LATG7
#define IO2_3LAT     _LATG8
#define IO2_4LAT     _LATG9
#define IO2_1TRIS     _TRISG6
#define IO2_2TRIS     _TRISG7
#define IO2_3TRIS     _TRISG8
#define IO2_4TRIS     _TRISG9

#define IO2_GET() (IO2_4<<3) | (IO2_3<<2) | (IO2_2<<1) | IO2_1)
#define IO2_PUT(a) do{BYTE vTemp = (a); IO2_4LAT = vTemp&0x8; IO2_3LAT = vTemp&0x1; IO2_2LAT = vTemp&0x2; IO2_1LAT = vTemp&0x1} while(0)
#define IO2_TRIS(a) do{BYTE vTemp = (a); IO2_4TRIS = vTemp&0x8; IO2_3TRIS = vTemp&0x1; IO2_2TRIS = vTemp&0x2; IO2_1TRIS = vTemp&0x1} while(0)

//IO2 hardware modules

//IO2_1 = AN4
#define IO2_1SetAsAnalogue() do{IO2_1TRIS = 1; AD1PCFGCLR = 0b10000 } while(0)
#define IO2_1SetAsDigital() do{AD1PCFGSET = 0b10000 } while(0)
#define IO2_1GetAnalogueFromScan() (ADC1BUF4)

//IO2_2 = AN5
#define IO2_2SetAsAnalogue() do{IO2_2TRIS = 1; AD1PCFGCLR = 0b100000 } while(0)
#define IO2_2SetAsDigital() do{AD1PCFGSET = 0b100000 } while(0)
#define IO2_2GetAnalogueFromScan() (ADC1BUF5)

//IO2_3 = AN6
#define IO2_3SetAsAnalogue() do{IO2_3TRIS = 1; AD1PCFGCLR = 0b1000000 } while(0)
#define IO2_3SetAsDigital() do{AD1PCFGSET = 0b1000000 } while(0)
#define IO2_3GetAnalogueFromScan() (ADC1BUF6)

//IO2_4 = AN7
#define IO2_4SetAsAnalogue() do{IO2_4TRIS = 1; AD1PCFGCLR = 0b10000000 } while(0)
#define IO2_4SetAsDigital() do{AD1PCFGSET = 0b10000000 } while(0)
#define IO2_4GetAnalogueFromScan() (ADC1BUF7)
#pragma config FNOSC    = PRIPLL          // External with PLL
#pragma config FPLLIDIV = DIV_2         // PLL Input Divider
#pragma config FPLLMUL  = MUL_20        // PLL Multiplier
#pragma config FPLLODIV = DIV_1         // PLL Output Divider
#pragma config FPBDIV   = DIV_4         // Peripheral Clock divisor
#pragma config FWDTEN   = OFF           // Watchdog Timer
#pragma config WDTPS    = PS1048576     // Watchdog Timer Postscale
#pragma config FCKSM    = CSDCMD        // Clock Switching & Fail Safe Clock Monitor
#pragma config OSCIOFNC = OFF           // CLKO Enable
#pragma config POSCMOD  = HS            // Primary Oscillator
#pragma config IESO     = OFF           // Internal/External Switch-over
#pragma config FSOSCEN  = ON            // Secondary Oscillator Enable
#pragma config CP       = ON           // Code Protect
#pragma config BWP      = ON           // Boot Flash Write Protect
#pragma config PWP      = OFF           // Program Flash Write Protect
#pragma config ICESEL   = ICS_PGx2      // ICE/ICD Comm Channel Select
#pragma config DEBUG    = OFF           // Debugger Disabled