Deloizy 1
PIC 16F628
Microchip
FLASH-Based 8-bit CMOS Microcontroller
I.1. Caractéristiques
CPU RISC
35 instructions (exécutées en 200ns)
fonctionnement statique à 20 MHz
2 K-mots mémoire programme (FLASH)
224 octets RAM
128 octets EEPROM
15 lignes d’Entrées/sorties
Module comparateur analogique
3 timers (deux 8 bits et un 16 bits)
module capture/comparaison/PWM
USART
I.2. Brochage
Microchip PIC 16F628 M. Deloizy 2
Legend:
O = output I/O = input/output P = power — = Not used
I = Input ST = Schmitt Trigger input TTL = TTL input I/OD =input/open drain
output
Note 1: This buffer is a Schmitt Trigger input when configured as the external interrupt.
Note 2: This buffer is a Schmitt Trigger input when used in serial programming mode.
Note 3: This buffer is a Schmitt Trigger I/O when used in USART/Synchronous mode.
Note 4: This buffer is a Schmitt Trigger I/O when used in CCP mode.
Note 5: This buffer is a Schmitt Trigger input when used in low voltage program mode.
Microchip PIC 16F628 M. Deloizy 3
IIII.. Architecture interne
→ Architecture Harvard
mémoire données 8 bits
mémoire programme 14 bits
PC 13 bits
II.1.b. Pile
Non implantée dans les plans mémoire
Accessible par instructions spécifiques
→ CALL, RETURN, RETFIE, RETLW
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)
bit 4: TO: Time-out bit
1 = After power-up, CLRWDT instruction, or SLEEP instruction
0 = A WDT time-out occurred
bit 3: PD: Power-down bit
1 = After power-up or by the CLRWDT instruction
0 = By execution of the SLEEP instruction
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: DC: Digit carry/borrow bit (ADDWF, ADDLW,SUBLW,SUBWF
instructions) (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: 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 1: When in ER oscillator mode, setting OSCF = 1 will cause the oscillator
speed to change to the speed specified by the external resistor.
♦ PCL et PCLATH
→ constitution de PC (13 bits)
Microchip PIC 16F628 M. Deloizy 12
♦ INDF et FSR
→ Adressage indirect
FSR contient l’adresse de la donnée
L’opération de lecture ou d’écriture sur INDF porte en réalité sur la donnée
pointée par FSR.
II.2.a. EEDATA :
→ Contient la donnée lue ou à écrire
II.2.b. EEADR :
→Indique l’adresse de la donnée
II.2.c. EECON1 :
→ Indique le type d’opération à réaliser.
III.2. Oscillateur
III.2.e. RC interne
Fournit en interne un oscillateur à 4MHz (5V / 25°C)
Microchip PIC 16F628 M. Deloizy 16
III.3. Démarrage du système
6 possibilités au démarrage du système :
• Power on reset (POR)
→ mise sous tension du système
• MCLR activé pendant fonctionnement normal
• MCLR activé pendant mode SLEEP
• Watchdog pendant fonctionnement normal
• Watchdog pendant le mode SLEEP
• Chute de la tension d’alimentation (Brown-Out Detect)
→ quand Vcc tombe en dessous de 4V.
III.4. Interruptions
Sources d’interruptions :
Interruption externe RB0/INT Changement sur PortB (RB7 :RB4)
TMR0 overflow Comparateur
TMR1 overflow USART
TMR2 match CCP
Quand iT demandée :
• GIE (Global Interrupt Enable) mis à 0 (interdit autres iT)
• Adresse de retour empilée
• PC chargé avec 0004h
• … sauvegarder W et STATUS (pas dans la pile !)
• … vérification de la source d’iT
• … traitement de l’iT
• … acquittement de l’iT par remise à 0 des flags d’iT
• RETFIE → termine la routine d’iT (et remet GIE à 1).
Microchip PIC 16F628 M. Deloizy 17
III.5. Watchdog
→ compteur indépendant.
Durée ≈ 18ms sans prédiviseur d’horloge (jusqu’à 2,3s avec)
Réveil par :
• MCLR → Réinitialisation du système
• Watchdog Poursuite du
• Interruption sur RB0/INT ou RB change ou comparateur programme
Microchip PIC 16F628 M. Deloizy 18
2 possibilités :
♦ avec tension de programmation
RB6 & RB7 maintenus à 0 pendant que Vpp passe de 0 à VIHH (VDD+3,5 à 13,5V)
♦ en basse tension (5V)
bit LVP du mot de configuration mis à 1.
Mode programmation atteint quand RB4=1 (interdit utilisation de RB4 en E/S)
LVP peut être mis à 1 en mode « haute tension » (ce mode est toujours
disponible).
Microchip PIC 16F628 M. Deloizy 19
Exemples :
CLRW 0→W
DECF CNT,1 CNT-1 → CNT
DECF CNT,0 CNT-1 → W
ENCORE DECFSZ REG,1 décrémente REG ; SKIP* si Zéro
GOTO ENCORE brancher à ENCORE si REG ≠ 0
SUITE f défini = 1
SWAP RG1,f si RG1=F4h ⇒ RG1=4Fh
SUBWF AB,W AB-W → W ; C=1 si résultat ≥ 0
W défini = 0
(*) : n'exécute pas l'instruction suivante.
Exemples :
BCF REG,3 met à 0 le bit 3 de REG
BTFSC CNT,7 test du bit 7 de CNT ; SKIP si = 0
Exemples :
MOVLW 5
CALL TABLE
………..
TABLE ADDWF PC
RETLW CT1 CT1 : valeur retournée si W=1
RETLW CT2 CT2 : valeur retournée si W=2
RETLW CT3 CT3 : valeur retournée si W=3
………..
Microchip PIC 16F628 M. Deloizy 21
V
V.. Périphériques
V.1.a. PORTA
Particularités :
entrées avec trigger de Schmitt
RA4 sortie drain ouvert
RA5 entrée seulement
autres sorties avec drivers push-pull
bits de TRISA :
'1' : drivers de sortie en haute impédance
'0' : drivers en basse impédance
Exemple d'initialisation
CLRF PORTA ;Initialize PORTA by
;setting output data latches
MOVLW 0x07 ;Turn comparators off and
MOVWF CMCON ;enable pins for I/O functions
BCF STATUS,RP1
BSF STATUS,RP0 ;Select Bank1
MOVLW 0x1F ;Value used to initialize
;data direction
MOVWF TRISA ;Set RA<4:0> as inputs
;TRISA<5> always read as ‘1’.
;TRISA<7:6> depend on oscillator mode
Microchip PIC 16F628 M. Deloizy 23
V.1.b. PORTB
8 bits bidirectionnel
Possibilité tirage haut interne (OPTION.7) (≈200µA)
bits de TRISB :
'1' : drivers de sortie en haute impédance
'0' : drivers en basse impédance
V.2. USART
(UNIVERSAL SYNCHRONOUS/ASYNCHRONOUS RECEIVER/TRANSMITTER)
Communication série synchrone ou asynchrone
sur pattes RB2/TX/CK and RB1/RX/DT
contrôlé par :
- TXSTA : état et contrôle de la transmission
- RCSTA : état et contrôle de la réception
- SPBRG : générateur de bauds
module d'émission :
module de réception :
Microchip PIC 16F628 M. Deloizy 24
Mode synchrone :
Fosc
Baud = avec BRGH = 0
4 ⋅ (SPBRG + 1)
Mode asynchrone :
Fosc
Baud = (BRGH = 0)
64 ⋅ (SPBRG + 1)
Fosc
Baud = (BRGH = 1)
16 ⋅ (SPBRG + 1)
VII.. Annexes
V
__CONFIG _CP_OFF & _WDT_ON & _BODEN_ON & _PWRTE_ON & _ER_OSC_CLKOUT &
_MCLRE_ON & _LVP_ON
;**********************************************************************
ORG 0x000 ; processor reset vector
goto main ; go to beginning of program
main