Você está na página 1de 42

An Introduction to PIC Microcontrollers

Supervised by : Dr. Loai Tawalbeh


ordan !niversity o" Science # Technolo$y
%aculty o" Co&puter # In"or&ation Technolo$y
Computer Engineering Department
Rami Mohammad Al-Sheikh
Fady Ahmad Ghanim

Family Core Arch Family Core Arch . .
Differences Differences
Overview
PIC16F877A Features PIC16F877A Features
PIC16F877A Memory PIC16F877A Memory
PIC16F877A Periherals PIC16F877A Periherals
PIC16F877A Instruction !et PIC16F877A Instruction !et
Intro"uction Intro"uction
Different Architectures Different Architectures
Intro"uction

What is PIC?
- A family of Harvard architecture microcontrollers
made by Microchip Technology
- erived from the PIC!"#$ originally developed
by %eneral Instrument Microelectronics ivision&
- The name PIC 'as originally an acronym for
(Programmable Intelligent Computer(&
Intro"uction

Why PIC is popular?

lo' cost )'ide availability 'ith high cloc* speed

availability of lo' cost or free development tools

+nly ,- instructions to remember

serial programming and re-programming 'ith flash


memory capability

Its code is e.tremely efficient) allo'ing the PIC to


run 'ith typically less program memory than its
larger competitors

PIC is very small and easy to implement for non-


comple. problems and usually accompanies to the
microprocessors as an interface
#wo Different Architectures

Harvard Architectures
/ne'er arch&0

1on-2eumann
Architecture
#wo Different Architectures

Harvard Architectures

3sed mostly in 4I5C CP3s

5eparate program bus and data


bus6 can be of different 'idths

7or e.ample) PICs use6

ata memory /4AM06 a small


number of 8bit registers

Program memory /4+M06 !9bit)


!:bit or !"bit 'ide /in ;P4+M)
7<A5H) or 4+M0

1on-2eumann Architecture

3sed in6 8$=8" /CI5C PCs0

+nly one bus bet'een CP3 and


memory

4AM and program memory share


the same bus and the same
memory) and so must have the
same bit 'idth

Bottleneck6 %etting instructions


interferes 'ith accessing 4AM
$I!C vs. CI!C

4educed Instruction 5et


Computer /4I5C0

3sed in6 5PA4C) A<PHA)


Atmel A14) etc&

7e' instructions
/usually > #$0

+nly a fe' addressing


modes

;.ecutes ! instruction in !
internal cloc* cycle /Tcyc0

Comple. Instruction 5et


Computer /CI5C0

3sed in6 8$=8") 8$#!)


"8HC!!) etc&

Many instructions
/usually ? !$$0

5everal addressing modes

3sually ta*es more than !


internal cloc* cycle /Tcyc0
to e.ecute
Family Core Architecture Differences

The PIC 7amily6 Cores

!9bit cores 'ith ,, instructions6 !9C#$.) !"C#.

!:bit cores 'ith ,# instructions6 !9C"-.)!"C...

!"bit cores 'ith #8 instructions6 !-C:.)!-C-..

@;nhancedA !"bit cores 'ith -- instructions6 !8C...


#he PIC Family% !ee"

Can use crystals& cloc' oscillators& or even an $C circuit.


Can use crystals& cloc' oscillators& or even an $C circuit.

!ome PICs have a (uilt in )M*+ $C cloc'& ,ot very


!ome PICs have a (uilt in )M*+ $C cloc'& ,ot very
accurate& (ut re-uires no e.ternal comonents/
accurate& (ut re-uires no e.ternal comonents/

Instruction see" 0 11) cloc' see" 2#cyc 0 ) 3 #cl'4


Instruction see" 0 11) cloc' see" 2#cyc 0 ) 3 #cl'4

All PICs can (e run from DC to their ma.imum secifie"


All PICs can (e run from DC to their ma.imum secifie"
see"%
see"%
!9C#$. :MHB
!9C"-. !$MHB
!"C... 9$MHB
!-C:. C !-C-... ,,MHB
!8C... :$MHB
Cloc' an" Instruction Cycles

Instruction Cloc'
Instruction Cloc'

Cloc* from the oscillator enters a microcontroller via +5C! pin 'here internal circuit of a
microcontroller divides the cloc* into four even cloc*s D!) D9) D,) and D: 'hich do not
overlap&

These four cloc*s ma*e up one instruction cycle /also called machine cycle0 during 'hich
one instruction is e.ecuted&

;.ecution of instruction starts by calling an instruction that is ne.t in string&

Instruction is called from program memory on every D! and is 'ritten in instruction register
on D:&

ecoding and e.ecution of instruction are done bet'een the ne.t D! and D: cycles& +n the
follo'ing diagram 'e can see the relationship bet'een instruction cycle and cloc* of the
oscillator /+5C!0 as 'ell as that of internal cloc*s D!-D:&

Program counter /PC0 holds information about the address of the ne.t instruction&
Pielinin5 in PIC

Instruction Pieline Flow


Instruction Pieline Flow
#he PIC Family% Pro5ram Memory

Technology6 ;P4+M) 7<A5H) or 4+M

