« Comment démarrer avec un PIC16F84 » : différence entre les versions

Contenu supprimé Contenu ajouté
Aucun résumé des modifications
 
Ligne 1 :
{{Modèle:Assembleur}}
 
<div style="width:70%; margin:auto; text-align:center;">
{| width="70%" border="0" cellspacing="0" cellpadding="5"
| align="center" |
 
''Un livre appartenant à la série [[Programmation]]<br/>
et à l'[[Accueil/Informatique|étagère Informatique]] de [[Accueil|Wikilivres]]''. [[Image:25%.svg]]
 
</div>
|-
| align="left" |
|-
|}
 
== Introduction ==
Ligne 124 ⟶ 119 :
'''Bank 0'''
 
<span style="color:darkblue#17f;">00h INDF</span> <span style="color:green#0a0;">Utilisé en adressage indirect avec FSR, il ne s’agit pas d’un registre physique</span>
<span style="color:darkblue#17f;">01h TMR0</span> <span style="color:green#0a0;">Timer/Compteur 8 bits</span>
<span style="color:darkblue#17f;">02h PCL</span> <span style="color:green#0a0;">Poids faible du compteur programme (PC)</span>
<span style="color:darkblue#17f;">03h STATUS</span> <span style="color:green#0a0;">Registre d’état dont les bits sont : IRP RP1 RP0 TO PD Z DC C</span>
<span style="color:darkblue#17f;">04h FSR</span> <span style="color:green#0a0;">Pointeur d’adresse en adressage indirect.</span>
<span style="color:darkblue#17f;">05h PORTA</span> <span style="color:green#0a0;">Port d’Entrée/Sortie A dont les bits sont : x x x RA4/T0CKI RA3 RA2 RA1 RA0</span>
<span style="color:darkblue#17f;">06h PORTB</span> <span style="color:green#0a0;">Port d’Entrée/Sortie B dont les bits sont: RB7 RB6 RB5 RB4 RB3 RB2 RB1 RB0/INT</span>
<span style="color:darkblue#17f;">07h Pas utilisé</span>
<span style="color:darkblue#17f;">08h EEDATA</span> <span style="color:green#0a0;">Registre de données de l’ Eeprom</span>
<span style="color:darkblue#17f;">09h EEADR</span> <span style="color:green#0a0;">Registre d’adresses de l’ Eeprom</span>
<span style="color:darkblue#17f;">0Ah PCLATH</span> <span style="color:green#0a0;">5 bits de poids fort du compteur programme</span>
<span style="color:darkblue#17f;">0Bh INTCON</span> <span style="color:green#0a0;">Registre des Interruptions dont les bits sont: GIE EEIE T0IE INTE RBIE T0IF INTF RBIF</span>
 
 
'''Bank 1'''
 
<span style="color:darkblue#17f;">80h INDF</span> <span style="color:green#0a0;">Utilisé en adressage indirect avec FSR, il ne s’agit pas d’un registre physique</span>
<span style="color:darkblue#17f;">81h OPTION_REG</span> <span style="color:green#0a0;">Registre d’options, bits : RBPU INTEDG T0CS T0SE PSA PS2 PS1 PS0</span>
<span style="color:darkblue#17f;">82h PCL</span> <span style="color:green#0a0;">Poids faible du compteur programme (PC)</span>
<span style="color:darkblue#17f;">83h STATUS</span> <span style="color:green#0a0;">Registre d’état dont les bits sont : IRP RP1 RP0 TO PD Z DC C</span>
<span style="color:darkblue#17f;">84h FSR</span> <span style="color:green#0a0;">Pointeur d’adresse en adressage indirect.</span>
<span style="color:darkblue#17f;">85h TRISA</span> <span style="color:green#0a0;">Registre de Direction du Port A</span>
<span style="color:darkblue#17f;">86h TRISB</span> <span style="color:green#0a0;">Registre de Direction du Port B</span>
<span style="color:darkblue#17f;">87h Pas utilisé</span>
<span style="color:darkblue#17f;">88h EECON1</span> <span style="color:green#0a0;">Registre de Contrôle n°1 de l’ Eeprom : x x x EEIF WRERR WREN WR RD</span>
<span style="color:darkblue#17f;">89h EECON2</span> <span style="color:green#0a0;">Registre de contrôle n°2 de l’ Eeprom (il ne s’agit pas d’un registre physique)</span>
<span style="color:darkblue#17f;">0Ah PCLATH</span> <span style="color:green#0a0;">5 bits de poids fort du compteur programme</span>
<span style="color:darkblue#17f;">0Bh INTCON</span> <span style="color:green#0a0;">Registre des ITs dont les bits sont: GIE EEIE T0IE INTE RBIE T0IF INTF RBIF</span>
 
 
Ligne 166 ⟶ 161 :
Voici les bits du registre STATUS qui reflètent le status de l’ALU du PIC, le status du reset et permet également de changer de Bank de registres.
 
