Professional Documents
Culture Documents
An Introduction To The
PIC Microcontroller
EE2801-L19P01
The PIC 1
erie Microcontroller
The PIC Series of microcontrollers is representative of the current industry trend towards
highly capable, low-cost, processors for embedded applications. Although they are not
suited to everything, they can do a lot!
However, they are quite a bit different that what were used to at this point!
Only 35 instructions!
All instructions (except branch) execute in 1 cycle.
Eight level deep hardware stack.
4K word program space, 192 bytes of RAM
Internal A/D converter, serial port, digital IO ports, timers, and more!
Remember, what you are about to see will look completely different than anything youve
seen so far!
However, all of the techniques weve used and the concepts weve learned are directly
applicable!
EE2801-L19P02
The PIC 1
il C
ilitie
The following table summarizes the capabilities of the PIC16F87X series components.
Although when we use the compiler well set the processor type to 16F877, thats only
because each component in the family is compatible. The actual version well use is the
PIC16F874:
PIC1
Mid-Range Referenc e
PIC16F873
PIC16F874
PIC16F876
PIC16F877
Operating Frequency
DC - 20 MHz
DC - 20 MHz
DC - 20 MHz
DC - 20 MHz
POR, BOR
POR, BOR
POR, BOR
POR, BOR
(PWRT, OST)
(PWRT, OST)
(PWRT, OST)
(PWRT, OST)
4K
4K
8K
8K
192
192
368
368
128
128
256
256
Interrupts
13
14
13
14
I/O Ports
Ports A,B,C
Ports A,B,C,D,E
Ports A,B,C
Ports A,B,C,D,E
Timers
Capture/Compare/PWM modules
MSSP, USART
MSSP, USART
MSSP, USART
MSSP, USART
Manu al (DS33023)
Serial Communications
Parallel Communications
10-bit Analog-to-Digital Module
Instruction Set
PSP
5 input channels
8 input channels
5 input channels
8 input channels
PSP
35 Instructions
35 Instructions
35 Instructions
35 Instructions
EE2801-L19P0
RA0/AN0
RA1/AN1
RA2/AN2/VREFRA3/AN3/VREF+
RA4/T0CKI
RA5/AN4/SS
Instruction reg
Direct Addr
PORTA
RAM
File
Registers
8 Level Stack
(13-bit)
14
Data Bus
Program Counter
PORTB
Indirect
Addr
FSR reg
STATUS reg
Instruction
Decode &
Control
OSC1/CLKIN
OSC2/CLKOUT
Timing
Generation
Power-up
Timer
Oscillator
Start-up Timer
Power-on
Reset
Watchdog
Timer
Brown-out
Reset
In-Circuit
Debugger
Low-Voltage
Programming
PORTC
MUX
ALU
PORTD
RB0/INT
RB1
RB2
RB3/PGM
RB4
RB5
RB6/PGC
RB7/PGD
RC0/T1OSO/T1CKI
RC1/T1OSI/CCP2
RC2/CCP1
RC3/SCK/SCL
RC4/SDI/SDA
RC5/SDO
RC6/TX/CK
RC7/RX/DT
W reg
RD7/PSP7:RD0/PSP0
PORTE
RE0/AN5/RD
RE1/AN6/WR
RE2/AN7/CS
Timer0
Data EEPROM
Timer1
CCP1,2
Timer2
Synchronous
Serial Port
10-bit A/D
Device
Program
FLASH
Data Memory
Data
EEPROM
PIC16F874
PIC16F877
4K
8K
192 Bytes
368 Bytes
128 Bytes
256 Bytes
USART
EE2801-L19P0
PC<12:0>
CALL, RETURN
RETFIE, RETLW
13
Stack Level 1
Stack Level 2
Stack Level 8
Reset Vector
Interrupt Vector
On-Chip
0000h
0004h
0005h
Page 0
07FFh
0800h
Program
Memory
Page 1
0FFFh
1000h
1FFFh
EE2801-L19P0
FFh
A0h
General
Purpose
Register
Bank 1
96 Bytes
7Fh
96 Bytes
Bank 0
File
Address
Indirect addr. (*) 180h
OPTION_REG 181h
PCL
182h
STATUS
183h
FSR
184h
185h
TRISB
186h
187h
188h
189h
18Ah
18Bh
18Ch
18Dh
18Eh
18Fh
190h
PCLATH
INTCON
EECON1
EECON2
Reserved(2)
Reserved(2)
accesses
A0h - FFh
Bank 3
1FFh
1EFh
1F0h
1A0h
17Fh
16Fh
170h
120h
accesses
20h-7Fh
Bank 2
EE2801-L19P06
e i ter
A ddr es
s
Name
Bi t 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
POR,
BOR
Value on
all ot her
resets
(2)
Ba nk 0
(4)
00h
INDF
Addressing this location uses contents of FSR to address data mem ory (not a physical register)
01h
TMR0
PCL
(4)
02h
(4)
03h
(4)
STATUS
IRP
RP1
RP0
TO
PD
04h
FSR
05h
PORTA
06h
PORTB
07h
PORTC
PORTD
(5)
08h
(5)
09h
0Ah
0Bh
(1,4)
(4)
0Dh
PIR2
GIE
(3)
PSPIF
E2
RE0
PEIE
T0IE
INTE
RBIE
T0IF
INTF
RBIF
RCIF
TXIF
SSPIF
CCP1IF
TMR2IF
TMR1IF
EEIF
BCLIF
0Eh
TMR1L
Holding register for the Least Significant Byte of the 16-bit TMR1 register
0Fh
TMR1H
Holding register for the Most Significant Byte of the 16-bit TMR1 register
10h
T1CON
11 h
TMR2
12h
T2CON
13h
SSPBUF
RE1
ADIF
(6)
CCP2IF
T1CKPS1
T1CKPS0
T1OSCEN
T1SYNC
TMR1CS
TMR1ON
TOUTPS2
TOUTPS1
TOUTPS0
TMR2ON
T2CKPS1
T2CKPS0
SSPM2
SSPM1
SSPM 0
TOUTPS3
14h
SSPCO N
15h
CCPR1L
WCO L
16h
CCPR1H
17h
CCP1CON
18h
RCSTA
19h
TXREG
SPEN
SSPOV
RX9
SSPEN
CKP
SSPM 3
CCP1X
CCP1Y
CCP1 M3
CCP1 M2
CCP1 M1
CCP1M0
SREN
CREN
ADDEN
FERR
OERR
RX9D
CCP2 M3
CCP2 M2
CCP2 M1
CCP2M0
1Ah
RCREG
1Bh
CCPR2L
1Ch
CCPR2H
1Dh
CCP2CON
1Eh
ADRESH
1Fh
ADCON0
CCP2X
CCP2Y
GO/
ADCS1
ADCS0
CHS2
CHS1
CHS0
DONE
PIR1
PCLATH
INTCON
PORTE
0Ch
DON
xxxx
0000
xxxx
xxxx
xxxx
uuuu
--0u
uuuu
uuuu
uuuu
uuuu
0000
uuuu
uuuu
uuuu
0000
0--0
xxxx
xxxx
0000
0000
0000
xxxx
0000
xxxx
xxxx
0000
000x
0000
0000
xxxx
xxxx
0000
xxxx
0000
-r-0
uuuu
uuuu
--uu
0000
-000
uuuu
0000
uuuu
uuuu
--00
0000
0000
0000
uuuu
uuuu
--00
uuuu
0000
0--0
uuuu
uuuu
uuuu
0000
0000
uuuu
0000
uuuu
uuuu
0000
000x
0000
0000
uuuu
uuuu
0000
uuuu
EE2801-L19P0
R/W-0
R/W-0
R-1
R-1
R/W-x
R/W-x
IRP
RP1
RP0
TO
PD
DC
bit7
R/W-x
C
bit0
R = Readable bit
W = Writable bit
U = Unimplemented bit,
read as 0
bit 7:
IRP:
Register Bank Select bit (used for indirect addressing)
bit 6-5:
bit 4:
bit 3:
bit 2:
Z: Zero bit
bit 1:
bit 0:
1 = A carry-out from the 4th low order bit of the result occurred
0 = No carry-out from the 4th low order bit of the result
C: Carry/borrow bit ( ADDWF, ADDLW,SUBLW,SUBWF instructions)
1 = A carry-out from the most significant bit of the result occurred
0 = No carry-out from the most significant bit of the result occurred
Note:
For borrow the polarity is reversed. A subtraction is executed by adding the twos complement of
RRF, RLF) instructions, this bit is loaded with either the high or low order
EE2801-L19P08
An E
le PIC- ed
te
EE2801-L19P09