Common Project Files (Code)

Appendices: P00

Using MPLAB® X Integrated Development Environment and chipKIT™Pro

Appendices: Common Project Files

config_bits.h

/* ************************ config_bits,h *************************************
 *	File name:  config_bits.h
 *  Author:     Richard Wall
 *  Date:       August 10, 2013
 *
 *   PIC32MX7 configuration definitions
 **************************************************************************** */

/* configuration settings */
    #pragma config FSRSSEL  = PRIORITY_7 /* Interrupt priority 7 assigned to shadow set */
    #pragma config FMIIEN   = OFF	/* RMII Ethernet PHY */
    #pragma config FETHIO   = ON	/* Default Ethernet I/O pin configuration */
    #pragma config FCANIO   = OFF	/* Alternate CAN I/O pin configuration */
    #pragma config FUSBIDIO = ON	/* USBID pin controlled by USB module */
    #pragma config FVBUSONIO= ON	/* VBUSON pin controlled by USB module */
    #pragma config FPLLIDIV = DIV_2	/* PLL input divider, divide by 2 */
    #pragma config FPLLMUL  = MUL_20	/* PLL multiplier, multiply by 20 */
    #pragma config UPLLIDIV = DIV_1	/* USB PLL input divider, divide by 2 */
    #pragma config UPLLEN   = OFF	/* USB PLL disabled */
    #pragma config FPLLODIV = DIV_1	/* PLL output divider, divide by 1 */
    #pragma config FNOSC    = PRIPLL	/* Primary oscillator (XT,HS, EC) w/PLL */
    #pragma config FSOSCEN  = OFF	/* Secondary oscillator disabled */
    #pragma config IESO     = OFF	/* Internal/external clock switchover disabled */
    #pragma config POSCMOD  = EC	/* Primary oscillator config,  8MHz resonator */
    #pragma config OSCIOFNC = OFF	/* CLK0 disabled on OSCO pin */
    #pragma config FPBDIV   = DIV_8	/* Peripheral bus clock divisor, divide by 8 */
    #pragma config FCKSM    = CSDCMD	/* Clock Switching & Fail Safe Clock Monitor disabled */
    #pragma config WDTPS    = PS1	/* Watchdog timer postcaler, 1:1 */
    #pragma config FWDTEN   = OFF	/* Watchdog timer disabled */
    #pragma config ICESEL   = ICS_PGx1 /* ICE/ICD Comm Channel Select, use PGC1 and PGD1 */
    #pragma config BWP      = OFF	/* Boot Flash Write Protect, disabled */
    #pragma config CP       = OFF	/* Code Protect disabled */
    #pragma config DEBUG    = ON	/* Background debugger */

/* End of config_bits.h */
                

chipKIT_Pro_MX7.h

/* ************************ chipKit_Pro_MX7.h *************************************
 *	File name:  chipKIT_Pro_MX7.h
 *  Author:     Richard Wall
 *  Date:       August 10, 2013
 *
 **************************************************************************** */

#ifndef __CHIPKIT_PRO_MX7_H__
    #define __CHIPKIT_PRO_MX7_H__

/* The following definitions are for IO assigned on the chipKIT Pro MX7
 * processor board */

    #define BTN1	BIT_6		/* Port G */
    #define BTN2	BIT_7		/* Port G */
    #define BTN3	BIT_0		/* Port A */


    #define LED1	BIT_12		/* Port G */
    #define LED2	BIT_13		/* Port G */
    #define LED3	BIT_14		/* Port G */
    #define LED4	BIT_15		/* Port G */
    #define BRD_LEDS	(LED1 | LED2 | LED3 | LED4)