<span style="color:darkblue#17f;"> b7: IRP non utilisé dans le 16F84</span>
<span style="color:darkblue#17f;"> b6-5: RP1 RP0 Sélection de la bank de registres active</span>
<span style="color:green#0a0;">00: Bank0
01: Bank1
10: non utilisé sur le 16F84
11: non utilisé sur le 16F84</span>
<span style="color:darkblue#17f;"> b4: TO\ Time Out du watch dog</span>
<span style="color:green#0a0;">1: après un démarrage, CLRWDT ou SLEEP.
0: après un time-out du watch dog</span>
<span style="color:darkblue#17f;"> b3: PD\ Power down bit</span>
<span style="color:green#0a0;">1: après un démarrage ou après l’instruction CLRWDT
0: après l’exécution de l’instruction SLEEP</span>
<span style="color:darkblue#17f;"> b2: Z bit Zero</span>
<span style="color:green#0a0;">1: Résultat de l’opération précédente nul
0: Résultat de l’opération non nul</span>
<span style="color:darkblue#17f;"> b1: DC Digital carry / borrow\</span>
<span style="color:green#0a0;">1: Débordement du 4° bit du résultat de l’opération précédente
0: Pas de débordement</span>
<span style="color:darkblue#17f;"> b0: C Carry / borrow\</span>
<span style="color:green#0a0;">1: Débordement bit du résultat de l’opération précédente
0: Pas de débordement</span>
 
Ligne 193 ⟶ 188 :
Permet de configurer les résistances de rappel internes du PortB, et aussi l’INT externe, le Timer0 et le prescaler du Timer0 ou du watch-dog
 
<span style="color:darkblue#17f;"> b7: RBPU\ Résistances de rappel des entrées du PortB</span>
<span style="color:green#0a0;"> 1: Les résistances sont désactivées
0: Les résistances du PortB sont activées</span>
<span style="color:darkblue#17f;"> b6: INTEDG Sélection du front actif de l’INT externe</span>
<span style="color:green#0a0;"> 1: Interruption sur le front montant de RB0/INT
0: Interruption sur le front descendant de RB0/INT</span>
<span style="color:darkblue#17f;"> b5: TOCS Source de l’horloge du Timer0</span>
<span style="color:green#0a0;"> 1: Comptage sur la pin RA4/TOCKI
0: Comptage sur l’horloge interne CLKOUT</span>
<span style="color:darkblue#17f;"> b4: TOCE Sélection du front actif pour le comptage sur RA4/TOCKI</span>
<span style="color:green#0a0;"> 1: Comptage sur front descendant
0: Comptage sur front montant</span>
<span style="color:darkblue#17f;"> b3: PSA Assignation du Prescaler</span>
<span style="color:green#0a0;"> 1: Prescaler assigné au chien de garde WDT
0: Assigné au Timer TMR0</span>
<span style="color:darkblue#17f;"> b2-b1-b0: PS2:PS1:PS0 Valeur du Prescaler du TMR0 ou du WDT</span>
<span style="color:green#0a0;">
''''' Valeurs du prescaler'''''
PS2:PS1:PS0 Prescaler TMR0 Prescaler WDT
Ligne 228 ⟶ 223 :
 
 
<span style="color:darkblue#17f;"> b7: GIE Autorisation Globale des Interruptions</span>
<span style="color:green#0a0;"> 1: Autorise toutes les interruptions
0: Interdit toutes les interruptions</span>
<span style="color:darkblue#17f;"> b6: EEIE Autorisation de l’interruption de fin d’écriture en Eeprom</span>
<span style="color:green#0a0;"> 1: Autorise l’interruption de fin d’écriture en Eeprom
0: Interdit l’interruption de fin d’écriture en Eeprom</span>
<span style="color:darkblue#17f;"> b5: TOIE Autorisation de l’interruption de débordement de TMR0</span>
<span style="color:green#0a0;"> 1: Autorise l’interruption de TMR0
0: Interdit l’interruption de TMR0</span>
<span style="color:darkblue#17f;"> b4: INTE Autorisation de l’interruption sur RB0/INT</span>
<span style="color:green#0a0;"> 1: Autorise l’interruption sur RB0/INT
0: Interdit l’interruption sur RB0/INT</span>
<span style="color:darkblue#17f;"> b3: RBIE Autorisation de l’interruption lors d’un changement d’état sur le PortB</span>
<span style="color:green#0a0;"> 1: Autorise l’interruption sur RB7:RB4
0: Interdit l’interruption sur RB7:RB4</span>
<span style="color:darkblue#17f;"> b2: TOIF Flag de débordement de TMR0</span>
<span style="color:green#0a0;"> 1: Le TMR0 a débordé (à effacer par programme)
0: Le TMR0 n’a pas débordé</span>
<span style="color:darkblue#17f;"> b1: INTF Flag d’interruption sur RB0/INT</span>
<span style="color:green#0a0;"> 1: Il y a eu une demande d’interruption sur RB0/INT
0: Il n’y a pas d’interruption sur RB0/INT</span>
<span style="color:darkblue#17f;"> b0: RBIF Flag d’interruption sur le PortB</span>
<span style="color:green#0a0;"> 1: Au moins une pin RB7:RB4 a changé d’état (doit être effacé par programme)
0: Il n’y a pas de changement d’état sur RB7:RB4</span>
 