It varies in siBe from one chip to another&


6 e.amles%
6 e.amles%
!C"#$ "! !bit
instructions
%C& #!' ( k ) 'bit
instructions
%F$&& $*! ( $k ) 'bit
instructions
&C&%% %+$' ( %k ) %bit
instructions
#he PIC Family% Data Memory

PICs use 5eneral urose 7File re5isters8 for $AM


PICs use 5eneral urose 7File re5isters8 for $AM
2each re5ister is 8(its for all PICs4
2each re5ister is 8(its for all PICs4
6 e.amles%
6 e.amles%
!9C#$8 9#E 4AM
!"C-!C ,"E 4AM
!"78--
,"8E 4AM F 9#"E of
nonvolatile ;;P4+M
!-C-"" G$9E 4AM
PIC Pro5rammin5 Proce"ure

7or e.ample6 in programming an embedded PIC featuring


electronically erasable programmable read-only memory
/;;P4+M0& The essential steps are6

5tep !6 +n a PC) type the program) successfully compile it and then


generate the H;= file&

5tep 96 3sing a PIC device programmer) upload the H;= file into the
PIC& This step is often called ,burning,&

5tep ,6 Insert your PIC into your circuit) po'er up and verify the
program 'or*s as e.pected& This step is often called ,dropping, the
chip& If it isnHt) you must go to 5tep ! and debug your program and
repeat burning and dropping&
PIC16F877A Features
-igh Per.ormance RISC CP/0

+nly ,# single 'ord instructions to learn

All single cycle instructions e.cept for program


branches) 'hich are t'o-cycle

+perating speed6 C - 9$ MHB cloc* input C -


9$$ ns instruction cycle
PIC16F877A Pin 9ayout
P+4TA
P+4TE
P+4T;
P+4TC P+4TC
P+4T
P+4T
AC inputs
Counter
$
e.ternal
input
PIC Memory

The PIC!"78--A has an 8!G9 /8*0 !:bit instruction


program memory

,"8 Eytes 4egisters as ata Memory 6

5pecial 7unction 4egisters6 used to control


peripherals and PIC behaviors

%eneral Purpose 4egisters6 used to a normal


temporary storage space /4AM0

9#" Eytes of nonvolatile ;;P4+M


PIC Pro5ram Memory

The PIC!"78-- 8!G9 /8*0 !:bit instructions


If interrupted) program
e.ecution continues from
here
When the
controller is reset)
program e.ecution
starts from here
Ta*es a ma. of 8 addresses) the
ninth address 'ill 'rite over the first&
PIC Data Memory
The data memory is devided into : memory ban*s
The most
important
registers
have
addresses
in all the
four
ban*s
$e5ister A""ressin5 Mo"es
Indirect Addressing0
I 7ull 8 bit register address is 'ritten the special function register 754
I I27 is used to get the content of the address pointed by 754
I ;.p 6 A sample program to clear 4AM locations HA9$A J HA976
M+1<W $.9$ KinitialiBe pointer
M+1W7 754 Kto 4AM
1234 C<47 I27 Kclear I27 register
I2C7 754)7 Kinc pointer
ET755 754): Kall done?
%+T+ 2;=T Kno clear ne.t
C514I1/2
6 Kyes continue
Immediate Addressing0
Movl' HA$7A
6irect Addressing0
3ses - bits of !: bit instruction to identify a register file address 8th and Gth
bit comes from 4P$ and 4P! bits of 5TAT35 register&
i&e& L eMu A9A K LN9
btfss 5TAT35) L K test if the ,rd bit of the 5TAT35 register is set
PIC Family Control $e5isters

3ses a series of O5pecial 7unction 4egistersP


for controlling peripherals and PIC behaviors&

S4A4/S Ean* select bits) A<3 bits /Bero) borro')


carry0

I14C51 Interrupt control6 interrupt enables) flags)


etc&

5P4I517R2G contains various control bits to


configure the TM4$ prescalerCWT
postscaler )the ;.ternal I2T Interrupt) TM4$
and the 'ea* pull-ups on P+4TE
!ecial Function $e5ister
8!#A#:! $e5ister7
!ecial Function $e5ister
8I,#CO, $e5ister 7
PIC Periherals

;ach peripheral has a set of 574s to control its


operation&

ifferent PICs have different on-board peripherals


Periheral Features

# igital IC+ Ports

Three timerCcounter modules

Timer$6 8-bit timerCcounter 'ith 8-bit pre-scaler

Timer!6 !"-bit timerCcounter 'ith pre-scaler) can be incremented during 5<;;P


via e.ternal crystalCcloc*

Timer96 8-bit timerCcounter 'ith 8-bit period register) pre-scaler and post-scaler

A !$-bit AC 'ith 8 inputs

T'o Capture) Compare) PWM modules

