Uploaded by Tinus vdW

PIC Primer

advertisement
Introduction to PICs
and
Practical Work
Tinus van de Wouw
Tinus van de Wouw
Contents
▪
About PICs
–
–
–
–
–
–
–
–
▪
PIC Primer lessons
–
–
–
▪
What is microcontroller
Applications of microcontrollers
Computer basics
PIC internals
PIC16F690 Small Pin Count Demo board
Machine code
High Level Languages
Programming a PIC with Pickit 2 programmer
Assembler
JAL
for PIC Basic and C: to be worked out
Teacher's PIC Project!
Tinus van de Wouw
PIC Controllers
▪
'PIC' is trade name for Microchip microcontrollers
–
–
Very versatile low-cost µcontroller for many applications
Very flexible because software controlled
▪ Most parts can be re-programmed many times
▪ 'In Circuit Serial Programming': device stays in application
▪
PICs from Microchip
–
–
–
–
▪
Widely available, good support, good tools, many new parts
Good language support: ASM, C, Basic, JAL
Nice cheap demo boards
Many discussion groups on Internet
Competitors / Alternatives
–
8051, Atmel AVR, Freescale 68HC, TI, Arduino
Once you know how to program PICs: others are similar.
–
http://www.voti.nl/pic/index.html & http://www.voti.nl/swp/index.html
–
Tinus van de Wouw
What is a Microcontroller?
▪
A microcontroller (also µC, uC or MCU) is a small
computer on a single integrated circuit containing:
–
Processor core
Memory
–
Programmable input/output peripherals
–
▪
▪ RAM
▪ Program memory (OTP-ROM or Flash)
They may include special circuits such as
–
–
–
–
–
–
Timers
A/D (sometimes D/A) converter
Serial: UART, I²C, CAN
PWM
USB
Special functions: RF (4.33 GHz)
Tinus van de Wouw
Applications of Microcontrollers
▪
Microcontrollers are used in a wide variety of automatically
controlled products and devices such as
–
–
–
–
–
–
–
–
–
–
–
–
–
Automobile engine control systems
Implantable medical devices
Appliances
Remote controls
Office machines
Power tools
Motor controls
Robotica, mechatronics
Production Equipment
Toys
Battery chargers
Mixed signal environments
Traffic lights
Tinus van de Wouw
Computers – ALU / CPU
▪
▪
▪
▪
An ALU (Arithmetic Logic Unit) or
CPU (Central Processing Unit)
can perform mathematical
actions on bytes such as add
them, shift a register (i.e. multiply
with 2) etc.
The ALU is the heart of a
microcontroller
But we need space to store
results and also space to tell the
CPU what to do
For that we need memory
Tinus van de Wouw
Computers – Memory
▪
▪
▪
▪
▪
▪
In a memory we can store data, i.e.
write and read them
Each memory place has a unique
number called an “address”
We need to store instructions to tell
the CPU what to do: the program
And we can store initial numbers
and the results of the CPU.
Also we have Special Function
Registers (SFR) that define the
function of the system
The total memory normally consists
of various separate memories
Tinus van de Wouw
Computers - Bus
▪
▪
▪
Memory and CPU must communicate! For that we use a “bus”.
Busses are parallel connections between the CPU and the
memory (and other parts of the system)
There is a bus for data, for addresses and for control lines such
as a read-write line (or they are combined)
Tinus van de Wouw
Computers – I/O – Inputs / Outputs
▪
▪
▪
We need connections to the
outside world!
So, we connect some memory
locations (addresses) to special
circuits that make a connection
to the outside world:
I/O lines (input/output lines)
Such an I/O unit may have
various states:
–
–
–
–
digital: input, output or neutral (tri-state)
analogue: use A/D converter to process analog data
comparator inputs
or special functions such as serial, USB, timers
Tinus van de Wouw
Computers – A/D converter
▪
▪
▪
An A/D converter converts an analog input signal into a
digital signal: a binary number
This binary number may be used for many purposes such
as to display its value or set a time
Some A/D converters are pretty course (8-bit), but there
are also much more accurate versions
Tinus van de Wouw
Computers – Serial Communication
▪
▪
▪
The number of I/O
lines is limited by the
number of pins of a
device
To transfer large
amounts of data to and
from the computer we
often need Serial
Communication
For that we also need
an accurate clock
signal
Tinus van de Wouw
Computers – Clock
▪
▪
▪
A computer always has a clock1).
The clock determines the timing
of the whole system
Types of clock generators:
–
RC oscillator
▪ pretty inaccurate
–
Ceramic resonator
▪ pretty accurate ± 0.5%
–
Crystal oscillator
▪ very accurate ± 50 ppm
–
Sometimes: internal oscillator
▪ can be factory tuned to 1%
▪
External clock may be used
1) except in asynchronous systems
Tinus van de Wouw
Computer - Timers
▪
▪
▪
▪
▪
Special blocks inside a computer
are related to timed processes
such as time delays or automatic
resets
These timers perform
independently from the CPU
They may “interrupt” the on-going process and then
special tasks may be carried out
After that the program resumes
Examples of such special timers:
–
–
Watchdog Timer (WDT)
Brown-out Reset (BOR)
Tinus van de Wouw
Computers – Watchdog Timer & BOR
▪
▪
▪
▪
Many computers normally work stand-alone. If something
goes wrong, nobody is present to press the “reset switch”!
A Watchdog Timer (WDT)
performs an automatic reset
after a certain period of
non-activity
You may disable it, e.g. in
case of long time delays
A “Brown-out reset” (BOR) is a
circuit that monitors VDD.
Reset happens for dips below
a certain level.
Tinus van de Wouw
Computers –
Block Diagram
▪
▪
▪
Generic diagram
of a computer
All discussed
element are inside
a real computer
Busses for data
and addresses let
all parts
communicate with
each other
Tinus van de Wouw
PIC Internals (super simplified)
1.
2.
3.
The program to run is in a “flash
memory” (fixed but programmable).
RAM contains variable data
The instruction register tells the CPU
what actions to perform such as:
–
–
4.
I/O Pins
Tinus van de Wouw
5.
Add W register and place in RAM
Place any of the input/output pins in a
certain state
In reality there are more registers, a
clock generator, complex logic to
drive the I/Os, A/D convertor, timers,
multiplexers, program counter, stack.
Datasheet PIC16F690: 294 pages!
PIC16F690 Demo board
▪
We will use this demo board to do our first experiments
Tinus van de Wouw
PIC16F690
Internal Circuitry
▪
▪
▪
▪
▪
▪
▪
Very complex
structure
Re-programmable,
>100,000 times
Three banks1) of I/O
registers RA, RB, RC
On-board oscillator,
crystal also possible
Timers
UART
Many more functions
available
1)
Tinus van de Wouw
We'll discuss later
Pinning of PIC16F690
Many pins with more functions! Each pin has only one function at the time.
Pin functions are defined with special instructions. Some highlights:
▪
▪
▪
▪
▪
▪
VDD/VSS - power supply
RXn - Digital inputs/outputs (18)
Txx - Timers
OSC1-2, CLKxx - Oscillator
ANn - Analog inputs (12)
MCLR - Memory Clear
Tinus van de Wouw
▪
▪
▪
▪
▪
VPP & ICSP - for Programming (5)
Cxx - Comparators (2)
Sx/Rx/Tx - Serial ports
Ixx - Interrupts (8)
ULPWU - Wake Up (ultra low power)
RAM Memory Inside a PIC
▪
The amount of RAM differs for every PIC
–
–
–
–
▪
▪
▪
'508
'675
'690
'877
32
64
256
368
Part of RAM is also taken by Special
Function Registers. These specify PIC
functions and are very important
'508 example: set bit 5 in the GPIO register and
output 5 will be active
Often RAM is organized in "banks".
The program should first activate bank 0, 1, 2 or 3 before
certain data can be read or written.
Tinus van de Wouw
Special Function Registers
▪
▪
Special Function Registers determine the status of the PIC
e.g. which pins are analog input or digital I/O
They are in a special part of the memory
bank0
▪
▪
bank1
bank2
bank3
If PORTA = 011000 then bits 3,4 are on, 0,1,2,5 are off
TRISA determines if pins are input pins or output pins
Tinus van de Wouw
ADCON0 controls the
A/D convertor
e.g. bits 2-5 set which
channel is selected
Tinus van de Wouw
More Functions Found in PICs
▪
PWM – Pulse Width Modulation
–
–
▪
Interrupts
–
–
▪
▪
▪
▪
▪
▪
Precise Control of Motors
or other loads
Interrupt the current program
then temporarily do something else
USB i/o
Ethernet
WiFi
RF units
CAN (serial network protocol for cars) and I2C
Digital to Analogue convertor
Tinus van de Wouw
PIC 'Low Pin Count Demo board'
▪
▪
▪
▪
PIC16F690
▪ Memory Clear switch
Variable voltage to RA0/AN0 ▪ 4 LEDs driven by RC0...RC3
External connector
▪ Power connector (none, but...)
Connection to programmer (includes power) for ICSP
Tinus van de Wouw
Machine Code Inside the '690 PIC
▪
▪
▪
▪
▪
▪
The program memory contains
a series of 14-bit numbers →
The 'opcode', a 6-bit number in
the instruction register, tells the PIC what it has to do.
E.g.: 000111 = add W register and memory position f
Bit 7 sets the destination:
W register or
memory position f
Programming in Machine
Code is extremely
cumbersome!
Every PIC has its own
'instruction set'
Tinus van de Wouw
Tinus van de Wouw
Assembler Language: Low Level Programming
▪
▪
▪
▪
▪
▪
In assembler you first define: Delay2=127 and f=1
Then you write: ADDWF Delay2,f
The assembler program 'compiles' this to machine code:
00011111111111 = opcode dest 127 = h07FF
The code is sent as 'hex file' to the PIC.
At execution: W and f are added and the result goes to f
Assembler is easier to
do then machine code,
but still very cryptic
Also, very detailed
knowledge of the PIC
is still required, so....
Tinus van de Wouw
Higher Level Programming Languages
▪
▪
▪
'C', Basic and JAL are popular PIC languages
Powerful commands and functions.
The line PIN_D2_Direction = INPUT would imply:
–
–
–
▪
▪
▪
▪
Activate bank 2, set bit 2 in TRISD to 0
Activate bank 1 again
This is a very simple 'routine’ – often used in programming
In a higher level language there are many such routines
No need to worry about memory banks and special
function registers
The program including all the relevant routines is then
'compiled' into a hex code
This hex code is then programmed into the PIC
Tinus van de Wouw
Higher Level Programming Languages (2)
Tinus van de Wouw
Higher Level Programming
Tinus van de Wouw
Programming PICs
Writing the program
in the PC (in Assy,
JAL, Basic or C)
▪ Program is 'compiled'
to a hex file
▪ The hex file is sent to
the PIC via a
'programmer', in this
case a PICKIT2.
▪ Here using 'ICSP':
program the PIC
while it is still ‘hot’
(under power)!
▪
Tinus van de Wouw
Bootloaders
▪
▪
▪
▪
▪
▪
▪
Processors may have a “bootloader” built in.
A bootloader is a device with an extra part in memory with
a program that is run before the real program
If it detects a special status it can function as programmer
to load a program in memory!
Can be applied for devices with a serial port, but
nowadays it is very practical for devices with USB built in
A very good example is the very popular Arduino
Small Arduino boards with bootloader are very cheap!
We can do a very simple training if need be after the PIC
training sessions.
Tinus van de Wouw
Installing and Testing PIC Software
Tinus van de Wouw
Installation of MPLAB
▪
▪
▪
▪
Insert the training DVD
Open MPLAB IDE 8.70 and run setup.exe
Choose custom install!
Under Microchips Applications tick:
–
–
–
–
MPASM Suite
Hi-Tech C for PIC 10/12/16
PICkit2
Data Monitor and controller interface
▪
Untick the rest where possible (go through the list twice...)
▪
If you use 64-bit Windows then on the DVD right-click
“64_bit.bat“ and “Run as administrator”
Tinus van de Wouw
Installation Assembler Lessons1)
▪
▪
On the DVD open 'Pickit_Starter_kit’
and click “PICkit_Starter_Kit_Welcome.htm”
Click picture 'Starter Kit’, then Quick Start and install:
2. Install PICkitTM 2 Programmer application
3. Install PICkitTM 2 Lessons for the Startkit Low Pin Count Demo Board
▪
▪
▪
Right-click “Getting Started Guide to PICkit™ 2 Programming in MPLAB”,
‘Save target as...’ to C:\PK2 Lessons\LPC Demo Board
Click “Datasheets” in the left column, then right-click
“PIC16F685/687/689/690”, ‘Save target as...’ to the same place
Make a shortcut to “C:\PK2 Lessons\LPC Demo
drag the PIC
and MPLab
icons there.
Board\”
1) Assumes
Tinus van de Wouw
and
MPLAB is installed
Test the Demoboard
▪
First open the shortcut and test if it works:
–
–
–
–
▪
Save/restore contents of the demo board
–
–
–
–
▪
Connect Pickit2 with demo board to PC. Start .
Set VDD to "on" to start the program in the PIC.
You should see the running LEDS.
The speed can be controlled by the potmeter and the
direction by the switch.
At the PICkit2 screen (bottom right) you see
Click and then save the contents of the demo program as
"LPC_Demo_Org.hex“
You may later load it again in the PIC using
This is a very convenient way to reset the Low Pincount
Demoboard in the original state for other students
We are now ready for the demo board lessons!
Tinus van de Wouw
Essential: PIC Practicum - Assembler
▪
▪
▪
Use File Explorer to go to C:\PK2 Lessons\LPC Demo Board or
use the shortcut
Open ‘SK Getting Started in MPLAB.pdf’
Read it, follow the guidelines and adapt settings if needed!
–
–
Don’t try to understand everything yet - we will discuss later
Especially read the text following ‘IMPORTANT‘ on page 7!
▪
We will now discuss the "Hello World“ Introductory Lesson!
▪
It is strongly advised to do all (or at least the first few)
assembler lessons before using a higher level language
Then you will learn a lot about the structure of the PIC!
Open file ‘Low Pin Count User Guide DS51556a.pdf’
Next, self study: read pages 7-11 and start lessons from p.13
▪
▪
▪
Tinus van de Wouw
"Hello World"
Introduction Lesson Assembly Language
with
Low Pin Count Demo Board
Tinus van de Wouw
Structure of a PIC Program
▪
▪
Introductory comments - description of the program
Definition of "configuration bits"
–
–
▪
Definition of variables
–
–
▪
–
Definition of pins: Input ports, Output ports
Which pins are connected to ADC, UART etc.
Main program
–
▪
E.g. PORTA = 6, Delay = 20
Include a PIC16Fxxx.inc file (lookup file)
Set initial states
–
▪
Oscillator Selection , Code Protect, Watchdog Timer
They can not be changed after programming!
Most of the time in one or more loops
End statement
Tinus van de Wouw
‘Hello World’ Program (part 1)
;******************************************************************************
;Software License Agreement
;
;The software supplied herewith by Microchip Technology
;Incorporated (the "Company") is intended and supplied to you, the
;Company’s customer, for use solely and exclusively on Microchip
;products. The software is owned by the Company and/or its supplier,
;and is protected under applicable copyright laws. All rights are
;reserved. Any use in violation of the foregoing restrictions may
;subject the user to criminal sanctions under applicable laws, as
;well as to civil liability for the breach of the terms and
;conditions of this license.
;
;THIS SOFTWARE IS PROVIDED IN AN "AS IS" CONDITION. NO WARRANTIES,
;WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
;TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
;PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT,
;IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
;CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
; *******************************************************************
▪
▪
Lines with ; (a semicolon) are comments
This part is only a disclaimer for legal reasons
Tinus van de Wouw
‘Hello World’ Program (part 2)
; *******************************************************************
; PICkit 2 Lesson 1 - "Hello World"
; This turns on DS1 LED on the Low Pin Count Demo Board.
; *******************************************************************
; * See Low Pin Count Demo Board User's Guide for Lesson Information*
; *******************************************************************
; 690_nn refers to page nn in the PIC16F690 datasheet (2007)
; *******************************************************************
#include <p16F690.inc>
__config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF &
_CP_OFF & _BOR_OFF & _IESO_OFF & _FCMEN_OFF)
org 0
Start:
bsf STATUS,RP0
; select Register Page 1 - see 690_31: TRISC is in Bank 1
bcf TRISC,VAR
; make IO Pin C0 an output - TRISC: see 690__76
bcf STATUS,RP0
; back to Register Page 0
bsf PORTC,VAR
; turn on LED C0 (DS1) - PORTC: see 690__76
goto $
; wait here
end
Let's discuss the details...
Tinus van de Wouw
Comments
; **************************************************************
; PICkit 2 Lesson 1 - "Hello World"
; This turns on DS1 LED on the Low Pin Count Demo Board.
; **************************************************************
; See Low Pin Count Demo Board User's Guide for Lesson Information*
; **************************************************************
; 690_nn refers to page nn in the PIC16F690 datasheet (2007)
; **************************************************************
▪
▪
▪
First part: general remarks about the program, disclaimer,
author, revision, etc.
Text following ; are comments, they are no part of the real
program and not programmed into the PIC
It is a good habit to comment every line in your program!
You will need it when you edit your program later
Tinus van de Wouw
Include
include <p16F690.inc>
▪
▪
▪
▪
'include': the specified file is inserted in our program
An .inc file is a look-up file. It specifies variables that are
hardware dependent: they are different for most PICs
E.g. the '690 only has ports A, B and C. The '877 also has
ports D and E. So, variables PORTD and PORTE are
defined in the file p16F877.inc but not in p16F690.inc
Inside p16F690.inc:
Inside ' p16F877.inc':
...
PORTC EQU H'0007'
PCLATH EQU H'000A'
...
Tinus van de Wouw
PORTC
PORTD
PORTE
PCLATH
EQU
EQU
EQU
EQU
H'0007'
H'0008'
H'0009'
H'000A'
Configuration Bits and ORG
__config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF &
_MCLRE_OFF & _CP_OFF & _BOR_OFF & _IESO_OFF & _FCMEN_OFF)
▪
▪
Configuration bits set the status of the PIC at programming
See 'p16F690.inc' , section 'CONFIG Options'
_INTRC_OSC_NOCLKOUT EQU H'3FFC'
; INTOSCIO oscillator: I/O
function on RA4/OSC2/CLKOUT pin, I/O function on RA5/OSC1/CLKIN
_WDT_OFF
EQU H'3FF7'
; WDT disabled
▪
▪
▪
_INTRC_OSC_NOCLKOUT sets the internal oscillator
_WDT_OFF disables watchdog timer
Also see datasheet '690', page 194
ORG 0
▪
ORG 0 sets the start location of the program in memory
Tinus van de Wouw
The heart of the program!
Start:
bsf STATUS,RP0 ; select Register Page 1 - see 690_31: TRISC is in Bank 1
bcf TRISC,0
; make IO Pin C0 an output - TRISC: see 690__76
bcf STATUS,RP0 ; back to Register Page 0
bsf PORTC,0
; turn on LED C0 (DS1) - PORTC: see 690__76
goto $
; wait here
end
▪
▪
We want to set pin C0 as output --> we must use TRISC
In order to use TRISC we must first go to memory bank1
–
▪
▪
See memory map
bsf f,b means “set bit b in register f”
bcf f,b means “clear bit b in register f”
Tinus van de Wouw
Memory Banks
bank0
bank1
bank2
bank3
We will take the following steps:
1. Move to bank1 (set bit 0 in the STATUS register)
2. Clear bit 0 in TRISC to make C0 an output
3. Go back to bank 0 (clear bit 0 in the STATUS register)
4. Set bit 0 in PORTC to turn on the LED
Tinus van de Wouw
PORTx and TRISx
▪
▪
▪
PORTx sets each output state to 0 or 1
TRISx sets each port to input or output
ANSEL sets each port to digital I/O or analogue input
Tinus van de Wouw
The heart of the program!
Start:
bsf STATUS,RP0 ; select Register Page 1 - see 690_31: TRISC is in Bank 1
bcf TRISC,0
; make IO Pin C0 an output - TRISC: see 690__76
bcf STATUS,RP0 ; back to Register Page 0
bsf PORTC,0
; turn on LED C0 (DS1) - PORTC: see 690__76
goto $
; wait here
end
▪
bsf STATUS,RP0 sets bit RP0 in variable STATUS
–
▪
▪
▪
Next, clear bit 0 in TRISC (see p. 76 in the databook)
Then bcf STATUS,RP0 returns to bank0
Next, bsf PORTC,0 sets (= turns on) the output pin C0
–
▪
See page 31 in the datasheet: this selects bank 1 or 3.
See page 76 in the datasheet
Goto $ means go to the current address -> infinite loop
Tinus van de Wouw
First MPLAB Exercise
▪
▪
▪
▪
▪
▪
▪
Connect Pickit 2 with Demo board (using USB cable)
Start MPLAB
From menu: Programmer, Select Programmer, Pickit 2
From menu: File, Open Workspace...
Open “Hello World.mcw” from
C:\Pk2 Lessons\LPC Demoboard\01 Hello World
Double click on “Hello World.asm” and study the
assembler code. Read the document “Low Pin Count
Demo Board Users’ Guide” and check the code
From menu: Project, Build All
From menu: Programmer, Program
Tinus van de Wouw
The other lessons
▪
After this first lesson you should be able to cope with the
other lessons from the document 'Low Pin Count Demo
Board User’s Guide.pdf’
▪
Follow the lessons 1 - 7 and understand all explanations.
▪
After that you are ready to do the lessons in JAL or C
▪
JAL lessons 1 - 7 have the same goals as lessons 1 - 7 in
the Assembler lessons - read the comments!
▪
Once you have done this you are ready to start further
experiments with the PIC16F887A or other PIC controllers
on a breadboard
Tinus van de Wouw
Working through the SFR’s
▪
▪
▪
Also in higher level languages you may have to set bits in
Special Function Registers.
For an A/D converter you set clockscaling in ADCON1
Change ADCON0 to
–
–
–
▪
Select channel
Justification
VREF source
You will learn
about these when
you need them
and study the
datasheet/Internet
Tinus van de Wouw
After the Lessons
▪
▪
▪
▪
▪
When experimenting you may find that you need to
change MPLAB for the switch of the demo board to be
recognized.
Do the following to correct
From the menu: Programmer, Setting
Select the Settings tab
Check both these options
–
–
3-State on “Release from Reset”
Run after a successful program
Tinus van de Wouw
Connecting Pickit2 to the Breadboard
We made special cables to connect to breadboard
▪ Line up PGC and PGD pins with the 5 leads of
the cable to the Pickit 2
16F690
16F887(A)
▪
1 = VPP (to program), 2 = VDD (+5), 3 = VSS (GND)
Tinus van de Wouw
Tips for Doing PIC Experiments
▪
It is a good habit to decouple your power
supply near the active area with 100 nF
▪
If you use an external power supply, do NOT connect the
VDD from the Pickit2 programmer.
▪
Always connect all VSS and VDD pins
▪
When changing hardware components:
turn power off!
▪
Remove IC’s carefully in small steps
from 2 sides, otherwise bent leads
may result...
Tinus van de Wouw
Good luck with your projects!
Tinus
Tinus van de Wouw
PIC Primer for PIC Basic
▪
▪
First do: PIC Primer for Assembler!
Download and install PBPDemo6.exe
–
▪
http://melabs.com/downloads/PBPDemo6.exe
Get the document
'PICBASIC PRO Demo and Low Pin Count Demo Board.pdf'
and follow the guidelines
–
Exception: use the following path for your experiments:
C:\PK2 Lessons\LPC Demo Board\PICBASICPRO\
▪
▪
Start the lessons from the manual using the demo board
Alternative:
http://www.picbasic.co.uk/forum/showthread.php?t=15065
Tinus van de Wouw
PIC Primer for JAL1)
▪
▪
▪
JAL = “Just Another Language”
Simple high level language only for PIC programming
Install from the JAL folder on the DVD:
–
–
Goto http://code.google.com/p/jaledit/, run JALPack_2.4o.exe
Also download jaledit0.9.0.9.zip
▪ Drag and drop all folders in the ZIP to c:\jalpack
–
Go to http://www.microchip.com/pickit2.
▪ Find 'pk2cmd v1.20' and copy the zipped files to c:\jalpack\tools
- Do not use the version on de Pickit CD-ROM, it not suitable!
–
From c:\jalpack\jaledit run JalEdit.exe
▪ click Tools, Menu, Environment Options, Programmer
▪ set path to C:\JALPack\tools\pk2cmd.exe
▪ set options to -P -F%f -M -R -BC:\JALPack\tools -T
▪
▪
Start lessons as provided
Great primer:
http://justanotherlanguage.org/sites/default/files/jallib_files/Tutorial_Book_0.4.pdf
1)
Tinus van de Wouw
MPLAB not needed
JAL PIC Primer from DVD1)
▪
▪
JAL = “Just Another Language”, a simple
high level language, only for PIC programming
On the DVD go to folder JAL
–
–
–
▪
Run JALPack_2.4o.exe
Unzip jallib-0.9.0.9.zip drag and drop all folders to c:\jalpack
Unzip PK2CMDv1-20.zip and copy the files to c:\jalpack\tools
Go to c:\jalpack\jaledit and run JalEdit.exe
–
–
–
click Tools, Menu, Environment Options, Programmer
set path to C:\JALPack\tools\pk2cmd.exe
set options to -P -F%f -M -R -BC:\JALPack\tools -T
▪
Start JAL lessons in c:\jalpack\sample\LPDB
▪
Great intro: C:\JalPack\Docs\Jallib Starters Guide.pdf’
Lessons
1)
Tinus van de Wouw
MPLAB not needed
PIC Primer for Hi-Tech C –Lite1)
▪
On the DVD open folder 'Pickit_Starter_kit’
–
–
–
–
–
–
▪
Click “PICkit_Starter_Kit_Welcome.htm”
Select Debug Express
Click “2. Install PICkit™ 2 Programmer application”.
Test: Connect Pickit2 with demo board to PC. Start Pickit2
and under VDD click "on" to start the PIC program
Click ”3. Install PICkit™ 2 Lessons for the ... 44-Pin Demo Board”
And "4. Getting Started Guide to PICkit™ 2 Programming in MPLAB."
Next: execute the lessons
–
–
These lessons are meant for an 16F887
Essential: change all references for the 16F887 to 16F690!!!
1) Assumes
Tinus van de Wouw
MPLAB is installed
PIC Primer for C
MPLAB XC8
▪
Install from
http://www.microchip.com/mplabxc8windows
▪
Info:
ww1.microchip.com/downloads/en/DeviceDoc/52053B.pdf
▪
Follow the instructions in the Gooligum docs
http://www.gooligum.com.au/tutorials.html
Also see: http://www.andrewhazelden.com/blog/2012/01/setting-up-the-microchip-mplab-ide-and-c-lite-compilers-part-1/
Tinus van de Wouw
Teacher's PIC Project
Tinus van de Wouw
Teacher's PIC Project
Build a simple traffic light system for a normal crossing
▪ We will do this in small teams
▪ For cars: 2 x 3 LEDs:
4 seconds green, 2 seconds
yellow, 1 second all red
▪ Use PIC16F877A
▪ Programming language: Any
▪ Design, layout, build & test it!
▪ Discuss what must be done
to change the timing
▪ Ready: Friday, 12:00
▪ For specialists: add pedestrian switch: 1 green and 1 red
Tinus van de Wouw
Traffic Light with PIC 16F887
Power and
Traffic lights →
programming
Start up
and reset
PIC
Switch
Tinus van de Wouw
Crystal
oscillator
Alternative Teacher's PIC Project
Build a burglar alarm! We will do this in small teams
▪ In the house there are 3 switches that close when a
door/windows is opened
▪ Reset code to be done
with 3 switches to be
pressed in the right order
▪ Use PIC16F877(A)
▪ Programming language:
Any
▪ Design, layout, build &
test it!
▪ Ready: Friday, 12:00
Tinus van de Wouw
Download