Ligne 367 ⟶ 362 :
 
'' Liste des broches, classées par catégories:''
<span style="color:darkblue#17f;">OSC1/CLKIN (pin 16)</span> <span style="color:green#0a0;">Quartz ou entrée de l’horloge externe</span>
<span style="color:darkblue#17f;">OSC2/CLKOUT (pin 15)</span> <span style="color:green#0a0;">Quartz en mode cristal ou sortie d’horloge à 1/4 de la fréquence en mode RC</span>
<span style="color:darkblue#17f;">MCLR\ (pin 4)</span> <span style="color:green#0a0;">Master Clear (Reset) ou tension de programmation. (Reset actif à l’état bas).</span>
<span style="color:darkblue#17f;">Port A :</span>
<span style="color:darkblue#17f;">RA0 (pin 17)</span> <span style="color:green#0a0;">Port A I/O TTL</span>
<span style="color:darkblue#17f;">RA1 (pin 18)</span> <span style="color:green#0a0;">Port A I/O TTL</span>
<span style="color:darkblue#17f;">RA2 (pin 1)</span> <span style="color:green#0a0;">Port A I/O TTL</span>
<span style="color:darkblue#17f;">RA3 (pin 2)</span> <span style="color:green#0a0;">Port A I/O TTL</span>
<span style="color:darkblue#17f;">RA4/T0CKI (pin 3)</span> <span style="color:green#0a0;">Port A I/O Entrée Trigger, sortie Drain ouvert. Entrée de comptage TMR0</span>
<span style="color:darkblue#17f;">Port B :</span> <span style="color:green#0a0;">peut être programmé pour avoir des résistances de pull-up internes sur ses entrées.</span>
<span style="color:darkblue#17f;">RB0/INT (pin 6)</span> <span style="color:green#0a0;">Port B I/O TTL en I/O et Entrée d’Interruption avec Trigger</span>
<span style="color:darkblue#17f;">RB1 (pin 7)</span> <span style="color:green#0a0;">Port B I/O TTL</span>
<span style="color:darkblue#17f;">RB2 (pin 8)</span> <span style="color:green#0a0;">Port B I/O TTL</span>
<span style="color:darkblue#17f;">RB3 (pin 9)</span> <span style="color:green#0a0;">Port B I/O TTL</span>
<span style="color:darkblue#17f;">RB4 (pin 10)</span> <span style="color:green#0a0;">Port B I/O TTL avec Interruption sur changement d’état de l’entrée</span>
<span style="color:darkblue#17f;">RB5 (pin 11)</span> <span style="color:green#0a0;">Port B I/O TTL avec Interruption sur changement d’état de l’entrée</span>
<span style="color:darkblue#17f;">RB6 (pin 12)</span> <span style="color:green#0a0;">Port B I/O TTL avec Interruption sur changement d’état de l’entrée.</span>
Serial programming clock avec entrée Trigger.
<span style="color:darkblue#17f;">RB7 (pin 13)</span> <span style="color:green#0a0;">Port B I/O TTL avec Interruption sur changement d’état de l’entrée.</span>
Serial programming data avec entrée Trigger.
<span style="color:darkblue#17f;">VSS (pin 5)</span> <span style="color:green#0a0;">Masse</span>
<span style="color:darkblue#17f;">VDD (pin 14)</span> <span style="color:green#0a0;">Alimentation positive</span>
</font>
 
