program Afficheur_002; var Lecture : Word; ResultLecture : Byte; AffichageUnite : Byte; AffichageDizaine : Byte; Ra1orRa2 : Byte; procedure init(); begin TRISA := %11000001; // Configuration de la broche RA0 comme entrée PORTA := %00000000; // On met toutes les sorties du PORTA à "0" TRISB := %00000000; // Configuration du PORTB comme sortie PORTB := %00000000; // On met toutes les sorties du PORTB à "0" ANSEL := %00000001; // Configuration de l'entrée RA0 en analogique ADC_Init(); // Initialisation du convertisseur Analogique /numérique (A/N) OPTION_REG := $00; INTCON.GIE := 1; // On active les interruptions générales PS0_bit := 0; //| PS1_bit := 1; //| Prescaler réglé sur 1:64 PS2_bit := 1; //| TMR0IE_bit := 1; // On active les interruptions du Timer0 TMR0IF_bit := 0; // Le drapeau de débordement est à zéro RA1orRA2 := 0; // Permet d'activer soir soit Q1 soit Q2 TMR0 := 0; // On initialise le Compteur du Timer0 à zéro! end; procedure interrupt(); begin if ((TMR0IF_bit = 1) and (RA1orRA2 = 0)) then begin RA1orRA2 := 1; TMR0IF_bit := 0; end; if ((TMR0IF_bit = 1) and (RA1orRA2 = 1)) then begin RA1orRA2 := 0; TMR0IF_bit := 0; end; end; procedure AffichageSegmentsUnite(ValeursUnite : Byte); begin case (ValeursUnite) of 0 : PORTB := %01000000; 1 : PORTB := %01111001; 2 : PORTB := %00100100; 3 : PORTB := %00110000; 4 : PORTB := %00011001; 5 : PORTB := %00010010; 6 : PORTB := %00000010; 7 : PORTB := %01111000; 8 : PORTB := %00000000; 9 : PORTB := %00010000; end; end; procedure AffichageSegmentsDizaine(ValeursDizaine : Byte); begin case (ValeursDizaine) of 0 : PORTB := %01000000; 1 : PORTB := %01111001; 2 : PORTB := %00100100; 3 : PORTB := %00110000; 4 : PORTB := %00011001; 5 : PORTB := %00010010; 6 : PORTB := %00000010; 7 : PORTB := %01111000; 8 : PORTB := %00000000; 9 : PORTB := %00010000; end; end; procedure Lecture_RV1(); begin Lecture := ADC_Read(0) * 10; // (*10) pour récupérer 1 chiffre après virgule begin if (RA1orRA2 = 1) then begin // Lecture après la virgule correspond à l'unité PORTA.RA1 := 1; ResultLecture := (Lecture * 5) / 1023; AffichageUnite := (ResultLecture MOD 10) ; // on récupère le chiffre apres la virgule AffichageSegmentsUnite(AffichageUnite); PORTA.RA1 := 0; end; if (RA1orRA2 = 0) then begin // Lecture avant la virgule correspond au dizaine PORTA.RA2 := 1; AffichageDizaine := ResultLecture / 10; AffichageSegmentsDizaine(AffichageDizaine); // On récupère le chiffre avant la virgule PORTA.RA2 := 0; end; end; end; begin init(); while true do begin Lecture_RV1(); // Lecture en boucle du potentiomètre RV1 end; end.