Capture is !"-bit) ma.& resolution is !9&# ns

Compare is !"-bit) ma.& resolution is 9$$ ns

PWM ma.& resolution is !$-bit

5ynchronous 5erial Port /55P0 'ith 5PIQ /Master mode0 and I9CQ
/MasterC5lave0

3niversal 5ynchronous Asynchronous 4eceiver Transmitter /35A4TC5CI0


'ith G-bit address detection

Parallel 5lave Port /P5P0 8-bits 'ide) 'ith e.ternal 4) W4 and C5 controls
PIC Periherals% Ports 2Di5ital I1O4

Ports are basically digital IC+ pins 'hich e.ist in all PICs

The PIC!"78--A have the follo'ing ports6

P+4T A has " bit 'ide) Eidirectional

P+4T E)C) have 8 bit 'ide) Eidirectional

P+4T ; has , bit 'ide) Eidirectional

Ports have 9 control registers

T4I5. sets 'hether each pin is an input /!0 or output /$0

P+4T. sets their output bit levels or contain their input bit levels

Pin functionality OoverloadedP 'ith other features

Most pins have 9#mA sourceCsin* thus it can drive <;s directly
PIC Periherals% Analo5ue to Di5ital
Converter

+nly available in !:bit and !"bit cores

7s /sample rate0 > #:RHB

the result is a !$ bit digital number

Can generate an interrupt 'hen AC


conversion is done
PIC Periherals% Analo5ue to Di5ital
Converter

The AC module has four registers& These registers are6

AC 4esult High 4egister /A4;5H0

AC 4esult <o' 4egister /A4;5<0

AC Control 4egister$ /AC+2$0

AC Control 4egister! /AC+2!0

Multiple.ed 8 channel inputs


Must 'ait T
acM
to charge up sampling capacitor

Can ta*e a reference voltage different from that of the controller


PIC Periherals% :!A$#% :A$#

5erial Communications Peripheral6


3niversal 5ynch&CAsynch& 4eceiverCTransmitter

Interrupt on T= buffer empty and 4= buffer full

Asynchronous communication6 3A4T /45-9,9C serial0

Can do ,$$bps - !!#*bps

8 or G bits) parity) start and stop bits) etc&

+utputs #1 so you need a 459,9 level converter /e&g&)


MA=9,90
PIC Periherals% :!A$#% :A$#

5ynchronous communication6 i&e&) 'ith cloc* signal

5PI N 5erial Peripheral Interface

, 'ire6 ata in) ata out) Cloc*

MasterC5lave /can have multiple masters0

1ery high speed /!&"Mbps0

7ull speed simultaneous send and receive /7ull duple.0

I9C N Inter IC

9 'ire6 ata and Cloc*

MasterC5lave /5ingle master onlyK multiple masters clumsy0

<ots of cheap I9C chips availableK typically > !$$*bps


PIC Periherals% #imers

Available in all PICs&

generate interrupts on timer overflo'&

5ome 8bits) some !"bits) some have prescalers


andCor postscalers

Can use e.ternal pins as cloc* inCcloc* out


/ie) for counting events or using a different 7osc0
#imer ; <loc' Dia5ram
5pecial 7unction 4egister
+PTI+2S4;% 4egister
PIC16F877A <loc' Dia5ram
Instruction
Eus
Most
important
register in
the PIC
must be
involved in
all
arithmetic
operations
ata Eus
ata
Memory
Instruction
Memory
PIC16F877A <loc' Dia5ram
4esets the
controller after
a specified
time
Reep the
controller in
reset state
until po'er
reaches an
acceptable
level T steady
Reep the
controller in
reset state until
the oscillator is
started T
stable
4esets the
controller after
detecting
Ero'n-+ut
condition
Ero'n-out6 'hen the supplying voltage
falls belo' a trip point /E1

0&
This ensures that the device does not
continue program e.ecution outside the
valid operation range of the device
Typically used in AC line or large battery
application 'here large loads maybe
s'itched in and cause the device voltage
to temporarily fall belo' the specified
operating minimum
PIC16F877A Instruction !et
9iteral an" Control Instructions
<yte6Oriente" Instructions
<it6Oriente" Instructions
PIC Alications

<; 7lasher
<oop6
bsf P+4TE) $
call elayS#$$ms
bcf P+4TE) $
call elayS#$$ms
goto <oop
PIC Alications

Eutton 4ead
Movl' $
mov'f T4I5) f
bsf T4I5) 9
<oop6
btfsc P+4T) 9
goto light
goto 2oSlight
<ight6
bsf P+4TE)$
goto <oop
2oSlight6
bcf P+4TE)$
goto <oop
$eferences an" Further
$eferences an" Further
$ea"in5s
$ea"in5s

http6CC'''&microchip&com

http6CCen&'i*ipedia&orgC'i*iCPICSmicrocontroller

!"78-. ata 5heet

Mid 4ange Manual



Than' (ou %or
Than' (ou %or
(our Attendance
(our Attendance
.
.

Você também pode gostar