Ligne 439 ⟶ 434 :
'''Exemple de configuration du PORTA:'''
 
<span style="color:darkblue#17f;">BSF STATUS, RP0</span> <span style="color:green#0a0;">; Acces Bank1</span>
<span style="color:darkblue#17f;">MOVLW 0xFB</span> <span style="color:green#0a0;">; TRISA.b2 à 0 pour RA2 en sortie (% 1111.1011)</span>
<span style="color:darkblue#17f;">MOVWF TRISA</span>
<span style="color:darkblue#17f;">BCF STATUS, RP0</span> <span style="color:green#0a0;">; Acces Bank0</span>
<span style="color:darkblue#17f;">…</span>
<span style="color:darkblue#17f;">…</span>
<span style="color:darkblue#17f;">BCF STATUS, RP0</span> <span style="color:green#0a0;">; Acces Bank0</span>
<span style="color:darkblue#17f;">BSF PORTA, RA2</span> <span style="color:green#0a0;">; Allume la Led connectée à la ligne RA2</span>
 
 
Ligne 460 ⟶ 455 :
'''Exemple de code:'''
 
<span style="color:green#0a0;">; Clignotement d'une Led sur RA2</span>
 
<span style="color:green#0a0;">;;;;;;; *** Configuration</span>
<span style="color:darkblue#17f;"> LIST p=16F84A</span> <span style="color:green#0a0;">; Processeur 16F84A</span>
<span style="color:darkblue#17f;">#INCLUDE <p16F84A.inc></span> <span style="color:green#0a0;">; Définition des registre internes du 16F84</span>
<span style="color:darkblue#17f;">__CONFIG _CP_OFF & _WDT_OFF & _HS_OSC</span> <span style="color:green#0a0;">; Option de programmation </span>
 
<span style="color:green#0a0;"> ;;;;;;; *** Définitions</span>
<span style="color:darkblue#17f;"> RA2 EQU 0x02</span> <span style="color:green#0a0;">; PortA, sortie RA2</span>
 
<span style="color:green#0a0;"> ;;;;;;; *** Variables</span>
<span style="color:darkblue#17f;">CBLOCK 0x0C
vTempo1, vTempo2;
ENDC</span>
 
<span style="color:green#0a0;"> ;;;;;;; *** Vecteurs</span>
<span style="color:darkblue#17f;">ORG H'0000'</span> <span style="color:green#0a0;">; Déclaration du Reset</span>
<span style="color:darkblue#17f;">GOTO Start</span>
 
<span style="color:green#0a0;">; * Tempo de clignotement qui utilise deux variables pour obtenir une tempo longue</span>
 
<span style="color:darkblue#17f;">Tempo MOVLW 0xFF</span> <span style="color:green#0a0;">; Charge W avec 0xFF</span>
<span style="color:darkblue#17f;"> MOVWF vTempo2</span> <span style="color:green#0a0;">; pour charge la vTempo2</span>
<span style="color:darkblue#17f;">_Tempo2 MOVWF vTempo1</span> <span style="color:green#0a0;">; et la vTempo1</span>
<span style="color:darkblue#17f;">_Tempo1 DECFSZ vTempo1, f</span> <span style="color:green#0a0;">; Décrémente vTempo et met le résultat dans vTempo</span>
<span style="color:darkblue#17f;"> GOTO _Tempo1</span> <span style="color:green#0a0;">; puis saute l'instruction suivante si 0. </span>
<span style="color:darkblue#17f;"> DECFSZ vTempo2, f</span>
<span style="color:darkblue#17f;"> GOTO _Tempo2</span>
<span style="color:darkblue#17f;"> RETURN</span>
<span style="color:green#0a0;">; * Programme principal</span>
 
<span style="color:darkblue#17f;">Start BSF STATUS, RP0</span> <span style="color:green#0a0;">; Acces Bank1</span>
<span style="color:darkblue#17f;"> MOVLW 0xFB</span> <span style="color:green#0a0;">; TRISA.b2 à 0 pour RA2 en sortie</span>
<span style="color:darkblue#17f;"> MOVWF TRISA</span>
<span style="color:darkblue#17f;"> BCF STATUS, RP0</span> <span style="color:green#0a0;">; Acces Bank0</span>
<span style="color:darkblue#17f;"> BSF PORTA, RA2</span> <span style="color:green#0a0;">; Allume la Led</span>
<span style="color:darkblue#17f;"> CALL Tempo</span>
<span style="color:darkblue#17f;"> BCF PORTA, RA2</span> <span style="color:green#0a0;">; Eteint la Led</span>
<span style="color:darkblue#17f;"> CALL Tempo</span>
<span style="color:darkblue#17f;"> GOTO Start</span> <span style="color:green#0a0;">; Reboucle au départ</span>
<span style="color:darkblue#17f;"> END</span>
 
