First Technology Transfer

Standard and Advanced Technical Training, Consultancy and Mentoring

Course M302 - A Comprehensive Introduction to Embedded C Programming using the XC32 Compiler

Duration: 5 Days

Intended Audience

This course is aimed at engineers with an understanding of microelectronics and programming who intend to create projects using the 'C' language, but who are new to the Microchip 32 bit processor architectures and/or MPLABX and the XC32 'C' compiler as well as the MPLAB Harmony tool. Some prior knowledge of programming is assumed, together with familiarity with code development using an IDE. This is a very intensive course and its contents can be tailored to the requirements and experience of the attendees.

Synopsis

This hands-on course aims to provide engineers with an understanding of the 32 bit PIC microcontrollers and experience of using the MPLABX IDE, the XC32 compiler and the MPLAB Hsrmony tool to create and debug 'C' programs. Starting with an in depth overview of the architecture and features of the Microchip 32 bit microcontrollers practical experience is then provided in using MPLABX , XC32 and MPLAB Harmony for creating and debugging 'C' programs on 32 bit PIC microcontrollers. Especially important is the coverage of how to make the best use of the Harmony tool to set up various on-chip peripherals and their associated libraries.

As well as using the XC32 compiler and MPLABX the course introduces Microsoft Visual Studio / Eclipse CDT for developing and testing ANSI C code that does not involve interaction with the processor hardware. The use of MPLAB Harmony and the libraries it generates is covered in detail.

Laboratory workshops include learning how to

  • Create, build and debug new projects on a target board using the XC32 C Compiler, MPLABX , MPLAB Harmony and ICD3
  • Set the configuration options appropriately for the target system
  • Use digital I/O ports to interact with the outside world
  • Display information on an LCD module
  • Read the value of an analogue input using the A-to-D converter
  • Use an interrupt handler to collect data in the background
  • Set up a Pulse Width Modulation (PWM) output with a variable duty cycle
  • Communicate with a PC over a serial interface using the USART peripheral

Course Outline

  • Overview of Development Tools
    • Microchip development software: MPLABX and associated tools
    • XC32 'C' compiler
    • Microchip In-Circuit Debugger (ICD3) hardware
    • The PIC32 Starter Kit.
  • The PIC32 MIPS Processor Architectures
    • Harvard versus Von Neumann architecture
    • Organisation of data memory
    • On-chip peripherals
    • In-Circuit Serial Programming (ICSP)
    • The MIPS processor core architecture
  • The XC32 Compiler
    • Key features and ANSI C extensions to support the 32 bit processor architectures
    • XC32 data types, storage classes and type qualifiers
    • Programming style - use of templates and comments
    • Debugging at 'C' source level using MPLABX and ICD3
    • Inclusion of external source code modules to add functionality to the project
    • Interrupt service routines - how to create handlers using XC32
  • Developing and testing pure (portable) ANSI C code on the PC
    • Overview of Microsoft Visual Studio and Eclipse CDT as C IDEs
    • Advantages of testing and developing portable code on a PC.
  • Foundations of C programming
    • Basic C data types - characters, integers and floating point numbers.
    • C arithmetic and logical operators
    • Functions and function prototypes and header files
    • if - else and switch statements
    • Arrays and pointers
    • Iteration using for loops, while loops and do - while loops
    • Data structures in C
    • Function pointers
    • Pointers to data structures
    • Data structures containing function pointers
    • Unions and enums
    • Bit level operators and bit level data structures
  • Processor specific C - Manipulating Memory Mapped Microcontroller Registers from within C code
    • How memory mapped registers are associated with variables and data structures
    • Understanding the processor specific C header files
    • Implementing interrupt handler code in C
    • Implementing a custom peripheral library
    • Overview of Microchip supplied peripheral libraries
  • Introduction to MPLAB Harmony
    • Improving productivity by generating processor specific device library code
    • Developing standalone projects vs. developing projects using MPLAB Harmony generated libraries.
    • Setting up a Harmony based project in MPLABX.
  • Embedded applications and examples
    • Flashing LEDs and detecting button presses
    • Software vs. timer interrupt driven delays
    • Using ADC to acquire analog sensor data
    • Basic serial communications using RS232
    • Implementing a simple user interface using buttons and a LCD
    • Acquiring data from a simple I2C / SPI sensor
    • Implementing a basic timer interrupt driven scheduler