Fonction Traiter – PIC 16F84 Sciences d’Ingénieur – 2ème BAC STE

Fonction Traiter – PIC 16F84 Sciences d’Ingénieur – 2ème BAC STE

Fonction Traiter – PIC 16F84
Sciences d’Ingénieur – 2ème BAC STE

Introduction

Le PIC 16F84 est un microcontrôleur RISC de 8 bits fabriqué par Microchip. Il est largement utilisé pour le traitement de données dans les systèmes embarqués grâce à sa simplicité et sa polyvalence.

PIC 16F84 18 broches 1,75KB Flash, 68B RAM

1. Architecture du PIC 16F84

1.1 Structure interne

Unité centrale

  • ALU (Unité Arithmétique et Logique)
  • Registre W (accumulateur)
  • Compteur programme (PC)

Mémoire

  • 1K x 14 mots Flash (programme)
  • 68 octets RAM (données)
  • 64 octets EEPROM

1.2 Brochage

Broche Fonction Description
RA0-RA4 Port A Entrées/Sorties digitales
RB0-RB7 Port B Entrées/Sorties (RB0 interruption)
MCLR Reset Remise à zéro (actif bas)

2. Programmation en assembleur

2.1 Structure d’un programme

LIST p=16F84
INCLUDE “P16F84.INC”

; Configuration bits
__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC

; Déclaration variables
CBLOCK 0x0C
  compteur
ENDC

ORG 0x000
  GOTO main

ORG 0x004
  RETFIE ; Routine d’interruption

main
  BSF STATUS, RP0 ; Bank1
  MOVLW b’00000000′
  MOVWF TRISB ; Port B en sortie
  BCF STATUS, RP0 ; Bank0

boucle
  MOVLW 0xFF
  MOVWF PORTB
  CALL delai
  GOTO boucle
END

2.2 Instructions principales

Transfert

  • MOVLW k → W = k
  • MOVWF f → f = W
  • MOVF f,d → d = f

Logiques/Arithmétiques

  • ADDWF f,d → d = f + W
  • ANDLW k → W = W AND k
  • DECF f,d → d = f – 1

3. Gestion des entrées/sorties

3.1 Configuration des ports

BSF STATUS, RP0 ; Sélection Bank1
MOVLW b’00001111′ ; RA0-RA3 en entrée, RA4 en sortie
MOVWF TRISA
MOVLW b’00000000′ ; RB tous en sortie
MOVWF TRISB
BCF STATUS, RP0 ; Retour Bank0

3.2 Lecture/Écriture

PIC 16F84 Capteur RA0 LED RB0 BTFSS PORTA,0 BSF PORTB,0

4. Timers et interruptions

4.1 Timer0

Configuration

  • Source horloge interne/externe
  • Prédiviseur programmable
  • Incrémente à chaque cycle

Registres associés

  • OPTION_REG
  • TMR0
  • INTCON

4.2 Gestion des interruptions

ORG 0x000
  GOTO main
ORG 0x004
  BTFSS INTCON, T0IF
  RETFIE
  BCF INTCON, T0IF
  RETFIE

main
  BSF INTCON, GIE ; Active interruptions globales
  BSF INTCON, T0IE ; Active interruption Timer0

Exercice d’application

On souhaite réaliser un système avec PIC 16F84 qui :

1. Fait clignoter une LED sur RB0 toutes les secondes

2. Active une alarme sur RB7 quand RA0 passe à l’état haut

3. Utilise le Timer0 pour générer le délai


Comments

No comments yet. Why don’t you start the discussion?

اترك تعليقاً

لن يتم نشر عنوان بريدك الإلكتروني. الحقول الإلزامية مشار إليها بـ *