La temporisation utilisée peut être améliorée de la sorte, afin d’obtenir des temps calibrés:
 
<span style="color:darkblue#17f;">
CBLOCK 0x0C
vWait1, vWait2, vWait3;
Ligne 513 ⟶ 508 :
<span style="color:green#0a0;"> ; * Tempo 500µS 1+1+165*(1+2)+1+2=500µS</span>
<span style="color:darkblue#17f;">T_500us MOVLW 0xA5</span> <span style="color:green#0a0;">; 1 cy</span>
<span style="color:darkblue#17f;"> MOVWF vWait1</span> <span style="color:green#0a0;">; 1 cy</span>
<span style="color:darkblue#17f;"> NOP</span> <span style="color:green#0a0;">; 1 cy</span>
<span style="color:darkblue#17f;">_T1 DECFSZ vWait1, f</span> <span style="color:green#0a0;">; 1 cy</span>
<span style="color:darkblue#17f;"> GOTO _T1</span> <span style="color:green#0a0;">; 2 cy</span>
<span style="color:darkblue#17f;"> NOP</span> <span style="color:green#0a0;">; 1 cy</span>
<span style="color:darkblue#17f;"> RETURN</span> <span style="color:green#0a0;">; 2 cy</span>
 
<span style="color:green#0a0;"> ; * Tempo 100ms 1+1+198*(2+500µS+1+2)+6+2=100'000µS = 100 mS</span>
<span style="color:darkblue#17f;">T_100ms MOVLW 0xC6</span> <span style="color:green#0a0;">; 1 cy</span>
<span style="color:darkblue#17f;"> MOVWF vWait2</span> <span style="color:green#0a0;">; 1 cy</span>
<span style="color:darkblue#17f;"> NOP</span> <span style="color:green#0a0;">; 1 cy</span>
<span style="color:darkblue#17f;">_T2 CALL T_500us</span> <span style="color:green#0a0;">; 2 cy + 500µS</span>
<span style="color:darkblue#17f;"> DECFSZ vWait2, f</span> <span style="color:green#0a0;">; 1 cy</span>
<span style="color:darkblue#17f;"> GOTO _T2</span> <span style="color:green#0a0;">; 2 cy</span>
<span style="color:darkblue#17f;"> NOP</span> <span style="color:green#0a0;">; </span>
<span style="color:darkblue#17f;"> NOP</span> <span style="color:green#0a0;">; </span>
<span style="color:darkblue#17f;"> NOP</span> <span style="color:green#0a0;">; </span>
<span style="color:darkblue#17f;"> NOP</span> <span style="color:green#0a0;">; </span>
<span style="color:darkblue#17f;"> NOP</span> <span style="color:green#0a0;">; </span>
<span style="color:darkblue#17f;"> NOP</span> <span style="color:green#0a0;">; 6 cy</span>
<span style="color:darkblue#17f;"> RETURN</span> <span style="color:green#0a0;">; 2 cy</span>
 
<span style="color:green#0a0;"> ; * Tempo 1 S 1+1+10*(2+100'000µS+1+2)+2= 1,000054 secondes</span>
<span style="color:darkblue#17f;">T_1s MOVLW 0x0A</span> <span style="color:green#0a0;">; 1 cy</span>
<span style="color:darkblue#17f;"> MOVWF vWait3</span> <span style="color:green#0a0;">; 1 cy</span>
<span style="color:darkblue#17f;"> NOP</span> <span style="color:green#0a0;">; 1 cy</span>
<span style="color:darkblue#17f;">_T3 CALL T_100ms</span> <span style="color:green#0a0;">; 2 cy + 100mS</span>
<span style="color:darkblue#17f;"> DECFSZ vWait3, f</span> <span style="color:green#0a0;">; 1 cy</span>
<span style="color:darkblue#17f;"> GOTO _T3</span> <span style="color:green#0a0;">; 2 cy</span>
<span style="color:darkblue#17f;"> RETURN</span> <span style="color:green#0a0;">; 2 cy</span>