First Technology Transfer

Standard and Advanced Technical Training, Consultancy and Mentoring

M102 - PIC18 Architecture and Assembler Programming

Duration: 4 Days

Intended Audience

This course is aimed at engineers with some understanding of microelectronics and programming who need to understand the architecture and instruction set of the PIC18 family of microcontrollers and how to develop assembler code for these processors.

Familiarity with a Windows, Linux or MAC OSX workstations, and with fundamental concepts such as bits, bytes, Boolean logic and addressing is assumed.

Some experience of assembly language programming on microprocessors or other microcontrollers will be useful background for an understanding of the more advanced concepts presented during this course. The course will be based on the Microchip MPLABX IDE and the MPASM assembler for Microchip 8 bit microcontrollers.

Synopsis

The course will teach the student how to

  • Program object code into target microcontrollers using MPLABX and ICD3.
  • Create, build and debug new assembly language projects using MPLABX and ICD3
  • Understand the components of an assembly source file
  • Set the microcontroller configuration options appropriately for the target system
  • Use digital I/O ports to interact with the outside world
  • Manipulate data memory using direct and indirect addressing
  • Create time delays using software loops and hardware timers
  • Take advantage of interrupts to handle events in the background
  • Implement fixed tables of data in program memory

Course Outline

  • Overview of Development Tools
    • Microchip development software: MPLABX, MPASM, Debug simulator and associated tools.
    • Microchip In-Circuit Debugger (ICD3) and In-Circuit Emulator (ICE) hardware
    • Device programmers and ICSP.
    • Demonstration boards and kits
    • Third-party development tools
  • The Architecture of the PIC18 Family of Processors
    • Harvard versus Von Neumann architecture
    • Design features: word length, pipelining and single-cycle execution
    • Organisation of program and data memory
    • Op-codes and addressing modes: immediate, direct, indirect, PC absolute and PC relative
    • Classes of operations performed by op-codes
    • Interrupt model - high and low level priority interrupts
    • On-chip peripherals: overview and detailed description
    • Special features: e.g., clock options, sleep mode, watchdog timer, brown-out detection
  • The MPASM Assembler
    • Assembler directives and op-codes
    • Programming style - use of templates and comments
    • Debugging assembly code using MPLABX, the Simulator debugger and ICD3
    • Interrupt service routines - how to create handlers using assembly code
  • The Linker
    • Overview of the linker and its relationship to the other MPLABX components
    • Use of linker scripts, command files and map files
    • Linker directives
    • Allocation of sections for relocatable code
    • Global and external declarations
    • Benefits of modular programming
    • Benefits of using libraries
    • Understanding and using maths libraries
  • Structured Programming Techniques for Assembly Language Programmers
    • Flow diagrams (including data flow and control flow)
    • State machine and state chart diagrams
    • Code specification using pseudo code (structured Natural Language)
    • Simple sequence diagrams
  • Functions - Implementating and Calling
    • Basic template for implementing and calling functions in assembler
    • Saving context before calling a function
    • Passing arguments to a function
    • Returning values from a function
    • Restoring context when returning from a function
    • Limitations of the PIC hardware stack and the nesting of function calls
  • Macros and macro pre-processing
    • Assembler directives
    • Inline code vs. function calls
    • Simple macros
    • Parameterised macros
    • Using macros to realise basic data structures
    • Using macros to capture complex logic
    • Using macros to realise parameter passing in function calls
  • Data structures and arrays
    • Importance of data structures for structured programming
    • Implementing data structures in assembler
    • Implementing and manipulating arrays in assembler
    • Creating and using read only data tables in code (flash) memory
    • Writing data into code (flash) memory
  • Serial communications protocols and peripherals
    • RS232
    • I2C and SPI
    • Bit banging techniques for realising serial communications protocols
    • Using on chip peripherals for realising serial communications protocols
  • Interrupts
    • Basic concepts
    • High and Low level prioritisation of interrupts
    • Integrating interrupt handling and application code
    • Layered interrupt handling
    • Circular buffers and interrupt handlers
    • Design considerations for low vs. high level interrupt prioritisation
  • Timers and their uses
    • Fundamental concepts
    • Timer interrupts and their uses
    • Timers and pulse-width modulation
    • Timers and data sampling and acquisition
    • Timers and task scheduling
  • Finite State machines and multitasking
    • Understanding Finite State Machines (FSMs)
    • Graphical representation of FSMs using UML notation
    • Realisation of FSMs in assembler
    • Limitations of FSMs
    • Software only approaches to multi-tasking
    • Interrupt driven approaches to multi-tasking
    • Hybrid interrupt and software approaches to multi-tasking