Microchip PIC32 Assembly Language Programming
Duration: 5 Days
Course Background
A knowledge of assembly language programming is a key skill for small embedded systems application developers. Not only does an understanding of the microcontroller instruction set help with debugging, it can be used to optimise code in resource constrained systems. It is also an important skill to have when implementing applications that are a mix of assembler and C code and when implementing low level device drivers. The Microchip 32 bit Microcontroller family with its MIPS architecture has an instruction set based on the original MIPS instruction set. The PIC32 processor core is based on the M4K core from MIPS Technologies. It supports a 16 bit instruction mode (MIPS16e) for more compact code. It also supports User and Kernel modes of operation which are especially useful when implementing and operating system, and has a multiply-divide unit.
This course will cover techniques for modular programming in assembler and the structured use of macros. It should also be of use to those teaching or developing computer science courses who will be delivering a module on more advanced microprocessor architectures, instruction sets and programming at the level of instruction sets.
Laboratory Workshops
- Program object code into a target PIC32 microcontroller using MPLABX and ICD3
- Create, build and debug new assembly language projects using MPLABX and ICD3
- Use the MPLAB X Simulator to simulate and debug code prior to programming it into a target device
- Understand the components of an assembly source file
- Setting the PIC32 configuration options appropriately for the target system
- Use digital I/O ports to interact with the outside world
- Manipulating data memory using direct and indirect addressing
- Create time delays using software loops and hardware timers
- Writing code for interrupt handling and stack manipulation
- Take advantage of interrupts to handle events in the background
- Jump and call routines across pages in program memory
- Use of PC-relative addressing to implement look-up tables
- Implementing robust design techniques to protect against malfunctions
Course Prerequisites and Target Audience
Basic knowledge of programming and working with PC tools is assumed. Attendees are also expected to have a working knowledge of number systems decimal, octal, hexadecimal and binary and basic logic operations such as AND, OR, Exclusive OR and NOT. An appreciation of basic approaches to structured programming would also be helpful.
Course Outline
- Market profile
- product range
- key advantages and support network
- Microchip development software: MPLABX and associated tools
- Microchip In-Circuit Debugger (ICD3) and In-Circuit Emulator (ICE) hardware
- Device programmers, and the design option of In-Circuit Serial Programming (ICSP)
- Demonstration boards and kits
- Third-party development tools
- The difference between a microcntroller and a microprocessor
- Harvard versus Von Neumann architecture
- Organisation of program and data memory
- RISC architecture with multiple working registers
- Op-codes and addressing modes: immediate, direct and indirect
- On-chip peripherals and interrupts
- Classes of operations performed by op-codes
- The System Clock
- Resets and Reset circuits
- PIC32 I-side and D-side buses
- Understanding microcontroller pinouts and schematic diagrams
- The PIC32 Microcontroller Instruction Sets
- Load and Store Instructions
- Computational Instructions
- Jump and Branch Instructions
- Miscellaneous Instructions
- Coprocessor Instructions
- Understanding PIC32 Microcontroller Addressing Modes
- Immediate I-type CPU instructions
- Jump J-type CPU instructions
- Register Indirect Addressing
- Registered R-type CPU instructions
- Special Function Registers and Ports
- The need for Special Function Registers
- CP0 Registers - Coprocessor0 Interface - Status and Control Information
- HWREna
- BadVAddr
- COUNT Register
- COMPARE Register
- STATUS Register
- Intctl - Interrupt Control Register
- SRSCtl Register - Control of GPR shadow sets
- SRSMap Register and its use in interrupt handling
- Cause and EPC (Cause of Last Exception and Program counter at last exception registers)
- PRid and EBASE Registers (Processor identification and revision and Exception BASE address registers)
- Config/Config1/Config2/Config3 (Configuration registers)
- Debug/Debug2/ (Dbug control/exception status and EJTAG control)
- DEPC - Program counter at last debug exception
- ErrorEPC - Program counter at last error
- DeSAVE - Debug handler scratchapad register
- ErrorEPC - Program counter at last error
- MIPS16e Mode and memory model
- CPU Initialisation
- PIC32 Memory Organisation
- Control Registers
- Memory Layout
- Address Mapping
- Bus Matrix
- I/O Pin Control
- Operation
- Control Registers
- Designing and implementing programs and applications
- Requirements analysis
- Describing algorithms using pseudo code (structured English)
- Describing algorithms using flow charts
- Basic template for an PIC32 assembler language application
- Brief Introduction to Structured Analysis and Design using Ward-Mellor / Hatley Pirbhai / Jackson methodologies
- Context Diagram
- Flow diagrams
- Control diagrams
- Finite State Machines
- Function mini-specs and pseudo code
- Macros
- Macros as pattern substitution
- Macros with parameters
- Macros and subroutines compared
- Macros with parameters
- Common Macro based patterns and idioms
- Interrupts
- The interrupt handling architecture of the PIC32
- Interrupts and Event Driven Systems
- Synchronous vs. Asynchronous Event Handling
- Template for implementing an interrupt handler
- Effective use of interrupt priorities in the PIC32
- Digital Inputs and Outputs
- Programming Digital Outputs
- Programming Digital Inputs
- Using Polling to detect input changes
- Using Edge Triggered Interrupts to detect input changes
- Debouncing
- Programming a matrix keypad
- Timers
- How timers work
- Timeout events and timeout handlers
- Capture Compare
- Pulse width modulation
- Timers for generating periodic events
- Timers and multi-tasking
- Analog Inputs
- Understanding Analog to Digital Conversion (ADC)
- ADC architectures
- Program templates for working with analog inputs
- Foundations of signal processing
- Use analog inputs to control and monitor
- Serial buses and Protocols
- RS232
- I2C
- SPI
- Introduction to multi-tasking