Mid-Range PIC C Programming Tutorials
The following tutorials build on the material covered in the mid-range assembler tutorial series, showing how to implement the example applications from those lessons, using Microchip's XC8 C compiler (running in "Free mode").
To get the most out of these lessons, you should purchase the Gooligum baseline and mid-range training and development board,
which was designed to complement this tutorial series.
Free samples
Download the free mid-range C lessons (1-5) as a single zip file: midrange_C_free.zip
or access them individually:
Click on the lesson title to read each lesson (PDF).
Right-click the source code links to save the code for that lesson to your PC.
Note: PIC12F629 Programming Issues
Workarounds for a couple of issues you may encounter as you work through the first lessons, especially if you are using a PICkit 2 programmer
1: Basic Digital I/O
Introducing XC8
Using delay loops to flash an LED, reading and debouncing simple switches, and using weak pull-ups on mid-range PICs
Updated 14/9/12 |
L1 source |
2: Using Timer0
Configuring and accessing Timer0
Using Timer0 for debouncing, background tasks, event timing and counting
(with an example of C macros)
Updated 16/9/12 |
L2 source |
3: Introduction to Interrupts
Interrupt service routines, Timer0 and external interrupts, debouncing
Updated 17/9/12 |
L3 source |
4: IOC, Sleep Mode and the Watchdog Timer
Using interrupt-on-change, sleep mode, and the watchdog timer
Updated 17/9/12 |
L4 source |
5: Reset, Power and Clock Options
Oscillator (clock) modes, power-on reset and brown-out detection
Updated 17/9/12 |
L5 source |
Additional lessons included with the Gooligum training board
(also available for separate purchase on the main tutorials page)
6: Analog Comparators
Using the single and dual comparators and programmable voltage reference
on the PIC12F629 and PIC16F684
Revised 28/6/12 |
7: Driving 7-Segment Displays
Single and multiple 7-segment displays, lookup tables and interrupt-driven multiplexing
Revised 3/7/12 |
8: Analog-to-Digital Conversion and Simple Filtering
Analog-to-digital conversion (ADC) and
using arrays and simple integer expressions to calculate a moving average
Revised 24/7/12 |
9: Timer1
Using Timer1 as a general 16-bit timer/counter, with an external watch crystal,
operation in sleep mode, and digital and comparator gate control
Revised 31/7/12 |
10: Timer2
Using Timer2 as a simple 8-bit timer, with period register and postscaler,
to generate a specific interrupt time-base
Revised 1/8/12 |
11: CCP, part 1 - Capture and Compare
Using the CCP module's capture and compare modes to measure signal and pulse widths
and to trigger precisely timed events, including periodic analog sampling
Added 9/11/12 |
12: CCP, part 2 - PWM
Using the CCP module's pulse-width modulation (PWM) modes for tasks including
tone generation, LED dimming and bi-directional brushed DC motor control
Added 6/4/13 |
Additional lessons are being compiled, and will be emailed to training board or CD purchasers, as they become available.
PDF files are read with free Adobe Reader software.
Return to Main Page
|