First Technology Transfer

Standard and Advanced Technical Training, Consultancy and Mentoring

M202 - A Comprehensive Introduction to Embedded C Programming of Microchip 16 bit devices using the XC16 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 16 bit processor architectures and/or MPLABX and the XC16 'C' compiler. 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 core features of 16 bit PIC microcontrollers and experience of using the MPLABX IDE and the XC16 compiler to create and debug 'C' programs. It aims to provide students with

  • An understanding the architecture and features of the Microchip 16 bit microcontrollers.
  • Hands-on experience of using MPLABX and XC16 to create and debug 'C' programs on Microchip 16 bit PIC microcontrollers.
  • Experience in making driving on-chip peripherals by using existing libraries, or implementing custom libraries.
The course includes many practical workshop exercises which are interleaved with the relevant presentation material for maximum impact and variety. These exercises are carried out using MPLABX and the XC16 C compiler running on a Windows PC, an ICD3 programmer/debugger and a target development board containing a target PIC24 microcontroller on which programs created during the exercises can be observed to be running in real-time. As well as using the XC16 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 course also cover details of the implementation of fixed tables of data in program memory

Course Outline

  • Overview of Development Tools
    • Microchip development software: MPLABX and associated tools
    • XC16 'C' compiler
    • Microchip In-Circuit Debugger (ICD3) hardware
    • Overview of available development boards
  • The PIC24 and dsPIC Architectures
    • Harvard versus Von Neumann architecture
    • Organisation of data memory
    • On-chip peripherals
    • In-Circuit Serial Programming (ICSP)
    • Differences between the PIC24 and dsPIC processor architectures and instruction sets.
  • The XC16 Compiler
    • Key features and ANSI C extensions to support the 16 bit processor architectures
    • XC16 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 interrupt handlers using XC8
  • 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
  • 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