Professional Documents
Culture Documents
An Introduction To The PIC Microcontroller PDF
An Introduction To The PIC Microcontroller PDF
An Introduction To The
PIC Microcontroller
EE2801-L19P01
The PIC 1 8 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
However, they are quite a bit different that what were used to at this point!
Only 35 instructions!
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 8 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 8
Resets (and Delays) POR, BOR POR, BOR POR, BOR POR, BOR
(PWRT, OST) (PWRT, OST) (PWRT, OST) (PWRT, OST)
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 3 3 3 3
Capture/Compare/PWM modules 2 2 2 2
Serial Communications MSSP, USART MSSP, USART MSSP, USART MSSP, USART
10-bit Analog-to-Digital Module 5 input channels 8 input channels 5 input channels 8 input channels
EE2801-L19P0
The PIC1 8 Architecture
13 Data Bus 8 PORTA
FLASH Program Counter
RA0/AN0
Program RA1/AN1
Memory RAM RA2/AN2/VREF-
8 Level Stack File RA3/AN3/VREF+
(13-bit) Registers RA4/T0CKI
RA5/AN4/SS
Program 14
Bus RAM Addr (1) 9 PORTB
RB0/INT
Instruction reg Addr MUX RB1
RB2
Direct Addr 7 Indirect RB3/PGM
8 Addr RB4
FSR reg RB5
RB6/PGC
STATUS reg RB7/PGD
8 PORTC
RC0/T1OSO/T1CKI
RC1/T1OSI/CCP2
3 MUX RC2/CCP1
Power-up RC3/SCK/SCL
Timer RC4/SDI/SDA
Instruction Oscillator RC5/SDO
Decode & Start-up Timer ALU RC6/TX/CK
Control Power-on RC7/RX/DT
Reset 8 PORTD
Timing Watchdog W reg
Generation Timer
OSC1/CLKIN Brown-out
OSC2/CLKOUT Reset RD7/PSP7:RD0/PSP0
In-Circuit
Debugger
Low-Voltage
Programming Parallel Slave Port PORTE
RE0/AN5/RD
RE1/AN6/WR
MCLR VDD, VSS RE2/AN7/CS
Instead of having a large memory space outside the processor and a small memory space
inside the processor (the registers) like we do in the 80x86, the PIC does two things. First,
it divides memory into two main spaces: program memory and data memory. For program
memory, the map looks as follows:
PC<12:0>
CALL, RETURN 13
RETFIE, RETLW
Stack Level 1
Stack Level 2
Stack Level 8
Program
07FFh this memory map is used in
Memory 0800h other family processors.
Page 1
0FFFh
1000h
1FFFh
EE2801-L19P0
EE2801-L19P06
File
Address
Indirect addr. (*) 00h Indirect addr.(*) 80h Indirect addr. (*) 100h Indirect addr. (*) 180h
TMR0 01h OPTION_REG 81h TMR0 101h OPTION_REG 181h
PCL 02h PCL 82h PCL 102h PCL 182h
STATUS 03h STATUS 83h STATUS 103h STATUS 183h
FSR 04h FSR 84h FSR 104h FSR 184h
PORTA 05h TRISA 85h 105h 185h
The PIC16F874 Register File Map
Value on
Value on:
A ddr es all ot her
Name Bi t 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 POR,
s resets
BOR
(2)
Ba nk 0
00h
(4)
INDF Addressing this location uses contents of FSR to address data mem ory (not a physical register) 0000 0000 0000 0000
01h TMR0 Timer0 modules register xxxx xxxx uuuu uuuu
02h
(4)
PCL Program Counter's (PC) Least Significant Byte 0000 0000 0000 0000
03h
(4) STATUS IRP RP1 RP0 TO PD Z D C C 0001 1xxx 000q quuu
04h
(4) FSR Indirect data memory address pointer xxxx xxxx uuuu uuuu
05h PORTA PORTA Data Latch when written: PORTA pins when read --0x 0000 --0u 0000
06h PORTB PORTB Data Latch when written: PORTB pins when read xxxx xxxx uuuu uuuu
07h PORTC PORTC Data Latch when written: PORTC pins when read xxxx xxxx uuuu uuuu
08h
(5)
PORTD PORTD Data Latch when written: PORTD pins when read xxxx xxxx uuuu uuuu
09h
(5)
PORTE R E2 RE1 RE0 ---- -xxx ---- -uuu
0Ah
(1,4)
PCLATH Write Buffer for the upper 5 bits of the Program Counter ---0 0000 ---0 0000
0Bh
(4) INTCON GIE PEIE T0IE INTE RBIE T0IF INTF RBIF 0000 000x 0000 000u
0Ch PIR1 PSPIF
(3) ADIF RCIF TXIF SSPIF CCP1IF TMR2IF TMR1IF 0000 0000 0000 0000
0Dh PIR2 (6) EEIF BCLIF CCP2IF -r-0 0--0 -r-0 0--0
0Eh TMR1L Holding register for the Least Significant Byte of the 16-bit TMR1 register xxxx xxxx uuuu uuuu
0Fh TMR1H Holding register for the Most Significant Byte of the 16-bit TMR1 register xxxx xxxx uuuu uuuu
10h T1CON T1CKPS1 T1CKPS0 T1OSCEN T1SYNC TMR1CS TMR1ON --00 0000 --uu uuuu
11 h TMR2 Timer2 modules register 0000 0000 0000 0000
12h T2CON TOUTPS3 TOUTPS2 TOUTPS1 TOUTPS0 TMR2ON T2CKPS1 T2CKPS0 -000 0000 -000 0000
13h SSPBUF Synchronous Serial Por t Receive Buffer/Transmit Register xxxx xxxx uuuu uuuu
14h SSPCO N WCO L SSPOV SSPEN CKP SSPM 3 SSPM2 SSPM1 SSPM 0 0000 0000 0000 0000
15h CCPR1L Capture/Compare/PWM Register1 (LSB) xxxx xxxx uuuu uuuu
16h CCPR1H Capture/Compare/PWM Register1 (MSB) xxxx xxxx uuuu uuuu
17h CCP1CON CCP1X CCP1Y CCP1 M3 CCP1 M2 CCP1 M1 CCP1M0 --00 0000 --00 0000
18h RCSTA SPEN RX9 SREN CREN ADDEN FERR OERR RX9D 0000 000x 0000 000x
19h TXREG USART Transmit Data Register 0000 0000 0000 0000
1Ah RCREG USART Receive Data Register 0000 0000 0000 0000
1Bh CCPR2L Capture/Compare/PWM Register2 (LSB) xxxx xxxx uuuu uuuu
1Ch CCPR2H Capture/Compare/PWM Register2 (MSB) xxxx xxxx uuuu uuuu
1Dh CCP2CON CCP2X CCP2Y CCP2 M3 CCP2 M2 CCP2 M1 CCP2M0 --00 0000 --00 0000
1Eh ADRESH A/D Result Register High Byte xxxx xxxx uuuu uuuu
1Fh ADCON0 ADCS1 ADCS0 CHS2 CHS1 CHS0
GO/
DONE
A DON 0000 00-0 0000 00-0
EE2801-L19P0
o To e l ith All The e e i ter
bit 7: IRP:
Register Bank Select bit (used for indirect addressing)
1 = Bank 2, 3 (100h - 1FFh)
0 = Bank 0, 1 (00h - FFh)
bit 6-5: RP1:RP0: Register Bank Select bits (used for direct addressing)
11 = Bank 3 (180h - 1FFh)
10 = Bank 2 (100h - 17Fh)
01 = Bank 1 (80h - FFh)
00 = Bank 0 (00h - 7Fh)
Each bank is 128 bytes
EE2801-L19P08
An E le PIC- ed te
EE2801-L19P09