unsigned int Lecture; unsigned int ResultLecture; unsigned int AffichageUnite; unsigned int AffichageDizaine; void init() { TRISA = 0b11000001; // Configuration de la broche RA0 comme entrée PORTA = 0b00000000; // On met toutes les sorties du PORTA à "0" TRISB = 0b00000000; // Configuration du PORTB comme sortie PORTB = 0b00000000; // On met toutes les sorties du PORTB à "0" ANSEL = 0b00000001; // Configuration de l'entrée RA0 en analogique ADC_Init(); // Initialisation du convertisseur Analogique /numérique (A/N) } void AffichageSegmentsUnite(int ValeursUnite) { switch (ValeursUnite) { case 0 : PORTB = 0b01000000; break; case 1 : PORTB = 0b01111001; break; case 2 : PORTB = 0b00100100; break; case 3 : PORTB = 0b00110000; break; case 4 : PORTB = 0b00011001; break; case 5 : PORTB = 0b00010010; break; case 6 : PORTB = 0b00000010; break; case 7 : PORTB = 0b01111000; break; case 8 : PORTB = 0b00000000; break; case 9 : PORTB = 0b00010000; break; } } void AffichageSegmentsDizaine(int ValeursDizaine) { switch (ValeursDizaine) { case 0 : PORTB = 0b01000000; break; case 1 : PORTB = 0b01111001; break; case 2 : PORTB = 0b00100100; break; case 3 : PORTB = 0b00110000; break; case 4 : PORTB = 0b00011001; break; case 5 : PORTB = 0b00010010; break; case 6 : PORTB = 0b00000010; break; case 7 : PORTB = 0b01111000; break; case 8 : PORTB = 0b00000000; break; case 9 : PORTB = 0b00010000; break; } } void Lecture_RV1() { Lecture = ADC_Read(0) * 10; // (*10) pour récupérer 1 chiffre après virgule { // 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 % 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 } } void main() { init(); while (1) { Lecture_RV1(); // Lecture en boucle du potentiomètre RV1 } }