Microchip 8 bit Microcontroller 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 8 bit Microcontroller family is characterised by the fact that as one moves from the low end microcontrollers such as the PIC10, PIC12 on to the PIC16 and PIC18 families so more instructions are added to the instruction set. Also the details of the memory architecture and interrupt handling change. Thus the PIC18 has two interrupt priority levels whereas the PIC16 has just one level of interrupt.
This course will cover the entire range of 8 bit microcontrollers. It will also 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 microprocessor architectures, instruction sets and basic programming at the level of instruction sets.
Laboratory Workshops
- Program object code into a target PIC16 / PIC18 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 PIC16 and PIC18 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
- 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
- Implement 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
- 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
- Differences in instruction sets and memory architecture between PIC16 and PIC18 microcontrollers
- The need for small, cheap and simple microcontrollers
- Overview of the PIC10 and PIC12 families and their uses
- The PIC10 and PIC12 instruction sets viewed as subsets of the PIC18 instruction set
- Understanding microcontroller pinouts and schematic diagrams
- The PIC 8 bit Microcontroller Instruction Sets
- Data Transfer Instructions
- Arithmetic Logic Instructions
- Bit-oriented Instructions
- Program Control Instructions
- Other Instructions
- Understanding PIC 8 bit Microcontroller Addressing Modes
- Direct addressing
- Register Direct Addressing
- Register Indirect Addressing
- Indexed Addressing
- Special Function Registers and Ports
- The need for Special Function Registers
- STATUS Register
- OPTION_REG Register
- INTCON Register
- PIE Register
- PIR Register
- PCON Register
- PCL and PCLATH Registers
- TRIS Registers
- PORT Registers
- ANSEL and ANSELH Registers
- Overview of Peripheral Associated Special Function Registers
- Designing and implementing programs and applications
- Requirements analysis
- Describing algorithms using pseudo code (structured English)
- Describing algorithms using flow charts
- Basic template for a PIC16/PIC18 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 PIC16 and PIC18
- Interrupts and Event Driven Systems
- Synchronous vs. Asynchronous Event Handling
- Template for implementing an interrupt handler
- Effective use of high and low level interrupt priorities in the PIC18
- 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