program Afficheur_002; var Lecture : Word; ResultLecture : Byte; AffichageUnite : Byte; AffichageDizaine : 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) 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 // Lecture après la virgule correspond à l'unité delay_ms(1000); // J'attend 1 sec avant d'éteindre Q1 et d'allumer Q2 PORTA.RA1 := 1; // Q1 allumé PORTA.RA2 := 0; // Q2 éteint ResultLecture := (Lecture * 5) / 1023; AffichageUnite := (ResultLecture MOD 10) ; // on récupère le chiffre apres la virgule AffichageSegmentsUnite(AffichageUnite); // Lecture avant la virgule correspond au dizaine delay_ms(1000); // J'attend 1 sec avant d'allumer Q1 et d'eteindre Q2 PORTA.RA1 := 0; // Q1 éteint PORTA.RA2 := 1; // Q2 allumé AffichageDizaine := ResultLecture / 10; AffichageSegmentsDizaine(AffichageDizaine); // On récupère le chiffre avant la virgule end; end; begin init(); while true do begin Lecture_RV1(); // Lecture en boucle du potentiomètre RV1 end; end.