Course M201 - PIC24 Architecture and Assembly Language 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 sets of the PIC24 family of microcontrollers and how to develop assembler code for these processors. Familiarity with a Windows, Linux or MAC OSX workstation, 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 XC16 assembler for Microchip 16 bit microcontrollers.
Synopsis
This hands-on course aims to provide engineers with an understanding of of the capabilities and architecture of the standard Microchip 16 bit microcontrollers and, also, to provide practical experience of designing and implementing applications for these processors in assembler. As well as covering in depth the architecture and features of the PIC24 family of microcontrollers, the course provides hands-on experience of Microchip MPLABX based development tools for creating and debugging assembly language programs on target PIC24 microcontrollers. Practical labs include- Programming object code into target microcontrollers using MPLABX and ICD3.
- Creating, building and debugging new assembly language projects using MPLABX and ICD3
- Understand the components of an assembly source file
- Setting the microcontroller configuration options appropriately for the target system
- Using digital I/O ports to interact with the outside world
- Manipulating data memory using direct and indirect addressing
- Creating time delays using software loops and hardware timers
- Taking advantage of interrupts to handle events in the background
- Implementing 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
- The Architecture of the PIC24 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
- PIC24 Interrupt Vector model
- On-chip peripherals: overview and detailed description
- Special features: e.g., clock options, sleep mode, watchdog timer, brown-out detection
- The XC16 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