Getting Started With Pics
Getting Started With Pics
Getting Started With Pics
Introducing Microcontrollers in
Grade Twelve Computer Engineering
Brad North
Agenda
What is a Microcontroller?
Where are Microcontrollers Used?
Why Use Microcontrollers in G12?
What You Need to Get Started
P16F84 Characteristics
“The PIC Process”
Resources
Questions
What is a Microcontroller?
“A computer inside a
chip”:
– CPU
– ROM
– RAM
– Bi-directional
ports
– Interrupts
– Internal clock
– Many other
functions……
Where Are Microcontrollers
Used?
DVD, TV, VCR
XBOX, Nintendo, Game Boy
Carbon Monoxide Alarms
PDAs, cellphones
Automobiles
Garage door openers
Household appliances
Automatic pilot systems
Astronauts’ space suits
Why Use Microcontrollers in G12?
Students are highly motivated
Potential to expand and
modify projects is unlimited
Reasonably priced – P16F84 -
under $9 each
Free Software and documents
Covers many Ministry
Expectations
ICE 4MO Ministry
Expectations …
Compare high-level and low-level programming
languages
Explain how to determine memory requirements for
information storage
Describe the function and interaction of a control unit,
arithmetic logic unit, and memory registers in a simple
CPU
Use a diagram to illustrate how buses move data and
instructions between memory and the CPU.
Explain several computer-controlled systems that interact
with real-world devices
…ICE 4M Ministry
Expectations
Describe the constructs of a simple assembly or
machine-level language
Identify similarities and differences among
memory addressing techniques
Design an effective system consisting of a
computer and interface that integrates input and
output devices
Write programs to process input and control
output devices through interfaces
Write low-level programs
What You Need To Get
Started
Hardware 1. P16F84 & 18-pin DIP socket
2. 4 MHz crystal oscillator
3. Breadboard, 7805, LEDs,
resistors
4. Programmer
5. Power adapter
6. Parallel port cable
Software
• MPLAB IDE v5.70
• Programmer Software
• Programmer Firmware
Documentation/Resources
• P16F84 Datasheet (.pdf)
• MPLAB Manual and Tutorial (.pdf)
P16F84
Characteristics
Datasheet
1024 x 14 program
memory
68 x 8 User RAM
Registers (data
memory)
13 Bi-directional
ports
Internal oscillator
Interrupts
1. Harvard Architecture
2 separate memory blocks , which
can be accessed simultaneously:
i. Program Memory
ii.Data Memory
i. Program Memory
Flash EEPROM – where your
program from assembler code is
written to.
Program memory bus is 14 bits
wide (Mid-Range PIC MCUs)
PIC16F84 has 1K x 14 bits of
program memory space = 1,024
words x 14 bits
Addresses are in hex: last
available address is 3FF
ii. Data Memory
12 Special
Function Registers
(SFR) which control
the PIC
68 General
Purpose
Registers (GPR)
First GPR is
0Ch
Last is 4Fh
2. Instruction Cycle/Clock Cycle
• RISC – 35 Word Instruction Set
• All instructions are processed in one
instruction cycle except for program
branches (i.e. subroutine)
3. W (Working Register)
8-bit register – also referred to as the
"accumulator" in other MPUs
ALL data must be placed into the W
register first, then moved from the W
register to any other register (i.e.
MOVLW, MOVF)
“The PIC Process”
Coding & Assembling in MPLAB 5.70 Downloading to the programmer
using PICALLW
Building Circuit
& testing, editing
1. Write Source Code
Text editor
(.asm file)
RISC
Instruction
Set
35 instructions
Mnemonic
instructions
and operands
are the
“commands”
used to write
the code
Coding Structure
Label Field
2. Assemble Code (MPASM)
3. Object Files Created
1. PICSTART PLUS
– Download via
MPLAB
2. P16PRO/PICALL
Download .hex file
via PICALLW
Resources
Documentation and MPLAB software
– www.microchip.com
Programmer Software
– 2 options
1. PICSTART PLUS
– Part and parcel of MPLAB
– $US200
2. P16PRO/PICALL
– $US20/30 assembled
– www.electronics123.com
Programmer Firmware (for P16PRO/PICALL)
– $US20
– www.picallw.com
Additional Resources
Easy PIC’n
– Benson, David (www.sq-1.com)
Poptronics Magazine
– PICtronics section (www.poptronics.com)
?