Project 0 Application files

Appendices: P00

Appendices:

Project 0 Application Files

Project0.h

/* ************************ Project0.h *************************************
 * File name: Project0.h
 *
 * Author:	Richard Wall
 * Date: 	August 10, 2013
 * This contains configuration for programming and operation with
 * the PIC32MX7 as well asdefines and function prototypes
 *************************************************************************** */

// Project0 definitions
#ifndef __Project0_H__
    #define __Project0_H__
    #define A   5
    #define B   17
#endif

// Function prototypes
void no_swap(int x, int y);

int swap(int *x, int *y);

// End of Project0.h
                

Project0.c

/* ************************ Project0.c *************************************
 * File name: Project0.c
 * Author:	Richard W. Wall
 * Date: 	August 13, 2013
 
 * This program is designed to provide a simple platform for exploring the
 * software instrumentation and debugging tools available with the MPLAB X
 * Integrated Development Environment (IDE). C code examples are provided
 * that demonstrate passing data by value and by reference between two
 * functions .
 * ********************************************************************* */

/*
 Note:  Local project header files are written between "  ". 
        System header files are bracketed between < >.  */

#include <plib.h>           /* Microchip PIC32 processor definitions */
#include "chipKIT_Pro_MX7.h"   /* chipKIT Pro MX7 board definitions */
#include "Project0.h"       /* Project definitions and function prototypes */

/* Global variable list - normally, only variables that are required
 * to pass data to or from interrupt service routines (ISR) are required
 * to be declared as global variables. Processor Special Function Register
 * (SFR) are global by the system. */

/* Constant data types cannot be modified at execution time and appear
 * as protected variables in the MPLAB watch window.  */

const int ac = A;   /* Constants assigned values that are defined */
const int bc = B;

/* --------------------  Start of program code ------------------------------ */
int main(void)
{
/* Variable that are declared as static can be viewed in the MPLAB watch
 * window but values for these type of variables will be shown when the program
 * is executing code in the function in which they are declared. Static local
 * variables do not automatically appear in the variables window.
 */

static int a;    /* Static local variables have permanent  memory allocation*/
static int b;
int c;           /* auto local variables have temporary memory allocation */

const int d = 3;    /* Variables that are declared as a data type "const"
                    are assigned a value when they are declared.  The
                    "const" variable cannot appear on the left side of the
                    equal (=) sign in any statement. For example, the
                    statement, d = 34*a;, will generate a compiler error */

    chipKit_Pro_MX7_Setup();  /* Initialize chipKIT Pro MX7 on board resources */

    while(1)                /* Infinite application loop */
    {
        a = ac;             /* Initialize variables a and b. */
        b = bc;
        no_swap(a, b);      /* Call swapping functions */
        c = swap(&a, &b);
        a = c - d;          /* Math statement */
    }

    return(1);  /* A program developed for the embedded system should never 
                   be able to execute this return instruction. - Why??? */
}  /* End of main */

/* no_swap FUNCTION DESCRIPTION ********************************************
 * SYNTAX:          void no_swap(int x, int y)
 * KEYWORDS:        swap, exchange, pass by value
 * DESCRIPTION:     This function swaps the values in variables x and y. Since
 *                  the variables are passed by value, the results are lost once
 *                  the program execution returns from this function.
 * PARAMETER1:      first integer value
 * PARAMETER2:      second integer value
 * RETURN VALUE:    None.
 *
 * NOTES:           Variables passed by value in the argument list are local
 *                  considered to be variables. Variables declared inside the
 *                  function are also local variables provided they are not
 *                  declared as static.
 * END DESCRIPTION **********************************************************/
void no_swap(int x, int y)
{
int z;          /* Temporary local variable */
    z = x;      /* Execute the exchange of values*/
    x = y;
    y = z;
}  /* End of no_swap funbction */

/* swap FUNCTION DESCRIPTION ************************************************
 * SYNTAX:          void swap(int ^x, int *y)

 * KEYWORDS:        swap, exchange, pass by reference
 * DESCRIPTION:     This function swaps the values of variables whose address are
 *                  passed as x and y. Since the variables are passed by reference,
 *                  the results are not lost once the function is done.
 * PARAMETER1:      first integer value
 * PARAMETER2:      second integer value
 * RETURN VALUE:    Sum of x and y.
 *
 * NOTES:       Variables that are passed by reference appear in the MPLAB
 *              locals window. Local variables that are declared as static
 *              can be viewed in the watch window.
 * END DESCRIPTION **********************************************************/
int swap(int *x, int *y)
{
int z;              /* Temporary local variable */
    z = *x;         /* Execute the exchange of values */
    *x = *y;
    *y = z;
    z = *x +*y;
    return z;
} /* End of swap function */

/* End of Project0.c */
                

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