0% found this document useful (0 votes)
67 views

PIC Intro 0

This document introduces PIC microcontrollers and provides recommendations for setting up a PIC programming environment. It discusses the different families of PIC microcontrollers and recommends the PICkit 3 programmer and MPLAB X IDE for beginners. The document also mentions different compilers that can be used for PIC programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
67 views

PIC Intro 0

This document introduces PIC microcontrollers and provides recommendations for setting up a PIC programming environment. It discusses the different families of PIC microcontrollers and recommends the PICkit 3 programmer and MPLAB X IDE for beginners. The document also mentions different compilers that can be used for PIC programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

© Gooligum Electronics 2013 www.gooligum.com.

au

Introduction to PIC Programming


Baseline to Enhanced Mid-Range Architecture

by David Meiklejohn, Gooligum Electronics

Lesson 0: Recommended Training Environment

About PICs
“PIC”
refers to an extensive family of microcontrollers manufactured by Microchip Technology Inc. –see
www.microchip.com.
A microcontroller is a microprocessor which has I/O circuitry and peripherals built-in, allowing it to
interface more or less directly with real-world devices such as lights, switches, sensors and motors. They
simplify the design of logic and control systems, allowing complex (or simple!) behaviours to be designed
into a piece of electronic or electromechanical equipment. They represent an approach which draws on
both electronic design and programming skills; an intersection of what was once two disciplines, and is
now called “embedded design”.
Modern microcontrollers make it very easy to get started. They are very forgiving and often need little
external circuitry.

Among the most accessible are the PIC microcontrollers.


The range of PICs available is very broad –from tiny 6-pin 8-bit devices with just 16 bytes (!) of data
memory which can perform only basic digital I/O, to 100-pin 32-bit devices with 512 kilobytes of memory
and many integrated peripherals for communications, data acquisition and control.

One of the more confusing aspects of PIC programming for newcomers is that the low-end devices have
entirely separate address and data buses for data and program instructions. When a PIC is described as
being 8- or 16-bit, this refers to the amount of data that can processed at once: the width of the data
memory (registers in Microchip terminology) and ALU (arithmetic and logic unit).
The low-end PICs, which operate on data 8-bits at a time, are divided into four architectural families:
 Baseline (12-bit instructions)
These PICs are based on the original PIC archi
Instrument’s “Peripheral They are quite Interface
limited, but, within their Controller”
limitations (such as having no interrupts), they are simple to work with.
Modern examples include the 6-pin 10F200, the 8-pin 12F509 and the 14-pin 16F506
 Mid-Range (14-bit instructions)
This is an extension of the baseline architecture, adding support for interrupts, more memory and
peripherals, including PWM (pulse width modulation) for motor control, support for serial, I2C
and SPI interfaces and LCD (liquid crystal display) controllers.
Modern examples include the 8-pin 12F629, the 20-pin 16F690 and the 40-pin 16F887

Introduction to PIC Programming, Lesson 0: Recommended Development Environment Page 1


© Gooligum Electronics 2013 www.gooligum.com.au

PIC Programmers and Debuggers


There are many PIC programmers available, including some that you can build yourself.
Once upon a time, PICs could only be erased by shining UV light through a window on the chip (except
for parts without a window, which could only be programmed once), and programmed by placing them
into a special programmer.
These days, PICs use electrically erasable flash memory. They can be programmed without having to be
taken out of the prototyping (or even production) environment, through a protocol called In-Circuit Serial
Programming (ICSP). But instead of worrying about designing your circuit to accommodate the ICSP
protocol, it can easier (especially for small PICs, where you may not have spare pins available to dedicate
to the programming function) to remove the PIC from your circuit and place it into a development board
or programming adapter connected to an ICSP programmer. A programming adapter is simply a minimal
circuit which allows a PIC to be programmed by an ICSP programmer.
It’s a really good idea to with buy an ICSP
a development board or a programmer
programming adapter, while keeping the option of later using
ready for that.

An excellent PIC programmer to start with is Microchip’s