/* The following definitions are for IO assigned for the PmodSTEP stepper
 * motor driver board that is commonly used for instrumentation and output
 * indication */

    #define LEDA	BIT_2		/*  Port B */
    #define LEDB	BIT_3		/*  Port B */
    #define LEDC	BIT_4		/*  Port B */
    #define LEDD	BIT_6		/*  Port B */
    #define LEDE	BIT_7		/*  Port B */
    #define LEDF	BIT_8		/*  Port B */
    #define LEDG	BIT_9		/*  Port B */
    #define LEDH	BIT_10		/*  Port B */
    #define SM1	LEDE
    #define SM2	LEDF
    #define SM3	LEDG
    #define SM4	LEDH

    #define SM_LEDS	(LEDA | LEDB | LEDC | LEDD | LEDE | LEDF | LEDG | LEDH)



/* Based upon setting in config_bits.h These directly influence timed
 * events using the Tick module.  They also are used for UART I2C, and SPI
 * baud rate generation. */

    #define GetSystemClock()		(80000000ul)	/* Hz */
    #define GetInstructionClock()	(GetSystemClock()/2)	
    #define GetPeripheralClock()	(GetSystemClock()/8)	

    #define XTAL	(8000000UL)         /* 8 MHz Xtal on chipKIT Pro MX7 */
    #define SYS_FREQ    GetSystemClock()  /* System clock rate */
    #define SYSTEM_FREQ GetSystemClock()
    #define CORE_OSC 	GetInstructionClock()  /* Core clock rate */
    #define FPB		GetPeripheralClock()   /* Peripheral bus clock rate */
    #define CORE_MS_TICK_RATE	GetInstructionClock()/1000

/* Timer 1 definitions */
    #define PRESCALE            256
    #define TOGGLES_PER_SEC     1000
    #define T1_TICK             (FPB/PRESCALE/TOGGLES_PER_SEC)

#endif

void chipKit_Pro_MX7_Setup(void);     /* chipKIT Pro MX7 hardware initialization */

/* End of chipKIT_Pro_MX7.h */
                

chipKIT_Pro_MX7.c

/* ************************ chipKIT_Pro_MX7.c *******************************
 *  File name:	 chipKIT_Pro_MX7.c
 *  Author:     Richard Wall
 *  Date:       August 15, 2013
 *
 *  Configures the chipKit Pro MX7 processor board for:
 *      Sets LED1 through LED4 for output
 *      Sets BTN1, BTN2 and BTN3 for input
 *
 ***************************************************************************/

#include <plib.h>           /* PIC32 System header file */
/* The config_bits.h must be included once and only once in any project */
#include "config_bits.h"    /* Processor configuration definitions */
#include "chipKIT_Pro_MX7.h"   /* chipKIT Pro MX7 pin definitions */

/* chipKit_Pro_MX7_Setup FUNCTION DESCRIPTION *****************************
 * SYNTAX:          void chipKit_Pro_MX7_Setup(void);
 * KEYWORDS:        chipKIT Pro MX7, PIC32, setup
 * Parameters:      None
 * Return:          None
 * Notes:           None
 * END DESCRIPTION ********************************************************/
void chipKit_Pro_MX7_Setup(void)
{
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * Statement configure cache, wait states and peripheral bus clock
 * Configure the device for maximum performance but do not change the PBDIV
 * Given the options, this function will change the flash wait states, RAM
 * wait state and enable prefetch cache but will not change the PBDIV.
 * The PBDIV value is already set via the pragma FPBDIV option above..
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
    SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);

    DDPCONbits.JTAGEN = 0;  // Statement is required to use Pin RA0 as IO
    PORTSetPinsDigitalIn(IOPORT_A, BTN3);	 /* Set BTN3 as input */

    PORTSetPinsDigitalIn(IOPORT_G, BTN1 | BTN2); /* Set BTN1 & BTN2 as inputs */
    PORTSetPinsDigitalOut(IOPORT_G, BRD_LEDS); 	 /* Set BDR LEDs as output */
    LATGCLR = BRD_LEDS;			/* Turn off LED1 through LED4 */
} /* End of chipKit_Pro_MX7_Setup */

/* End of chipKIT_Pro_MX7.c */

                

  • Other product and company names mentioned herein are trademarks or trade names of their respective companies. © 2014 Digilent Inc. All rights reserved.