Académique Documents
Professionnel Documents
Culture Documents
PIC16F87X Finale
PIC16F87X Finale
SOMMAIRE
1) INTRODUCTION........................................................................................................................................... 4
2) CARACTRISTIQUES DES MICROCONTROLEURS................................................................................ 5
2) ORGANISATIONS INTERNES..................................................................................................................... 6
2.1) LES CS 16F873 ET 16F876. ................................................................................................................. 6
2.2) LES CS 16F874 ET 16F877. ................................................................................................................. 7
3) DESCRIPTION DES DIFFERENTES BROCHES ........................................................................................ 8
3.1) LES CS 16F873 ET 16F876. ................................................................................................................. 8
3.2) LES CS 16F874 ET 16F877. ................................................................................................................. 9
4) BROCHAGES PHYSIQUES DES DIFFERENTES VERSIONS DE CS. ................................................. 10
5) LES BROCHES DU C............................................................................................................................... 11
5.1) MCLR.................................................................................................................................................... 11
5.2) OSCILLATEUR : OSC1 ET OSC2 OU CLKIN ET CLOUT....................................................................... 12
5.3) ALIMENTATION : VDD ET VSS. ............................................................................................................. 13
5.4) LINTERRUPTION : RBO/INT. ................................................................................................................ 13
6) L'UNIT CENTRALE. ................................................................................................................................. 14
6.1) ORGANISATION MEMOIRE. ................................................................................................................... 14
6.1.1) Plan Mmoire pour les instructions (code programme). ............................................................................... 14
6.1.2) Plan Mmoire pour les donnes et registres internes (SFR : Special Function Register). ............................ 15
6.1.2) LUAL : Lunit Arithmtique et Logique. ..................................................................................................... 17
7) JEU D'INSTRUCTIONS. ............................................................................................................................. 18
8) LES MODES DADRESSAGES ................................................................................................................. 19
8.1) ADRESSAGE INHERENT OU IMPLICITE ................................................................................................. 19
8.2) ADRESSAGE IMMEDIAT......................................................................................................................... 19
8.3) ADRESSAGES DIRECT ET ETENDU. ...................................................................................................... 19
8.4) ADRESSAGE RELATIF. .......................................................................................................................... 20
8.5) ADRESSAGE INDIRECT OU ENCORE INDEXE........................................................................................ 20
8.6) MANIPULATION DE BITS........................................................................................................................ 21
8.6.1) Forage de bits............................................................................................................................................... 21
8.6.2) Test de bits...................................................................................................................................................... 21
9) LES PORTS D'ENTREES SORTIES.......................................................................................................... 22
9.1) GENERALITES. ...................................................................................................................................... 22
9.2 CONFIGURATION DES PORTX , LES REGISTRES PORTX ET TRISX..................................................... 23
9.3) LE PORT A............................................................................................................................................ 24
9.3) LE PORT B............................................................................................................................................ 25
9.4) LE PORT C. .......................................................................................................................................... 26
9.5) LES PORT D ET E................................................................................................................................. 27
10) LE CONVERTISSEUR ANALOGIQUE NUMERIQUE. ............................................................................ 28
10.1) ORGANISATION INTERNE.................................................................................................................... 28
10.2) FONCTIONNEMENT DU CONVERTISSEUR. ......................................................................................... 29
10.3) LE REGISTRE ADCON1. ..................................................................................................................... 30
10.4) LE REGISTRE ADCON0. ..................................................................................................................... 31
10.5) EXEMPLE DUTILISATION. ................................................................................................................... 32
page 1
page 2
page 3
1) INTRODUCTION.
Ces microcontrleurs mritent bien une introduction. En effet, ils ont t conus sur une architecture
dite HARVARD (RISC) et non sur un modle VON NEUMANN (COMPLEX).
Larchitecture HARVARD utilise par les microcontrleurs PICS est base sur deux bus de
donnes. Un bus est utilis pour les donnes et un autre pour les instructions.
Avantages et inconvnients.
Architecture VON NEUMANN
(MOTOROLA, INTEL, ZILOG, ..)
- Jeu dinstructions riches.
- Accs la mmoire facile.
Avantages
Inconvnients
Remarque : La taille mmoire spcifie pour un PICs sexprime en Kilo Mots (14 bits pour la famille
16F87X) et non en kilo octets. Comme chaque instruction est code par un mot de 14 bits, compares aux
microcontrleurs classiques (1,2 ou 3 octets par instruction), les PICs ont un code plus compact et ils
utilisent moins de mmoire.
page 4
PIC16F873
PIC16F874
PIC16F876
PIC16F877
Operating Frequency
DC - 20 MHz
DC - 20 MHz
DC - 20 MHz
DC - 20 MHz
POR, BOR
(PWRT, OST)
POR, BOR
(PWRT, OST)
POR, BOR
(PWRT, OST)
POR, BOR
(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
3
Timers
Capture/Compare/PWM Modules
Serial Communications
MSSP, USART
MSSP, USART
MSSP, USART
MSSP, USART
Parallel Communications
PSP
PSP
5 input channels
8 input channels
5 input channels
8 input channels
Instruction Set
35 instructions
35 instructions
35 instructions
35 instructions
Caractristiques communes :
Programmable sur site ICSP (In Circuit Serial Programming).
Dbuggable sur site ICD.
Frquence de fonctionnement leve, jusqu 20 Mhz.
Une mmoire vive de 192 368 octets.
Une mmoire EEPROM pour sauver des paramtres de 128 256 octets.
Une mmoire morte de type FLASH de 4 Kmots 8 Kmots (1mot = 14 bits).
Chien de garde WDT.
Surveillance d'horloge OST.
Surveillance de tension dalimentation BOR.
De 21 32 Entres et sorties suivant le type de micro contrleur.
Chaque sortie peut sortir un courant maximum de 25mA.
3 Temporisateurs : TIMER0 (8 bits avec pr diviseur), TIMER1 (16 bits avec pr diviseur avec
possibilit dutiliser une horloge externe rseau RC ou QUARTZ) et TIMER2 (8 bits avec pr
diviseur et post diviseur)
2 entres de captures et de comparaison avec PWM (Modulation de largeur dimpulsions).
Convertisseur analogique numrique 10 bits avec de 5 8 entres multiplexes maximum.
Une interface de communication srie asynchrone et synchrone. (USART/SCI).
Une interface de communication srie synchrone. (SSP/SPI et I2C).
Plusieurs modes de fonctionnements faible consommation.
Une seule tension d'alimentation 2 ou 5V.
Conservation des informations en mmoire vive jusqu' 1.5V.
Faible consommation :
<2mA 5V pour Fquartz=4Mhz.
20A 3V pour Fquartz 32Khz.
<1A pour en mode sommeil.
page 5
Program
FLASH
Data Memory
Data
EEPROM
PIC16F873
4K
192 Bytes
128 Bytes
PIC16F876
8K
368 Bytes
256 Bytes
13
FLASH
Program
Memory
Program
Bus
PORTA
RA0/AN0
RA1/AN1
RA2/AN2/VREFRA3/AN3/VREF+
RA4/T0CKI
RA5/AN4/SS
RAM
File
Registers
8 Level Stack
(13-bit)
14
Data Bus
Program Counter
RAM Addr(1)
PORTB
RB0/INT
RB1
RB2
RB3/PGM
RB4
RB5
RB6/PGC
RB7/PGD
Addr MUX
Instruction reg
Direct Addr
Indirect
Addr
FSR reg
STATUS reg
8
PORTC
3
Power-up
Timer
Instruction
Decode &
Control
Timing
Generation
OSC1/CLKIN
OSC2/CLKOUT
Oscillator
Start-up Timer
Power-on
Reset
MUX
ALU
8
Watchdog
Timer
Brown-out
Reset
In-Circuit
Debugger
RC0/T1OSO/T1CKI
RC1/T1OSI/CCP2
RC2/CCP1
RC3/SCK/SCL
RC4/SDI/SDA
RC5/SDO
RC6/TX/CK
RC7/RX/DT
W reg
Low Voltage
Programming
MCLR
VDD, VSS
Timer0
Timer1
Timer2
10-bit A/D
Data EEPROM
CCP1,2
Synchronous
Serial Port
USART
page 6
Progr am
FLASH
Data Memo ry
Data
EEPROM
PIC16F874
4K
192 Bytes
128 Bytes
PIC16F877
8K
368 Bytes
256 Bytes
13
Program
Memory
14
PORTA
RA0/AN0
RA1/AN1
RA2/AN2/VREFRA3/AN3/VREF+
RA4/T0CKI
RA5/AN4/SS
RAM
File
Registers
8 Level Stack
(13-bit)
Program
Bus
Data Bus
Program Counter
FLASH
RAM Addr(1)
PORTB
RB0/INT
RB1
RB2
RB3/PGM
RB4
RB5
RB6/PGC
RB7/PGD
Addr MUX
Instruction reg
Direct Addr
Indirect
Addr
FSR reg
STATUS reg
PORTC
3
Power-up
Timer
Instruction
Decode &
Control
Oscillator
Start-up Timer
Timing
Generation
Watchdog
Timer
Brown-out
Reset
OSC1/CLKIN
OSC2/CLKOUT
Power-on
Reset
RC0/T1OSO/T1CKI
RC1/T1OSI/CCP2
RC2/CCP1
RC3/SCK/SCL
RC4/SDI/SDA
RC5/SDO
RC6/TX/CK
RC7/RX/DT
MUX
ALU
8
W reg
PORTD
RD0/PSP0
RD1/PSP1
RD2/PSP2
RD3/PSP3
RD4/PSP4
RD5/PSP5
RD6/PSP6
RD7/PSP7
In-Circuit
Debugger
Low-Voltage
Programming
PORTE
MCLR
RE0/AN5/RD
VDD, VSS
RE1/AN6/WR
RE2/AN7/CS
Timer0
Timer1
Timer2
10-bit A/D
Data EEPROM
CCP1,2
Synchronous
Serial Port
USART
Remarque : Les 16F873 et 16F874 prsentent peu dintrt par rapport aux
16F876 et 16F877, en effet ils possdent moins de mmoires programmes et
ils sont peu prs au mme prix.
page 7
SOIC
Pin#
I/O/P
Type
OSC1/CLKIN
OSC2/CLKOUT
10
10
MCLR/VPP
I/P
ST
RA0/AN0
I/O
TTL
RA1/AN1
I/O
TTL
RA2/AN2/VREF-
I/O
TTL
RA3/AN3/VREF+
I/O
TTL
RA4/T0CKI
I/O
ST
RA5/SS/AN4
I/O
TTL
Pin Name
Buff er
Type
Descri ption
21
21
I/O
TTL/ST(1)
RB1
22
22
I/O
TTL
RB2
23
23
I/O
TTL
RB3/PGM
24
24
I/O
TTL
RB4
25
25
I/O
TTL
Interrupt-on-change pin.
Interrupt-on-change pin.
RB5
26
26
I/O
TTL
RB6/PGC
27
27
I/O
TTL/ST(2)
RB7/PGD
28
28
I/O
TTL/ST(2)
RC0/T1OSO/T1CKI
11
11
I/O
ST
RC1/T1OSI/CCP2
12
12
I/O
ST
RC2/CCP1
13
13
I/O
ST
RC3/SCK/SCL
14
14
I/O
ST
RC4/SDI/SDA
15
15
I/O
ST
RC5/SDO
16
16
I/O
ST
RC6/TX/CK
17
17
I/O
ST
RC7/RX/DT
18
18
I/O
ST
VSS
8, 19
8, 19
VDD
20
20
Legend: I = input
O = output
= Not used
I/O = input/output
TTL = TTL input
P = power
ST = Schmitt Trigger input
Note 1: This buffer is a Schmitt Trigger input when configured as the external interrupt.
2: This buffer is a Schmitt Trigger input when used in Serial Programming mode.
3: This buffer is a Schmitt Trigger input when configured in RC oscillator mode and a CMOS input otherwise.
page 8
DIP
Pin#
PLCC
Pin#
QFP
Pin#
I/O/P
Type
Bu ffer
Type
Descri pti on
(4)
OSC1/CLKIN
13
14
30
OSC2/CLKOUT
14
15
31
ST/CMOS
MCLR/VPP
18
I/P
ST
RA0/AN0
19
I/O
TTL
RA1/AN1
20
I/O
TTL
RA2/AN2/VREF-
21
I/O
TTL
RA3/AN3/VREF+
22
I/O
TTL
RA4/T0CKI
23
I/O
ST
RA5/SS/AN4
24
I/O
TTL
PORTB is a bi-directional I/O port. PORTB can be software programmed for internal weak pull-up on all inputs.
RB0/INT
33
36
I/O
TTL/ST(1)
RB1
34
37
I/O
TTL
RB2
35
38
10
I/O
TTL
RB3/PGM
36
39
11
I/O
TTL
RB4
37
41
14
I/O
TTL
Interrupt-on-change pin.
RB5
38
42
15
I/O
TTL
RB6/PGC
39
43
16
I/O
TTL/ST(2)
RB7/PGD
40
44
17
I/O
TTL/ST(2)
RC0/T1OSO/T1CKI
15
16
32
I/O
ST
RC1/T1OSI/CCP2
16
18
35
I/O
ST
RC2/CCP1
17
19
36
I/O
ST
RC3/SCK/SCL
18
20
37
I/O
ST
RC4/SDI/SDA
23
25
42
I/O
ST
RC5/SDO
24
26
43
I/O
ST
RC6/TX/CK
25
27
44
I/O
ST
RC7/RX/DT
26
29
I/O
ST
Interrupt-on-change pin.
19
21
38
I/O
ST/TTL(3)
RD1/PSP1
20
22
39
I/O
ST/TTL(3)
RD2/PSP2
21
23
40
I/O
ST/TTL(3)
RD3/PSP3
22
24
41
I/O
ST/TTL(3)
RD4/PSP4
27
30
I/O
ST/TTL(3)
RD5/PSP5
28
31
I/O
ST/TTL(3)
RD6/PSP6
29
32
I/O
ST/TTL(3)
RD7/PSP7
30
33
I/O
ST/TTL(3)
RE0/RD/AN5
25
I/O
ST/TTL(3)
RE1/WR/AN6
10
26
I/O
ST/TTL(3)
RE2/CS/AN7
10
11
27
I/O
ST/TTL(3)
VSS
12,31
13,34
6,29
VDD
11,32
12,35
7,28
NC
1,17,28,
40
12,13,
33,34
page 9
RA3/AN3/VREF+
RA2/AN2/VREFRA1/AN1
RA0/AN0
MCLR/VPP
NC
RB7/PGD
RB6/PGC
RB5
RB4
NC
40
39
RB7/PGD
RB6/PGC
RA1/AN1
RA2/AN2/VREF-
38
RB5
37
RA3/AN3/VREF+
36
35
RB4
RB3/PGM
RA4/T0CKI
5
6
34
RB1
33
RB0/INT
32
31
VDD
30
29
28
RD7/PSP7
RD6/PSP6
RD5/PSP5
27
RD4/PSP4
26
RC7/RX/DT
RA5/AN4/SS
RE0/RD/AN5
RE1/WR/AN6
9
10
RE2/CS/AN7
VDD
VSS
OSC1/CLKIN
11
12
13
PIC16F877/874
1
2
RB2
VSS
OSC2/CLKOUT
14
RC0/T1OSO/T1CKI
15
RC1/T1OSI/CCP2
16
25
RC6/TX/CK
RC2/CCP1
17
24
RC5/SDO
RC3/SCK/SCL
RD0/PSP0
18
23
19
20
22
21
RC4/SDI/SDA
RD3/PSP3
RD1/PSP1
RD2/PSP2
18
19
20
21
22
23
24
25
26
27
28
44
43
42
41
40
39
38
37
36
35
34
QFP
MCLR/VPP
RA0/AN0
PIC16F877
PIC16F874
RB3/PGM
RB2
RB1
RB0/INT
VDD
VSS
RD7/PSP7
RD6/PSP6
RD5/PSP5
RD4/PSP4
RC7/RX/DT
RC1/T1OSI/CCP2
RC2/CCP1
RC3/SCK/SCL
RD0/PSP0
RD1/PSP1
RD2/PSP2
RD3/PSP3
RC4/SDI/SDA
RC5/SDO
RC6/TX/CK
NC
RB7/PGD
RB6/PGC
RB5
RB4
RB3/PGM
RB2
RB1
RB0/INT
VDD
VSS
RC7/RX/DT
RC6/TX/CK
RC5/SDO
RC4/SDI/SDA
39
38
37
36
35
34
33
32
31
30
29
RC6/TX/CK
RC5/SDO
RC4/SDI/SDA
RD3/PSP3
RD2/PSP2
RD1/PSP1
RD0/PSP0
RC3/SCK/SCL
RC2/CCP1
RC1/T1OSI/CCP2
NC
28
27
26
25
24
23
22
21
20
19
18
17
16
15
7
8
9
10
11
12
13
14
15
16
17
RC7/RX/DT
RD4/PSP4
RD5/PSP5
RD6/PSP6
RD7/PSP7
VSS
VDD
RB0/INT
RB1
RB2
RB3/PGM
1
2
3
4
5
6
7
8
9
10
11
PIC16F877
PIC16F874
33
32
31
30
29
28
27
26
25
24
23
12
13
14
15
16
17
18
19
20
21
22
1
2
3
4
5
6
7
8
9
10
11
12
13
14
PIC16F876/873
MCLR/VPP
RA0/AN0
RA1/AN1
RA2/AN2/VREFRA3/AN3/VREF+
RA4/T0CKI
RA5/AN4/SS
VSS
OSC1/CLKIN
OSC2/CLKOUT
RC0/T1OSO/T1CKI
RC1/T1OSI/CCP2
RC2/CCP1
RC3/SCK/SCL
RA4/T0CKI
RA5/AN4/SS
RE0/RD/AN5
RE1/WR/AN6
RE2/CS/AN7
VDD
VSS
OSC1/CLKIN
OSC2/CLKOUT
C0/T1OSO/T1CK1
NC
NC
RC0/T1OSO/T1CKI
OSC2/CLKOUT
OSC1/CLKIN
VSS
VDD
RE2/AN7/CS
RE1/AN6/WR
RE0/AN5/RD
RA5/AN4/SS
RA4/T0CKI
NC
NC
RB4
RB5
RB6/PGC
RB7/PGD
MCLR/VPP
RA0/AN0
RA1/AN1
A2/AN2/VREFRA3/AN3/VREF+
PDIP, SOIC
6
5
4
3
2
1
44
43
42
41
40
PLCC
page 10
5) LES BROCHES DU C.
5.1) MCLR.
Cette broche sert initialiser le C .
Le C dispose de plusieurs sources de RESET :
POR.
EXTERNAL RESET.
WDT.
BOR.
POR: (POWER ON RESET) Mise sous tension.
Un front montant sur MCLR dclenche l'initialisation du C. Le temps ncessaire est au
minimum de 72mS et au maximum de 72mS+1024*Tosc. Le C dispose en interne dun
circuit de dtection de niveau, quand la tension VDD est comprise entre 1.2V et 1.7V, il
dmarre une procdure dinitialisation.
Cette broche peut tre simplement relie VDD si on na pas besoin de RESET externe.
Par contre si on souhaite implanter un bouton de remise zro, on pourra cbler un simple
rseau RC sur la broche MCLR.
Remarque importante : On peut se passer de circuit RC la seule condition que le temps
de mont de VDD soit suffisamment rapide (au minimum 50mV/mS). Si le temps de monte
est infrieur 50mV/ms, il faut rajouter un rseau RC.
EXTERNAL RESET (Mise ltat bas de MCLR). Remise zro extrieure. Il faut
appliquer un niveau bas sur l'entre RESET pendant au moins 2S pour que l'Initialisation
soit prise en compte.
WDT
SLEEP
Time-out
Reset
VDD Rise
Detect
Power-on Reset
VDD
Brown-out
Reset
BODEN
OST/PWRT
OST
10-bit Ripple Counter
Chip_Reset
R
OSC1
(1)
On-chip
RC OSC
PWRT
10-bit Ripple Counter
Enable PWRT
Enable OST
page 11
C1(1)
TABLE 12-1:
OSC1
XTAL
C2(1)
Ranges Teste d:
To
Internal
Logic
RF(3)
OSC2
Mode
Freq .
OSC1
OSC2
XT
455 kHz
2.0 MHz
4.0 MHz
68 - 100 pF
15 - 68 pF
15 - 68 pF
68 - 100 pF
15 - 68 pF
15 - 68 pF
HS
8.0 MHz
16.0 MHz
10 - 68 pF
10 - 22 pF
10 - 68 pF
10 - 22 pF
SLEEP
Rs (2)
PIC16F87X
Note 1: See Table 12-1 and Table 12-2 for recommended values of C1 and C2.
2: A series resistor (Rs ) may be required for AT
strip cut crystals.
CERAMIC RESONATORS
TABLE 12-2:
Osc Type
LP
XT
HS
Cry stal
Freq .
Cap. Range
C1
Cap. Range
C2
33 pF
32 kHz
33 pF
200 kHz
15 pF
15 pF
200 kHz
47-68 pF
47-68 pF
1 MHz
15 pF
15 pF
4 MHz
15 pF
15 pF
4 MHz
15 pF
15 pF
8 MHz
15-33 pF
15-33 pF
20 MHz
15-33 pF
15-33 pF
Un rseau RC.
Un oscillateur externe.
VDD
OSC1
Clock from
Ext. System
REXT
PIC16F87X
Open
OSC2
Internal
Clock
OSC1
CEXT
PIC16F87X
VSS
FOSC/4
Recommended values:
OSC2/CLKOUT
3k
REXT
100 k
Remarque : Les instructions standards durent 1 cycle machine (sauf les instructions de sauts 2
cycles). Le C utilise 4 coups dhorloge pour raliser un cycle machine.
Si la frquence du QUARTZ est de 20MHz( T=50nS) , une instruction sera excute toutes les
200nS, Dans ce cas l, le C a une puissance de calcul de 5MIPS (5 Millions dinstructions par
secondes ! ! !).
La frquence MAX est de 20MHz pour les C dont les rfrences se terminent par -20.
Par exemples : 16F876-20 (20MHz max) et 16F876-04 (4MHz max).
La frquence MIN est le continu.
Remarque : La consommation du circuit sera d'autant plus faible que la frquence sera petite, cela
peut tre intressant pour des applications de faible consommation (alimentation autonome).
Pour des applications faible consommation, on peut utiliser les sries LF (Low Frequency and Low
Power).
page 12
page 13
CALL, RETURN
RETFIE, RETLW
13
Stack Level 1
Stack Level 2
Stack Level 8
RESET Vector
0000h
Interrupt Vector
0004h
0005h
Page 0
07FFh
0800h
On-Chip
Program
Memory
Page 1
0FFFh
1000h
Page 2
17FFh
Page 3
1800h
1FFFh
Le plan mmoire est linaire les adresses vont de 0000h 1FFFh (8k mots de 14 bits), par page de
2K mots . On peut remarquer, le vecteur de reset est fig en 0000h.
Les PICs nont quun seul vecteur dinterruption en 0004h. Lors dune interruption, le sous
programme associ devra dterminer quel priphrique a demand une interruption.
La pile utilise par les sous programmes nest pas implante en mmoire de donne comme avec
les microcontrleurs classiques, mais dans la mmoire programme. Elles sont utilises lors dappels de
sous programmes, on ne peut pas imbriquer plus de 8 sous programmes (Ce qui est dj beaucoup ! !).
page 14
00h
01h
02h
03h
04h
05h
06h
07h
08h
09h
0Ah
0Bh
0Ch
0Dh
0Eh
0Fh
10h
11h
12h
13h
14h
15h
16h
17h
18h
19h
1Ah
1Bh
1Ch
1Dh
1Eh
1Fh
20h
96 Bytes
Bank 0
File
Address
Indirect addr.(*)
OPTION_REG
PCL
STATUS
FSR
TRISA
TRISB
TRISC
TRISD(1)
TRISE(1)
PCLATH
INTCON
PIE1
PIE2
PCON
SSPCON2
PR2
SSPADD
SSPSTAT
TXSTA
SPBRG
ADRESL
ADCON1
7Fh
80h
81h
82h
83h
84h
85h
86h
87h
88h
89h
8Ah
8Bh
8Ch
8Dh
8Eh
8Fh
90h
91h
92h
93h
94h
95h
96h
97h
98h
99h
9Ah
9Bh
9Ch
9Dh
9Eh
9Fh
accesses
70h-7Fh
Bank 1
File
Address
File
Address
Indirect addr.(*)
TMR0
PCL
STATUS
FSR
PORTB
PCLATH
INTCON
EEDATA
EEADR
EEDATH
EEADRH
General
Purpose
Register
16 Bytes
A0h
General
Purpose
Register
80 Bytes
General
Purpose
Register
Zone slectionne
(BANK)
De 00h 7Fh : BANK 0
De 80h FFh : BANK 1
De 100h 17Fh : BANK 2
De 180h 1FFh : BANK 3
EFh
F0h
FFh
General
Purpose
Register
80 Bytes
accesses
70h-7Fh
Bank 2
100h
101h
102h
103h
104h
105h
106h
107h
108h
109h
10Ah
10Bh
10Ch
10Dh
10Eh
10Fh
110h
111h
112h
113h
114h
115h
116h
117h
118h
119h
11Ah
11Bh
11Ch
11Dh
11Eh
11Fh
120h
16Fh
170h
17Fh
Indirect addr.(*)
OPTION_REG
PCL
STATUS
FSR
TRISB
PCLATH
INTCON
EECON1
EECON2
Reserved(2)
Reserved(2)
General
Purpose
Register
16 Bytes
180h
181h
182h
183h
184h
185h
186h
187h
188h
189h
18Ah
18Bh
18Ch
18Dh
18Eh
18Fh
190h
191h
192h
193h
194h
195h
196h
197h
198h
199h
19Ah
19Bh
19Ch
19Dh
19Eh
19Fh
1A0h
General
Purpose
Register
80 Bytes
accesses
70h - 7Fh
Bank 3
1EFh
1F0h
1FFh
page 15
Les registres appels General Purpose Register ne sont ni plus ni moins que des cases mmoires pour
stocker les donnes.
Remarque : Les 4 banques mmoires ne facilitent pas la gestion de la mmoire.
Par exemple, pour accder la case mmoire 1A0h (BANK3), il ne faut pas oublier de positionner
correctement les bits RP0 et RP1 du registre STATUS.
Code : Transfert du contenu de ladresse 1A0h dans le registre W.
BSF
STATUS,5
; RP0 = 1 Slection de la BANK 3
BSF
STATUS,6
; RP1 = 1 Slection de la BANK 3
MOVF
0x20,0
; Transfert du contenu de ladresse 1A0h dans W.
Pourquoi les concepteurs des PICs ont t obligs de scinder en 4 banques mmoires ?
Ladresse des donnes est code sur 7 bits, donc les adresses vont de 00h 7Fh. Les 2 bits RP0 et RP1
sont 2 bits dadresses supplmentaires et extrieurs, ce qui porte 29 adresses possibles ou 512 registres.
Code binaire de MOVF.
001000 d fff ffff
d : destination 0 si W et 1 si F
fff ffff : adresse mmoire.
page 16
R/W-0
R/W-0
R-1
R-1
R/W-x
R/W-x
R/W-x
IRP
RP1
RP0
TO
PD
DC
bit 7
bit 0
bit 7
bit 6-5
bit 4
bit 3
bit 2
Z: Zero bit
1 = The result of an arithmetic or logic operation is zero
0 = The result of an arithmetic or logic operation is not zero
bit 1
, ADDLW,SUBLW,SUBWF
instructions)
DC: Digit carry/borrow bit (ADDWF
(for borrow, the polarity is reversed)
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
bit 0
, ADDLW,SUBLW,SUBWFinstructions)
C: Carry/borrow bit (ADDWF
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 the second operand. For rotate (RRF, RLF ) instructions, this bit is
loaded with either the high, or low order bit of the source register.
Legend:
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
page 17
Description
Cycl es
14-Bit Opco de
MSb
LSb
Statu s
Affected
Notes
f, d
f, d
f
f, d
f, d
f, d
f, d
f, d
f, d
f, d
f
f, d
f, d
f, d
f, d
f, d
Add W and f
AND W with f
Clear f
Clear W
Complement f
Decrement f
Decrement f, Skip if 0
Increment f
Increment f, Skip if 0
Inclusive OR W with f
Move f
Move W to f
No Operation
Rotate Left f through Carry
Rotate Right f through Carry
Subtract W from f
Swap nibbles in f
Exclusive OR W with f
1
1
1
1
1
1
1(2)
1
1(2)
1
1
1
1
1
1
1
1
1
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
0111
0101
0001
0001
1001
0011
1011
1010
1111
0100
1000
0000
0000
1101
1100
0010
1110
0110
df ff
df ff
lf ff
0x xx
df ff
df ff
df ff
df ff
df ff
df ff
df ff
lf ff
0x x0
df ff
df ff
df ff
df ff
df ff
ffff
ffff
ffff
xxxx
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
0000
ffff
ffff
ffff
ffff
ffff
00bb
01bb
10bb
11bb
bf
bf
bf
bf
ffff
ffff
ffff
ffff
111x
1001
0kkk
0000
1kkk
1000
00xx
0000
01xx
0000
0000
110x
1010
kk kk
kk kk
kk kk
0110
kk kk
kk kk
kk kk
0000
kk kk
0000
0110
kk kk
kk kk
C,DC,Z
Z
Z
Z
Z
Z
Z
Z
Z
C
C
C,DC,Z
Z
1,2
1,2
2
1,2
1,2
1,2,3
1,2
1,2,3
1,2
1,2
1,2
1,2
1,2
1,2
1,2
f, b
f, b
f, b
f, b
Bit Clear f
Bit Set f
Bit Test f, Skip if Clear
Bit Test f, Skip if Set
1
1
1 (2)
1 (2)
01
01
01
01
ff
ff
ff
ff
1,2
1,2
3
3
k
k
k
k
k
k
k
k
k
1
1
2
1
2
1
1
2
2
2
1
1
1
11
11
10
00
10
11
11
00
11
00
00
11
11
kkkk
kkkk
kkkk
0100
kkkk
kkkk
kkkk
1001
kkkk
1000
0011
kkkk
kkkk
C,DC,Z
Z
TO,PD
Z
TO,PD
C,DC,Z
Z
1: When an I/O register is modified as a function of itself ( e.g., MOVF PORTB, 1 ), the value used will be that value present
on the pins themselves. For example, if the data latch is 1 for a pin configured as input and is driven low by an external
device, the data will be written back with a 0.
2: If this instruction is executed on the TMR0 register (and, where applicable, d = 1), the prescaler will be cleared if
assigned to the Timer0 module.
3: If Program Counter (PC) is modified, or a conditional test is true, the instruction requires two cycles. The second cycle is
executed as a NOP.
Dtermine la destination :
d=0 Registre Travail
d=1 Registre Mmoire SFR ou RAM.
Adresse SFR ou RAM en hexa.
Adresse SFR ou RAM en binaire.
Valeur immdiate sur 8bits ou Adresse de destination sur 11 bits.
Valeur dcimale, elle dtermine le bit a modifier ou tester.
Valeur binaire, elle dtermine le bit a modifier ou tester.
Remarque: toutes les instructions ne durent quun seul cycle machine, sauf les instructions de sauts tels
que GOTO, CALL.
page 18
; Mise zro de W
; aucune opration (temporisation)
; Mise en sommeil du C
constante
8.2.3) Exemples.
MOVLW
ADDLW
255
0x20
EQU
EQU
0x06
0x20
; page 0
PORTB
;
;
;
;
page 19
Adresse
PCL
8
11 10
0
GOTO,CALL
PC
2
11
PCLATH<4:3>
Opcode <10:0>
PCLATH
Remarque : Pour le retour de sous programme, il nest pas ncessaire de ce proccuper de ces bits
car la valeur du PC est mmorise sur 13 bits dans la pile.
;
;
;
;
;
page 20
f,b
f,b
pour mettre 1
pour mettre 0
8.6.1.3) Exemples.
BCF
BSF
PORTA,2
STATUS,0
f,b
f,b
8.6.2.3) Exemple.
SINON
FSI
MOVF
CMP,1
BTFSS
GOTO
MOVLW
MOVWF
GOTO
DECF
..
.
STATUS,Z
SINON
0xFF
CMP
FSI
CMP,1
;
;
;
;
;
;
; allez en fin de si
; CMP <- CMP -1 Dcrmenter CMP
page 21
Le PORT B (8 bits) I/O pure et/ou programmation in situ ICSP/ICD (Broche RB3/PGM,
RB6/PGC et RB7/PGD) et lentre dinterruption externe RB0/INT.
Remarque : Si le PIC est utilis en mode ICSP/ICD il faut laisser libre les broches
RB3/PGM, RB6/PGC ainsi que RB7/PGD) et les configurer en entre.
Le PORT C (8 bits) I/O pure et/ou TIMER 1 et/ou SPI / I2C et/ou USART.
Le PORT D (8 bits) I/O pure et/ou port parallle 8 bits associ au PORT E.
Le PORT E (3 bits) I/O pure et/ou pilotage du PORT E RE0/RD, RE1/WR et RE2/CS.
Toutes les lignes de PORTs peuvent fournir un courant de 25mA par ligne de PORT. Une limite de
40mA par PORT doit tre respecte pour des questions de dissipation.
PORTA
PORTC
PORTB
RA0/AN0
RA1/AN1
RA2/AN2/VREFRA3/AN3/VREF+
RA4/T0CKI
RA5/AN4/SS
RB0/INT
RB1
RB2
RB3/PGM
RB4
RB5
RB6/PGC
RB7/PGD
PORTD
PORTE
RD0/PSP0
RD1/PSP1
RD2/PSP2
RD3/PSP3
RD4/PSP4
RD5/PSP5
RD6/PSP6
RD7/PSP7
RC0/T1OSO/T1CKI
RC1/T1OSI/CCP2
RC2/CCP1
RC3/SCK/SCL
RC4/SDI/SDA
RC5/SDO
RC6/TX/CK
RC7/RX/DT
RE0/AN5/RD
RE1/AN6/WR
RE2/AN7/CS
page 22
NC
NC
NC
NC
S
RA5
E
RA4
S
RA3
S
RA2
S
RA1
E
RA0
SENS
PORTB
E
RB7
E
RB6
S
RB5
S
RB4
E
RB3
S
RB2
S
RB1
E
RBO
Programme en assembleur.
Remarque toutes les lignes de sorties des PORTs sont mises zro.
; Mise zro des registres de donnes des ports A et B
clrf PORTA
clrf PORTB
; Configuration des PORTA et B
; Accs aux registres TRISx
bsf
STATUS,RP0 ; RP0 = 1
bcf
STATUS,RP1 ; RP1 = 0
; Configuration des
;
movlw B11010001 ;
movwf TRISA
;
movlw B11001001 ;
movwf TRISB
(Banque mmoire 1)
registres de direction
Configuration du PORTA X X S E S S S E
valeur binaire
1 1 0 1 0 0 0 1
Configuration du PORTB E E S S E S S E
valeur binaire
1 1 0 0 1 0 0 1
page 23
Data Latch
Data
Bus
Data
Bus
CK
I/O pin(1)
WR
TRIS
CK
VSS
Analog
Input
Mode
CK
CK
WR
TRIS
VSS
Schmitt
Trigger
Input
Buffer
RD
TRIS
RD
TRIS
I/O pin(1)
TRIS Latch
TRIS Latch
D
WR
Port
VDD
WR
Port
Data Latch
TTL
Input
Buffer
D
ENEN
RD Port
TMR0 Clock Input
EN
To A/D Converter
Note 1: I/O pins have protection diodes to VDD and VSS.
PORTA FUNCTIONS
Bit#
Buffe r
RA0/AN0
Name
bit0
TTL
Func
tion
RA1/AN1
bit1
TTL
RA2/AN2
bit2
TTL
RA3/AN3/VREF
bit3
TTL
RA4/T0CKI
bit4
ST
Input/output or external clock input for Timer0. Output is open drain type.
RA5/SS/AN4
bit5
TTL
Input/output or slave select input for synchronous serial port or analog input.
Name
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value on:
POR,
BOR
RA5
RA4
RA3
RA2
RA1
RA0
--0x 0000
--0u 0000
--11 1111
--11 1111
--0- 0000
05h
PORTA
85h
TRISA
9Fh
ADCON1 ADFM
Value on all
ot her
RESETS
page 24
BLOCK DIAGRAM OF
BLOCK DIAGRAM OF
RB7:RB4 PINS
VDD
RBPU(2)
VDD
RBPU(2)
Weak
P Pull-up
Weak
P Pull-up
Data Latch
Data Bus
WR Port
Data Latch
D
Q
Data Bus
Q
I/O
pin(1)
CK
WR Port
TRIS Latch
D
WR TRIS
TRIS Latch
D
Q
TTL
Input
Buffer
CK
I/O
pin(1)
CK
WR TRIS
RD TRIS
TTL
Input
Buffer
CK
RD TRIS
Q
Latch
RD Port
ST
Buffer
RD Port
EN
EN
Set RBIF
RB0/INT
RB3/PGM
Schmitt Trigger
Buffer
RD Port
Q1
D
RD Port
From other
RB7:RB4 pins
EN
Q3
RB7:RB6
PORTB FUNCTIONS
Bit#
Bu ffer
RB0/INT
Name
bit0
TTL/ST(1)
uncti on
RB1
bit1
TTL
RB2
bit2
TTL
RB3/PGM(3)
bit3
TTL
RB4
bit4
TTL
RB5
bit5
TTL
RB6/PGC
bit6
TTL/ST(2)
RB7/PGD
bit7
TTL/ST(2)
Name
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value on:
POR,
BOR
RB7
RB6
RB5
RB4
RB3
RB2
RB1
RB0
xxxx xxxx
uuuu uuuu
1111 1111
1111 1111
1111 1111
1111 1111
06h, 106h
PORTB
86h, 186h
TRISB
81h, 181h
OPTION_REG
RBPU
INTEDG
T0CS
T0SE
PSA
PS2
PS1
PS0
Value o n
all o ther
RESETS
page 25
Port/Peripheral Select(2)
Port/Peripheral Select(2)
D
CK
VDD
Data Bus
WR
Port
I/O
pin(1)
Data Latch
D
WR
TRIS
CK
VDD
CK
I/O
pin(1)
Data Latch
Q
Q
WR
TRIS
TRIS Latch
CK
N
Vss
RD
TRIS
Schmitt
Trigger
Peripheral
OE(3)
TRIS Latch
VSS
RD
TRIS
Schmitt
Trigger
Peripheral
OE(3)
EN
RD
Port
D
EN
RD
Port
Schmitt
Trigger
with
SMBus
levels
SSPl Input
Peripheral Input
CKE
SSPSTAT<6>
PORTC FUNCTIONS
Name
Bit#
Buffe r Type
Function
RC0/T1OSO/T1CKI
bit0
ST
RC1/T1OSI/CCP2
bit1
ST
RC2/CCP1
bit2
ST
RC3/SCK/SCL
bit3
ST
RC3 can also be the synchronous serial clock for both SPI
and I2C modes.
RC4/SDI/SDA
bit4
ST
RC4 can also be the SPI Data In (SPI mode) or data I/O (I2C mode).
RC5/SDO
bit5
ST
RC6/TX/CK
bit6
ST
RC7/RX/DT
bit7
ST
Name
07h
PORTC
87h
TRISC
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value on:
POR,
BOR
RC7
RC6
RC5
RC4
RC3
RC2
RC1
RC0
xxxx xxxx
uuuu uuuu
1111 1111
1111 1111
Value on all
ot her
RESETS
page 26
PORTD FUNCTIONS
I/O pin
Data Latch
D
Q
WR
Port
(1)
CK
TRIS Latch
D
Q
WR
TRIS
Schmitt
Trigger
Input
Buffer
CK
Bit#
Buffe r Type
RD0/PSP0
Name
bit0
ST/TTL(1)
Functi on
RD1/PSP1
bit1
ST/TTL(1)
RD2/PSP2
bit2
ST/TTL(1)
RD3/PSP3
bit3
ST/TTL(1)
RD4/PSP4
bit4
ST/TTL(1)
RD5/PSP5
bit5
ST/TTL(1)
RD6/PSP6
bit6
ST/TTL(1)
RD7/PSP7
bit7
ST/TTL(1)
RD
TRIS
ENEN
RD Port
Addre ss
Name
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value on:
POR,
BOR
RD6
RD5
RD4
RD3
RD2
RD1
RD0
xxxx xxxx
uuuu uuuu
1111 1111
1111 1111
0000 -111
0000 -111
WR
Port
PORTD
RD7
88h
TRISD
89h
TRISE
IBF
I/O pin
Data Latch
D
Q
Name
Bit#
Buffe r Type
bit0
ST/TTL(1)
RE1/WR/AN6
bit1
ST/TTL
(1)
I/O port pin or write control input in Parallel Slave Port mode or analog input:
WR
1 = Idle
0 = Write operation. Value of PORTD I/O pins is latched into PORTD
register (if chip selected)
RE2/CS/AN7
bit2
ST/TTL(1)
Q
Schmitt
Trigger
Input
Buffer
CK
RD
TRIS
D
ENEN
Func tion
I/O port pin or read control input in Parallel Slave Port mode or analog input:
RD
1 = Idle
0 = Read operation. Contents of PORTD register are output to PORTD
I/O pins (if chip selected)
RE0/RD/AN5
CK
PORTE FUNCTIONS
(1)
TRIS Latch
WR
TRIS
Legend: x = unknown, u = unchanged, - = unimplemented, read as '0'. Shaded cells are not used by PORTD.
08h
Value on
all o ther
RESETS
I/O port pin or chip select control input in Parallel Slave Port mode or analog input:
CS
1 = Device is not selected
0 = Device is selected
RD Port
Addre ss
Name
Bi t 7
Bit 6
Bit 5
Bit 4
Bit 3
09h
PORTE
89h
TRISE
IBF
OBF
IBOV
PSPMODE
9Fh
ADCON1
ADFM
PCFG3
Bit 2
Bit 1
Bit 0
Value on:
POR, BOR
RE2
RE1
RE0
Value on
all ot her
RESETS
---- -xxx
---- -uuu
0000 -111
0000 -111
PCFG2
--0- 0000
--0- 0000
PCFG1
PCFG0
Legend: x = unknown, u = unchanged, - = unimplemented, read as 0. Shaded cells are not used by PORTE.
page 27
111
110
101
100
VAIN
011
(Input Voltage)
010
A/D
Converter
001
VDD
000
RE2/AN7(1)
RE1/AN6(1)
RE0/AN5(1)
RA5/AN4
RA3/AN3/VREF+
RA2/AN2/VREFRA1/AN1
RA0/AN0
VREF+
(Reference
Voltage)
PCFG3:PCFG0
VREF(Reference
Voltage)
VSS
PCFG3:PCFG0
Remarque : Les entres analogiques RE1/AN5, RE2/AN6 et RE3/AN2 sont disponibles avec les PICs
16F877 et 16F874.
De plus la broche RA4 nest pas concerne pas le convertisseur.
page 28
TAD2
TAD3
TAD4
TAD5
TAD6
TAD7
TAD8
b9
b8
b7
b6
b5
b4
b3
b2
b1
b0
Conversion starts
Holding capacitor is disconnected from analog input (typically 100 ns)
Set GO bit
ADRES is loaded
GO bit is cleared
ADIF bit is set
Holding capacitor is connected to analog input
page 29
U-0
R/W-0
U-0
R/W-0
R/W-0
R/W-0
R/W-0
ADFM
PCFG3
PCFG2
PCFG1
PCFG0
bit 7
bit 0
bit 7
bit 6-4
bit 3-0
AN 7(1)
RE2
AN6 (1)
RE1
AN5 (1)
RE0
AN4
RA5
0000
0001
0010
0011
0100
0101
011x
VREF-
CHAN/
Refs (2)
VDD
VSS
8/0
RA3
VSS
7/1
VDD
VSS
5/0
RA3
VSS
4/1
VDD
VSS
3/0
RA3
VSS
2/1
VDD
VSS
0/0
VREF+
VREF-
RA3
RA2
6/2
VDD
VSS
6/0
VREF+
RA3
VSS
5/1
VREF+
VREF-
RA3
RA2
4/2
VREF+
VREF-
RA3
RA2
3/2
VREF+
VREF-
RA3
RA2
2/2
VDD
VSS
1/0
VREF+
VREF-
RA3
RA2
1/2
AN 2
RA 2
AN1
RA1
AN0
RA0
VREF+
VREF+
VREF+
1000
1001
1010
1011
1100
1101
1110
1111
A = Analog input
Note 1:
2:
AN3
RA3
VREF+
D = Digital I/O
Legend:
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
De plus le bit ADFM permet de choisir entre deux types de justification pour le rsultat.
- Si ADFM=1 alors le rsultat sera justifi droite dans les registre ADRESH et ADRESL, c'est-dire ARESL contient les bits 7 0 du rsultat de la conversion et ADRESH contient 6 zros
suivi des bit 9 et 8 du rsultat de la conversion.
- Si ADFM=0 alors le rsultat sera justifi gauche, c'est--dire ARESH contient les bits 9 2 du
rsultat de la conversion et ADRESH contient les bit 1 et 0 du rsultat de la conversion suivi de
6 zros.
A/D RESULT JUSTIFICATION
10-bit Result
ADFM = 0
ADFM = 1
2107
0765
0000 00
0
0000 00
ADRESH
ADRESL
10-bit Result
Right Justified
ADRESH
ADRESL
10-bit Result
Left Justified
page 30
REGISTE R
(A D DRE S S : 1Fh)
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
U-0
R/W-0
ADCS 1
ADCS0
CHS2
CHS1
CHS0
GO/DONE
ADO N
bit 7
bit 0
bit 7-6
bit 5-3
bit 2
bit 1
bit 0
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
Le choix de lhorloge est dtermin par les bit ADCS1 et ADCS0, sachant que le temps TAD doit tre au
minimum de 1,6S.
TAD vs. MAXIMUM DEVICE OPERATING FREQUENCIES (STANDARD DEVICES (C))
AD Clo ck Sourc e (TAD )
Operation
ADCS1:ADCS0
Max.
2TOSC
00
1.25 MHz
8TOSC
01
5 MHz
32TOSC
10
20 MHz
RC(1, 2, 3)
11
(Note 1)
Note 1: The RC source has a typical TAD time of 4 s, but can vary between 2-6 s.
2: When the device frequencies are greater than 1 MHz, the RC A/D conversion clock source is only recommended for SLEEP operation.
3: For extended voltage devices (LC), please refer to the Electrical Characteristics (Sections 15.1 and 15.2).
page 31
1 1 0 1 1 1 1 1
0 0 0 0 0 0 0 1
ATT
1 0 0 0 0 0 0 1
0 1 1
page 32
11.1) Le timer 0.
11.1.1) Prsentation :
Cest le plus ancien des timers implants dans les PICs, son ancienne appellation tait RTC, pour
Real Time Clock (horloge temps relle). On peut se servir de celui-ci pour gnrer des vnements
priodiques, comme le rafrachissement dafficheurs multiplexs ou lincrmentation de variables (secondes,
minutes . ).
Celui-ci est incrment soit par lhorloge interne (Fosc/4) ou par une horloge applique sur la
broche
TOCKI/ RA4 .
BLOCK DIAGRAM OF THE TIMER0/WDT PRESCALER
Data Bus
CLKOUT (= FOSC/4)
0
RA4/T0CKI
pin
1
T0SE
M
U
X
M
U
X
T0CS
SYNC
2
Cycles
TMR0 Reg
PSA
PRESCALER
Watchdog
Timer
M
U
X
8-bit Prescaler
8
8 - to - 1MUX
PS2:PS0
PSA
WDT Enable bit
0
MUX
PSA
WDT
Time-out
Note: T0CS, T0SE, PSA, PS2:PS0 are (OPTION_REG<5:0>).
Comme on peut le constater sur ce schma le timer 0 partage avec le chien de garde Watchdog le pr
diviseur. Celui-ci est affect lun ou lautre, suivant la valeur du bit PSA (0 : Timer0 et 1 : chien de
garde).
page 33
FOSC/4
0
1
PSout
1
Programmable
Prescaler
T0CKI pin
T0SE
Sync with
Internal
clocks
TMR0
PSout
(2 cycle delay)
Set interrupt
ag bit T0IF
on overow
PSA
T0CS
11.1.2) Fonctionnement :
Le bit T0CS permet de choisir lhorloge, interne (Fosc/4) ou externe T0CKI/RA4. Dans ce dernier cas
lincrmentation du timer 0 peut se faire soit sur front montant ou descendant suivant la valeur du bit T0SE.
Le bit PSA de choisir si horloge permet de pr diviser lhorloge dun rapport allant de 2 256. La valeur de
pr division est fixe par les bits PS2, PS1 et PS0.
Quand le contenu du timer 0 passe de FF 00 le bit T0IF passe 1 pour signaler un dbordement, si le bit
T0IE est 1 alors une interruption timer 0 est dclenche.
Le contenu du timer 0 peut tre modifi tout instant, une condition prs, la nouvelle valeur inscrite dans
le registre TMR0 sera prise en compte aprs 3 cycles machines.
Remarque importante : Lorsque le bit T0IF passe 1 lors du passage de la valeur FFh 00h du registre
TMR0, il doit tre remis 0 de faon logicielle par une instruction du type : bcf INTCON,T0IF
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
RBPU
INTEDG
T0CS
T0SE
PSA
PS2
PS1
PS0
bit 7
bit 0
bit 7
RBPU
bit 6
INTEDG
bit 5
bit 4
bit 3
bit 2-0
TMR0 Rate
1
1
1
1
1
1
1
1
:
:
:
:
:
:
:
:
WDT Rate
2
4
8
16
32
64
128
256
1
1
1
1
1
1
1
1
:
:
:
:
:
:
:
:
1
2
4
8
16
32
64
128
Legend:
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
Name
01h,101h
TMR0
0Bh,8Bh,
10Bh,18Bh
INTCON
81h,181h
OPTION_REG
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value on:
POR,
BOR
Value on
all oth er
RESETS
xxxx xxxx
uu uu uuuu
GIE
PEIE
T0IE
INTE
RBIE
T0IF
INTF
RBIF
0000 000x
00 00 000u
RBPU
INTEDG
T0CS
T0SE
PSA
PS2
PS1
PS0
1111 1111
11 11 1111
page 34
TMR1
TMR1H
Synchronized
Clock Input
TMR1L
1
TMR1ON
On/Off
T1OSC
RC0/T1OSO/T1CKI
RC1/T1OSI/CCP2(2)
T1SYNC
1
T1OSCEN FOSC/4
Enable
Internal
Oscillator(1) Clock
Prescaler
1, 2, 4, 8
0
2
T1CKPS1:T1CKPS0
Synchronize
det
Q Clock
TMR1CS
Note 1: When the T1OSCEN bit is cleared, the inverter is turned off. This eliminates power drain.
11.2.2) Fonctionnement :
Le bit TMR1CS permet de choisir lhorloge soit interne (Fosc/4), externe T1CKI ou un oscillateur quartz
connect sur les broches T1OSO et T1OSI.
Les bits T1CKPS1 et T1CKPS0 permettent de choisir la valeur de la pr division appliquer lhorloge
choisie, de 1 8.
Le bit T1SYNC permet de choisir si lhorloge de sortie du pr diviseur doit tre synchrone avec lhorloge du
microcontrleur. Dans le cas o lon choisit lhorloge interne Fosc/4, il nest pas ncessaire de la
synchroniser.
Le bit TMR1ON active ou dsactive le timer 1. Si ce bit est 1 alors le timer 1 est en fonctionnement et les
registres TMR1H :TMR1L sont incrments chaque coup dhorloge.
Quand le contenu du timer 1 passe de FFFF 0000 le bit TMR1IF passe 1 pour signaler un dbordement,
de plus si le bit TMR1IE est 1 alors une interruption timer 1 est dclenche.
Remarque importante : Lorsque le bit TMR1IF passe 1 lors du passage de la valeur FFFF 0000 des
registres TMR1H :TMR1L, il doit tre remis 0 de faon logicielle par une instruction du type :
bcf PIR1,TMR1IF
page 35
U-0
R/W-0
R/W-0
T1CKPS1 T1CKPS0
R/W-0
R/W-0
T1OSCEN
R/W-0
R/W-0
bit 7
bit 0
bit 7-6
bit 5-4
bit 3
bit 2
bit 1
bit 0
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
Name
Bit 7
0Bh,8Bh,
10Bh, 18Bh
INTCON
GIE
0Ch
PIR1
PSPIF
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value on:
POR,
BOR
Value on
all o ther
RESETS
PEIE
T0IE
INTE
RBIE
T0IF
INTF
RBIF
0000 000x
0000 000u
(1)
ADIF
RCIF
TXIF
SSPIF
CCP1IF
TMR2IF
TMR1IF
0000 0000
0000 0000
(1)
ADIE
RCIE
TXIE
SSPIE
CCP1IE
TMR2IE
TMR1IE
0000 0000
0000 0000
xxxx xxxx
uuuu uuuu
8Ch
PIE1
PSPIE
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
T1SYNC
TMR1CS
TMR1ON
xxxx xxxx
uuuu uuuu
--00 0000
-- uu uuuu
Legend:
x = unknown, u = unchanged, - = unimplemented, read as '0'. Shaded cells are not used by the Timer1 module.
Note 1: Bits PSPIE and PSPIF are reserved on the PIC16F873/876; always maintain these bits clear.
page 36
TMR2 (1)
Output
RESET
Postscaler
1:1 to 1:16
4
EQ
TMR2 Reg
Comparator
PR2 Reg
Prescaler
1:1, 1:4, 1:16
FOSC/4
2
T2CKPS1:
T2CKPS0
T2OUTPS3:
T2OUTPS0
Note 1: TMR2 register output can be software selected by the
SSP module as a baud clock.
11.3.2) Fonctionnement :
Il est incrment par lhorloge interne (Fosc/4) pr divise ou non.
permettent de choisir la valeur de la pr division (1,4 ou 16).
Le contenu du registre incrment TMR2 et il est compar au registre PR2, si ces deux registres sont gaux
alors une impulsion dhorloge est gnre et le contenu de TMR2 est remis 00h. Celle-ci peut servir
dhorloge pour piloter les liaisons I2C et SPI du module SSP ou encore tre divise par un post diviseur
appel : POSTSCALER.
Son rapport de division peut tre de 1 16. Les bits T2OUTPS0, T2OUTPS1, T2OUTPS2, et T2OUTPS3,
permettent de choisir la valeur de la post division 1, 2, 3, 4, 5 . 16.
Quand la sortie du post diviseur passe 1 le bit TMR2IF est positionn, celui-ci peut dclencher une
interruption si celle-ci a t autorise (Bit TMR2IE 1 du registre PIE1).
Remarque importante : Lorsque le bit TMR2IF passe 1 lorsquune impulsion est gnre en sortie du
POSTSCALER, il doit tre remis 0 de faon logicielle par une instruction du type : bcf PIR1,TMR2IF
page 37
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
bit 7
bit 0
bit 7
bit 6-3
bit 2
bit 1-0
Legend:
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
page 38
CCPRxH
and
edge detect
Capture
Enable
TMR1H
Q
s
CCPRxL
TMR1L
CCPxCON<3:0>
page 39
Etat de repos
ligne libre (Idle line)
8 ou 9 bits de donnes
D0
D1
D2
D3
D4
START
D5
D6
D7
D8
D0
STOP START
page 40
TXREG Register
TXIE
8
MSb
(8)
LSb
0
Pin Buffer
and Control
TSR Register
Interrupt
TXEN
RC6/TX/CK pin
SPEN
SPBRG
Baud Rate Generator
TX9
TX9D
12.2.2) Fonctionnement :
ASYNCHRONOUS MASTER TRANSMISSION
Write to TXREG
BRG Output
(Shift Clock)
RC6/TX/CK (pin)
Word 1
START Bit
Bit 0
TXIF bit
(Transmit Buffer
Reg. Empty Flag)
TRMT bit
(Transmit Shift
Reg. Empty Flag)
Bit 1
Word 1
Bit 7/8
STOP Bit
Word 1
Transmit Shift Reg
Cette fonction utilise un registre dcalage pour transmettre les 8 ou 9 bits de linformation du
registre TXREG.
Pour que cette fonction soit oprationnelle, il faut que la broche RC6 du PORTC soit configure en
sortie, positionner 1 le bit SPEN du registre RCSTA et le bit TXEN du registre TXSTA.
Dans le cas o lon utilise une transmission sur 9 bits (Bit de parit par exemple), il faut autoriser la
transmission sur 9 bits via le bit TX9 du registre TXSTA, la valeur du neuvime bit doit tre mise dans le bit
TX9D du registre TXSTA.
Avant de transmettre une information, il faut sassurer que le registre de transmission soit libre
travers le bit TXIF (1 libre et 0 occupe). Le bit TMRT du registre TXSTA indique si la transmission est
compltement termine (1 termine et 0 occupe).
page 41
Name
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value on:
POR,
BOR
Value on
all ot her
RESETS
GIE
PEIE
T0IE
INTE
RBIE
T0IF
INTF
R0IF
0000 000x
0000 000u
PSPIF(1)
ADIF
RCIF
TXIF
SSPIF
CCP1IF
TMR2IF
TMR1IF
0000 0000
0000 0000
SPEN
RX9
SREN
CREN
FERR
OERR
RX9D
0000 -00x
0000 -00x
0000 0000
0000 0000
0000 0000
PIR1
18h
RCSTA
19h
TXREG
ADIE
RCIE
TXIE
CSRC
TX9
TXEN
SYNC
8Ch
PIE1
98h
TXSTA
99h
SSPIE CCP1IE
BRGH
TMR2IE
TMR1IE
0000 0000
TRMT
TX9D
0000 -010
0000 -010
0000 0000
0000 0000
Legend: x = unknown, - = unimplemented locations read as 0. Shaded cells are not used for asynchronous transmission.
Note 1: Bits PSPIE and PSPIF are reserved on the PIC16F873/876; always maintain these bits clear.
R/W-0
R/W-0
R/W-0
U-0
R/W-0
R-1
R/W-0
CSRC
TX9
TXEN
SYNC
BRGH
TRMT
TX9D
bit 7
bit 0
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
page 42
FERR
OERR
CREN
SPBRG
Baud Rate Generator
64
or
16
RSR Register
MSb
STOP (8)
LSb
0 START
RC7/RX/DT
Pin Buffer
and Control
Data
Recovery
RX9
RX9D
SPEN
RCREG Register
FIFO
8
Interrupt
RCIF
Data Bus
RCIE
12.3.2) Fonctionnement :
ASYNCHRONOUS RECEPTION
RX (pin)
Rcv Shift
Reg
Rcv Buffer Reg
Read Rcv
Buffer Reg
RCREG
START
bit
bit0
bit1
bit7/8 STOP
bit
START
bit
bit0
Word 1
RCREG
bit7/8 STOP
bit
START
bit
bit7/8
STOP
bit
Word 2
RCREG
RCIF
(Interrupt Flag)
OERR bit
CREN
Note:
This timing diagram shows three words appearing on the RX input. The RCREG (receive buffer) is read after the third word,
causing the OERR (overrun) bit to be set.
Cette fonction utilise un registre RSR dcalage pour les 8 ou 9 bits de linformation recevoir, une
fois la rception termine la valeur est stocke dans le registre RCREG.
Pour que cette fonction soit oprationnelle, il faut que la broche RC7 du PORTC soit configure en
entre et positionne 1 le bit SPEN du registre RCSTA.
Dans le cas ou lon utilise une rception sur 9 bits, il faut autoriser la rception sur 9 bits via le bit
RX9 du registre RCSTA, la valeur du neuvime bit est rcupre dans le bit RX9D du registre RCSTA.
Avant de lire une information dans le registre RCREG, il faut sassurer que linformation est bien
reue en testant le bit RCIF (1 Donne reue), ce bit est remis 0 lors de la lecture du registre RCREG.
Les bits FERR et OERR peuvent indiquer respectivement une erreur de format et une erreur over
run .
page 43
Bi t 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value on:
POR,
BOR
Value o n
all ot her
RESETS
GIE
PEIE
T0IE
INTE
RBIE
T0IF
INTF
R0IF
0000 000x
0000 000u
PSPIF(1)
ADIF
RCIF
TXIF
SSPIF
CCP1IF
TMR2IF
TMR1IF
0000 0000
0000 0000
SPEN
RX9
SREN
CREN
FERR
OERR
RX9D
0000 -00x
0000 -00x
0000 0000
0000 0000
0000 0000
0000 0000
Name
PIR1
18h
RCSTA
1Ah
8Ch
PIE1
98h
TXSTA
99h
SPBRG
PSPIE(1)
ADIE
RCIE
TXIE
SSPIE
CCP1IE
CSRC
TX9
TXEN
SYNC
BRGH
TMR2IE TMR1IE
TRMT
TX9D
0000 -010
0000 -010
0000 0000
0000 0000
Legend: x = unknown, - = unimplemented locations read as '0'. Shaded cells are not used for asynchronous reception.
Note 1: Bits PSPIE and PSPIF are reserved on PIC16F873/876 devices; always maintain these bits clear.
R/W-0
R/W-0
R/W-0
R/W-0
R-0
R-0
R-x
SPEN
RX9
SREN
CREN
ADDEN
FERR
OERR
RX9D
bit 7
bit 0
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
RX9D: 9th bit of Received Data (can be parity bit, but must be calculated by user firmware)
Legend:
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
page 44
0
1
Tableaux de vitesses :
BAUD R ATES FOR AS YNCHRONOUS MODE (BRGH = 0)
BAUD
RATE
(K)
FOSC = 20 MHz
%
ERROR
KBAUD
FOSC = 16 MHz
SPBRG
va lu e
(d eci mal)
%
ERROR
KBAUD
FOSC = 10 MHz
SPBRG
va lue
(d ecim al)
KBAUD
%
ERROR
SPBRG
val ue
(decim al )
0.3
1.2
1.221
1.75
255
1.202
0.17
207
1.202
0.17
129
2.4
2.404
0.17
129
2.404
0.17
103
2.404
0.17
64
9.6
9.766
1.73
31
9.615
0.16
25
9.766
1.73
15
19.2
19.531
1.72
15
19.231
0.16
12
19.531
1.72
28.8
31.250
8.51
27.778
3.55
31.250
8.51
33.6
34.722
3.34
35.714
6.29
31.250
6.99
57.6
62.500
8.51
62.500
8.51
52.083
9.58
HIGH
1.221
255
0.977
255
0.610
255
LOW
312.500
250.000
156.250
BAUD
RATE
(K)
FOSC = 4 MHz
KBAUD
%
ERROR
SPBRG
va lu e
(d eci mal)
KBAUD
%
ERROR
SPBRG
valu e
(dec im al)
0.3
0.300
207
0.3
191
1.2
1.202
0.17
51
1.2
47
2.4
2.404
0.17
25
2.4
23
9.6
8.929
6.99
9.6
19.2
20.833
8.51
19.2
28.8
31.250
8.51
28.8
33.6
57.6
62.500
8.51
57.6
HIGH
0.244
255
0.225
255
LOW
62.500
57.6
FOSC = 20 MHz
FOSC = 16 MHz
FOSC = 10 MHz
KBAU D
%
ERROR
SPBRG
va lue
(decim al)
KBAUD
%
ERROR
SPBRG
val ue
(decim al )
0.3
1.2
2.4
KBAUD
%
ERROR
SPBRG
va lue
(d ecim al)
2.441
1.71
255
9.6
9. 615
0.16
129
9.615
0.16
103
9.615
0.16
64
19.2
19.231
0.16
64
19.231
0.16
51
19.531
1.72
31
28.8
29.070
0.94
42
29.412
2.13
33
28.409
1.36
21
33.6
33.784
0.55
36
33.333
0.79
29
32.895
2.10
18
57.6
59.524
3.34
20
58.824
2.13
16
56.818
1.36
10
HIGH
4.883
255
3.906
255
2.441
255
LOW
1250.000
1000.000
625.000
BAUD
RATE
(K)
FOSC = 4 MHz
KBAUD
%
ERROR
SPBRG
va lu e
(d eci mal)
KBA UD
%
ERROR
SPBRG
valu e
(d ec im al)
0.3
1.2
1.202
0.17
207
1.2
191
2.4
2.404
0.17
103
2.4
95
9.6
9. 615
0.16
25
9.6
23
19.2
19.231
0.16
12
19.2
11
28.8
27.798
3.55
28.8
33.6
35.714
6.29
32.9
2.04
57.6
62.500
8.51
57.6
HIGH
0.977
255
0.9
255
LOW
250.000
230.4
page 45
Name
Bi t 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value on:
POR,
BOR
Value on
all ot her
RESETS
98h
TXSTA
CSRC
TX9
TXEN
SYNC
BRGH
TRMT
TX9D
0000 -010
18h
RCSTA
SPEN
RX9
SREN
CREN
ADDEN
FERR
OERR
RX9D
0000 000x
0000 000x
99h
SPBRG
0000 0000
0000 0000
0000 -010
Legend: x = unknown, - = unimplemented, read as '0'. Shaded cells are not used by the BRG.
page 46
13.2) Fonctionnement.
Lors dun vnement dans un ou plusieurs des circuits priphriques (ADC, EEPROM, USART-SCI,
MSSP-I2C-SPI, TIMER1, TIMER2) comme par exemple : la fin de conversion, la fin de programmation dun
octet dans lEEPROM, la rception dune information, la dtection dun front, etc et si le bit de linterruption
concerne a t autorise (EEIE, PSPIE, ADIE, RCIE, TXIE, SSPIE, CCP1IE, TMR2IE, TMR1IE, CCP2IE
ou BCLIE : Registres PIE1 et PIE2) alors une interruption priphrique est dclenche. Pour que celle-ci
soit prise en compte il faut que le bit dautorisation des interruptions priphriques soit positionn 1 (PEIE)
ainsi que le bit GIE dautorisation globale des interruptions du registre INTCON.
Pour quune interruption du type TIMER0 ou INT/RB0 ou PORTB soit prise en compte il suffit que le
bit local dautorisation dinterruption soit positionn 1 (T0IE ou INTE ou RBIE) ainsi que le bit GIE
dautorisation globale des interruptions du registre INTCON.
Dans ces conditions le programme en cours dexcution est interrompu et le microcontrleur
excute le programme dinterruption partir de ladresse 0x0004. Au dbut de celui-ci il faut que le logiciel
vrifie quel priphrique a dclench linterruption.
INTERRUPT LOGIC
EEIF
EEIE
PSPIF
PSPIE
ADIF
ADIE
T0IF
T0IE
INTF
INTE
RCIF
RCIE
TXIF
TXIE
Interrupt to CPU
RBIF
RBIE
SSPIF
SSPIE
PEIE
CCP1IF
CCP1IE
GIE
TMR2IF
TMR2IE
TMR1IF
TMR1IE
CCP2IF
CCP2IE
BCLIF
BCLIE
T0IF
INTF
RBIF
RCIF
TXIF
SSPIF
PIC16F876/873
Yes
Yes
Yes
PSPIF ADIF
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
PIC16F877/874
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
page 47
Q1
Q2
Q3
Q4
Timing
Q1
Q2
Q3
Q4
Q1
Q2
Q3
Q4
Q1
Q2
Q3
Q4
Q1
Q2
Q3
Q4
OSC1
CLKOUT 3
INT pin
INTF ag
(INTCON<1>)
Interrupt Latency 2
GIE bit
(INTCON<7>)
INSTRUCTION FLOW
PC
PC
Instruction
fetched
Inst (PC)
Instruction
executed
Inst (PC-1)
PC+1
PC+1
Inst (PC+1)
Inst (PC)
Dummy Cycle
0004h
0005h
Inst (0004h)
Inst (0005h)
Dummy Cycle
Inst (0004h)
W_TEMP
STATUS,W
STATUS
STATUS_TEMP
PCLATH, W
PCLATH_TEMP
PCLATH
RP0
page 48
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
RBPU
INTEDG
T0CS
T0SE
PSA
PS2
PS1
PS0
bit 7
bit 6
bit 0
- Le registre INTCON permet dautoriser les interruptions globales (GIE), les interruptions des priphriques
(PEIE), Linterruption TIMER0 (T0IE), linterruption extrieure (INT/RB0), linterruption de changement dtat
du PORTB (RBIE) et les indicateurs associs des interruptions (TIMER0, INT/RB0 et du changement dtat
du PORTB : RBIF).
INTCON REGISTER (ADDRESS 0Bh, 8Bh, 10Bh, 1 8Bh)
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-x
GIE
PEIE
T0IE
INTE
RBIE
T0IF
INTF
RBIF
bit 7
bit 0
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
page 49
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
PSPIE(1)
ADIE
RCIE
TXIE
SSPIE
CCP1IE
TMR2IE
TMR1IE
bit 7
bit 0
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
R/W-0
U-0
R/W-0
R/W-0
U-0
U-0
R/W-0
Reserved
EEIE
BCLIE
CCP2IE
bit 7
bit 7
bit 0
bit 6
bit 5
bit 4
bit 3
bit 2-1
bit 0
page 50
R/W-0
R-0
R-0
R/W-0
R/W-0
R/W-0
R/W-0
PSPIF(1)
ADIF
RCIF
TXIF
SSPIF
CCP1IF
TMR2IF
TMR1IF
bit 0
bit 7
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
page 51