PICkit 3, shown on the right.
Although there are cheaper equivalents available3, the
PICkit 3 is not expensive, available for around US$45.
And being a Microchip product, you can be sure that it
will work with Microchip’s tools, and development
(importantly!) PICs.
The PICkit 3 can also work as a debugger, as long as the
PIC you are using supports hardware debugging (meaning
that it has special debug circuitry built in). Although these
tutorials don’t cover hardware debugging, it is a ve
own projects –it allows you to see exactly what the PIC is doing by stepping through your code an
instruction at a time, or stopping at a particular location (a ‘breakpoint’), and
of the PIC’s internal your program’s registers variables.
and A hardwa
“what on Earth is that PIC doing?” ogrammer And is the
that great
you get a capable hardware debugger as well, because they do that, too.
When you become more experienced, and/or work on bigger PICs, you may want to step up to a more
capable (and of course more expensive) D 3 or REAL ICE. Butdebugger,
to start
with, a PICkit 3 is ideal.

Development Software
Every PIC developer should have a copy of Microchip’s d developmentMPLAB
environment integra
(IDE) –even if you primarily use a third-party tool chain (a set of development tools that work together).
It includes Microchip’s assembler (MPASM), an edi
debug your application before committing it to the chip. Not long ago, a development environment as
sophisticated as this would have cost thousands. But MPLAB is free, including support from Microchip,
so there is no reason not to have it. Download it from www.microchip.com.

3
Such as the PICkit 2, described in the baseline and mid-range lessons. Although a capable programmer, it does not
support enhanced mid-range PICs, and therefore the PICkit 2 is no longer recommended for use with these tutorials.

Introduction to PIC Programming, Lesson 0: Recommended Development Environment Page 4


© Gooligum Electronics 2013 www.gooligum.com.au

MPLAB directly supports the PICkit 3 as a programmer for pretty much every modern baseline, mid-
range and enhanced mid-range PIC.
Microchip provides and supports two different “MPLAB” products.
For many years, MPLAB had been only available as a Windows application, and the latest versions are
numbered 8.xx –the most recent at the time of writing (October 2013) is v8.92. We can refer to this as
MPLAB 8. It’s very stable,
d has all easy to use, an
the features we need.
However, Microchip has found it difficult to add additional features to MPLAB, or to meet requests to
have it run on platforms other than Windows. The
replacement, called MPLAB X, which also runs on Linux and Mac OS X. MPLAB 8 is now effectively
be retired, with all new development, including support for new tools, compilers and PICs, being for
MPLAB X.
Therefore, although the older baseline and mid-range tutorials describe both MPLAB 8 and MPLAB X,
the enhanced mid-range tutorials focus only on MPLAB X4.

MPLAB 8 includes a free copy of CCS’s PCB C compiler for Windows, which supports most baseline
PICs, including those used in these tutorials. Although it’s now
d (at the time ofawriting,
littlethe date
version bundled with MPLAB was 4.073, while the latest commercially available version was 5.013), it
remains useful and is used in the baseline C tutorials.
The Microchip XC8 C compiler can be downloaded from www.microchip.com. It supports all of the
baseline, mid-range and enhanced mid-range PICs, and is available for Windows, Linux and OS X. It can
be used for free, Free mode”,when runningbut within most “
–meaningoptimisation
that it
generates much larger code than the paid-for commercial versions. However, co
much for the small example programs in these tutorials, so the free version of XC8 is used in the baseline,
mid-range and enhanced mid-range C tutorials.

Prototyping
If you use an ICSP programmer, then you’ll need a
also need to be able to test your PIC in a real circuit, before building the final design.

One solution, satisfying PICkit both 3 Lowthese


