unsigned int Lecture; unsigned int ResultLecture; unsigned int AffichageUnite; unsigned int AffichageDizaine; bit RA1orRA2; 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) OPTION_REG = 0x00; 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! } void interrupt() { if ((TMR0IF_bit == 1) && (RA1orRA2 == 0)) { RA1orRA2 = 1; TMR0IF_bit = 0; } if ((TMR0IF_bit == 1) && (RA1orRA2 == 1)) { RA1orRA2 = 0; TMR0IF_bit = 0; } } 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 { if (RA1orRA2 == 1) { // Lecture après la virgule correspond à l'unité PORTA.RA1 = 1; ResultLecture = (Lecture * 5) / 1023; AffichageUnite = (ResultLecture % 10) ; // on récupère le chiffre apres la virgule AffichageSegmentsUnite(AffichageUnite); PORTA.RA1 = 0; } if (RA1orRA2 == 0) { // 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; } } } void main() { init(); while (1) { Lecture_RV1(); // Lecture en boucle du potentiomètre RV1 } }