Pin Count (LPC)purposes,
Demo is
Board” . It is available for around US$26, including a PIC16F1829 and PIC18F14K22. Or you can buy a
“PICkit 3
Starter Kit” bundle, including programmer, LPC DemoaBoard,
PICkit
PIC16F18293 and
PIC18F14K22, for around US$60. That’s excellent value; given th
everything you need to get started, including a programmer, demo board and PIC chips, for only US$60!
It includes four LEDs, a pushbutton switch and a trimpot (variable resistor). Above this, a prototyping
area is provided. The IC socket supports all of the modern (flash memory based) 8-, 14- and 20-pin
baseline, mid-range and enhanced mid-range PICs. Note that it does not support the 6-pin 10F PICs, even
when they are in 8-pin DIP package.
Most of the I/O lines are brought out to the 14-pin header on the side of the board, allowing it to be
connected to another circuit. For example, a prototype circuit can be constructed on a breadboard and the
power and signal lines connected back to the header on the LPC Demo Board. This arrangement allows
you to develop a complex circuit with no need to remove the PIC from its socket for programming; the
PICkit 3 can remain plugged into the LPC Demo Board during development.

4
MPLAB 8 supports the devices used in the enhanced mid-range PIC tutorials and can be used with those lessons if
you are already comfortable with MPLAB 8. However, it is unlikely to support future enhanced mid-range devices.

Introduction to PIC Programming, Lesson 0: Recommended Development Environment Page 5


© Gooligum Electronics 2013 www.gooligum.com.au

Unfortunately, the LEDs on the LPC Demo Board can only be used with 14- and 20-pin PICs, not the 8-
pin devices. The board also doesn’t come with jumpers installe
LEDs and trimpot can be selectively disconnected, to avoid interference with the rest of your circuit.
Many of the tutorial lessons require the use of parts not included on the LPC Demo Board, such as
photocells, crystal-driven oscillator circuits, and 7-segment LED displays. Although it is possible to build
all of these circuits on a breadboard, connected to the LPC Demo Board, it is a little cumbersome to do so,
for some of the more complex circuits.
And of course you need to obtain all the necessary parts.
To avoid these problems, we have developed a training and development board, specifically for use with
the baseline, mid-range and introductory enhanced mid-range tutorials, as shown below.

Introduction to PIC Programming, Lesson 0: Recommended Development Environment Page 6


© Gooligum Electronics 2013 www.gooligum.com.au

It works with a PICkit 3 programmer, and supports all 8- and 14-pin baseline, mid-range and enhanced
mid-range PICs, as well as all 6-pin 10F devices (in an 8-pin DIP package). It is fully configurable using
the provided jumpers, and comes with all of the hardware needed for the baseline and introductory mid-
range and enhanced mid-range tutorials, including all the required PICs. Add-on parts kits, such as a
motor-control kit, allow the board to be used with more topics covered in more advanced lessons.
Every PIC pin is brought out to the header at the bottom of the board, allowing the easy prototyping on the
breadboard of circuits not provided by the onboard components, including circuits which require more
than the 20 mA that a PICkit 3 can deliver, through the use of an external regulated DC power supply.

A number of other prototyping boards are available from various of sources, including Microchip. Some
of these include more advanced peripherals, such as LCD displays, while others are intended to be an
introduction to “mechatronics” (microcontroller
-controlled robotics), and include motors, gears, etc. And
some are intended to be general development boards, offering as much flexibility and expansion as
possible. Most of these boards can of course be adapted for use with these tutorials.

However, the examples in these tutorials are intended to be used directly, without modification with the
Gooligum Baseline and Mid-range PIC Training and Development Board.

Recommendation
To make a start in PIC development,
do better it’s
than the low-cost combination of: difficul
 PICkit 3 programmer
 Gooligum Baseline and Mid-Range PIC Training and Development Board
 MPLAB X integrated development environment
These tutorials assume that you are using that recommended combination. However, most of the lesson
content is of course applicable to other development environments, including the Microchip Low Pin
Count Demo Board, but you may need to modify the examples to work correctly in those environments.

Other than a PC, the only other thing you need is a PIC!
If you purchase the Gooligum training board, it will come with all the necessary PICs.
Otherwise, to follow all the lessons exactly, you will need one each of:
 PIC10F200 or PIC12F508
 PIC12F509
 PIC16F506
 PIC12F629
 PIC16F684
 PIC12F1501

It is possible to adapt the lessons to other baseline and mid-range PICs by reading the data sheets, but of
course it’s easier to work with those listed here

Good luck!!

Introduction to PIC Programming, Lesson 0: Recommended Development Environment Page 7

You might also like