Sunteți pe pagina 1din 21

BachelierInformatique&Systme 2013

Christophe********

IEPSCF U CCLE

MICROCONTROLEURLABO2

Professeur:Najdi

BachelierInformatique&Systme 2013

Tabledesmatires
Introduction......................................................................................................... 2

Prsentationduprojet......................................................................................... 2

Quelestl'ulititdumultiplexage:....................................................................... 9

LeschmaProteus:............................................................................................. 9

PremierProgramme:.........................................................................................10

SecondProgramme:..........................................................................................13

Troisimeprogramme:......................................................................................15

Conclusion:........................................................................................................20

Professeur:Najdi

P a g e |1

BachelierInformatique&Systme 2013

Introduction
Le multiplexage consiste utiliser les mmes lignes pour alimenter plusieurs afficheurs et les faire fonctionner alternativement. Ceci est rpt pour les afficheurs et ralis de faon suffisamment rapide pour viter de voir des clignotements. On souhaite piloter un afficheur sept segments constitue de LED. Pour piloter un tel afficheur on utilise un dcodeur directement intgr l'afficheur, il est compos de 4 entres : les 4 bits ici 1 2 3 4 ncessaires pour coder les chiffres 0 9, et 7 sorties a, b, c, d, e, f, g. Grace au programme crit en langage C, on pourra afficher le compteur sur chaque afficheur en changeant les valeurs attribues au PORTA. L'ajout de 3 boutons poussoirs connects au PORTB serviront remettre 0, incrmenter de 1 et dcrmenter de 1 selon le bouton sur lequel on appuie.

Prsentation du projet
Multiplexage afficheurs sept segments L'objectif est d'afficher un compteur sur AFF3 AFF2 AFF1 AFF0 AFF3 AFF2 AFF1 AFF0

8
PORTA RA0 20 = 1

8
PORTA RA1 21 = 2

8
PORTA RA2 22 = 4

8
PORTA RA3 23 = 8

Chiffre de 4 caractres. Vous trouvez le premier programme exploitant les afficheurs dans le dossier : C:\Program Files \Mikroelektronika\mikroC\Examples\EasyPic5\P16F877A\7segdisplay1 Display_utils.c //-------------- Returns mask for common cathode 7-seg. display unsigned short mask(unsigned short num) { switch (num) { case 0 : return 0x3F;
Professeur:Najdi P a g e |2

BachelierInformatique&Systme 2013

case 1 : return 0x06; case 2 : return 0x5B; case 3 : return 0x4F; case 4 : return 0x66; case 5 : return 0x6D; case 6 : return 0x7D; case 7 : return 0x07; case 8 : return 0x7F; case 9 : return 0x6F; } //case end }//~ Display_1.C /* * Project name: Display_1 (The 'Hello World' example for the 7Seg. display) * Copyright: (c) MikroElektronika, 2005-2008. * Description: This code demonstrates how to display number on one 7-segment display (common cathode). Display is connected to PORTD (RD0..RD7, segment A to RD0, segment B to RD1, etc); common cathode is connected to the pin RA0 on PORTA. Number is incremented every 1s. * Test configuration: MCU: P16F877A Dev.Board: EasyPIC5 Oscillator: HS, 08.0000 MHz Ext. Modules: SW: mikroC v8.0 * NOTES: None. */ #include "Display_utils.h" unsigned short i; void main() { INTCON = 0; // Disable GIE, PEIE,INTE,RBIE,T0IE PORTA = 0; TRISA = 0; PORTD = 0; TRISD = 0; do { for (i = 0; i <= 9u; i++) { PORTA = 0; // Turn off all 7seg displays PORTD = mask(i); // bring appropriate value to PORTD PORTA = 1; // turn on appropriate 7seg. display
Professeur:Najdi P a g e |3

BachelierInformatique&Systme 2013

Delay_ms(1000); } } while (1); }

//endless loop

Compltez et excutez le programme. Que fait ce programme ? Modifiez le pour afficher le compteur sur AFF1 puis sur AFF2 et puis sur AFF3 Quel est l'utilit du multiplexage ?

Matriel pour Proteus

PIC 16F877a

7seg MPx4-CA

Professeur:Najdi

P a g e |4

BachelierInformatique&Systme 2013

MINRES 10K

Vous trouverez le deuxime programme exploitant les afficheurs dans la dossier C:\Program Files \Mikroelektronika\mikroC\Examples\EasyPic5\P16F877A\7segdisplay2

Display7seg_02.c : /* * Project name: Display7Seg_02 (Usage of 2 7Seg. displays) * Copyright: (c) MikroElektronika, 2005-2008. * Description: This code demonstrates displaying numbers (0,1,2..99) on two 7-segment displays. Each digit is on for 1 second. * Test configuration: MCU: PIC16F877A Dev.Board: EasyPIC5 Oscillator: HS, 08.0000 MHz Ext. Modules: SW: mikroC v8.0 */ #include "Display_utils.h" unsigned short digit_no, digit10, digit1, digit, i; void interrupt() { if (digit_no==0) { PORTA = 0; // Turn off all 7seg displays PORTD = digit1; // send mask for ones digit to PORTD PORTA = 1; // turn on 1st 7 seg., turn off 2nd digit_no = 1; } else { PORTA = 0; // Turn off all 7seg displays PORTD = digit10; // send mask for tens digit to PORTD PORTA = 2; // turn on 2nd 7 seg., turn off 1st digit_no = 0; }
Professeur:Najdi P a g e |5

BachelierInformatique&Systme 2013

TMR0 = 0; // clear TMRO INTCON = 0x20; // clear TMR0IF and set TMR0IE } void main() { OPTION_REG = 0x80; // Timer0 settings TMR0 = 0; INTCON = 0xA0; // Disable PEIE,INTE,RBIE,T0IE PORTA = 0; // clear PORTA (make sure both displays are off) TRISA = 0; // designate PORTA pins as output PORTD = 0; // clear PORTD (make sure LEDs are off) TRISD = 0; // designate PORTD pins as output do { for (i = 0; i<=99; i++) { // count from 0 to 99 digit = i % 10u; digit1 = mask(digit); // prepare ones digit digit = (char)(i / 10u) % 10u; digit10 = mask(digit); // prepare tens digit Delay_ms(1000); } } while (1); // endless loop }

Professeur:Najdi

P a g e |6

BachelierInformatique&Systme 2013

Vous trouverez le troisime programme exploitant les afficheurs dans la dossier C:\Program Files \Mikroelektronika\mikroC\Examples\EasyPic5\P16F877A\7segdisplay3

Display7seg_03.c : unsigned short shifter, portd_index; unsigned int digit, number; unsigned short portd_array[4]; void interrupt() { PORTA = 0; // Turn off all 7seg displays PORTD = portd_array[portd_index]; // bring appropriate value to PORTD PORTA = shifter; // turn on appropriate 7seg. display // move shifter to next digit shifter <<= 1; if (shifter > 8u) shifter = 1; // increment portd_index portd_index++ ; if (portd_index > 3u) portd_index = 0; TMR0 = 0; INTCON = 0x20; }//~ void main() { ADCON1 = 0x07; CMCON = 7; OPTION_REG = 0x80; digit = 0; portd_index = 0; shifter = 1; TMR0 = 0; INTCON = 0xA0; PORTA = 0; TRISA = 0; PORTD = 0; TRISD = 0; number = 6789;

// turn on 1st, turn off 2nd 7seg. // reset TIMER0 value // Clear TMR0IF

// Set AN pins to Digital I/O // Turn off comparators // Timer0 settings

// Enable GIE, TMR0IE // Set PORTA as output // Set PORTD as output // some initial value
P a g e |7

Professeur:Najdi

BachelierInformatique&Systme 2013

do { digit = number / 1000u ; // extract thousands digit portd_array[3] = mask(digit); // and store it to PORTD array digit = (number / 100u) % 10u; // extract hundreds digit portd_array[2] = mask(digit); // and store it to PORTD array digit = (number / 10u) % 10u; // extract tens digit portd_array[1] = mask(digit); // and store it to PORTD array digit = number % 10u; // extract ones digit portd_array[0] = mask(digit); // and store it to PORTD array Delay_ms(1000); number++ ; if (number > 9999u) number = 0; } while(1); // one second delay // increment number

// endless loop

} Ajouter des boutons RB0 RB1 RB2 RB0 --> tat 0000 BT1 pour remettre zro RB1 --> tat + 1 BT2 pour incrmenter de 1 RB2 --> tat - 1 BT3 pour dcrmenter de 1 Modifiez le troisime programme afin que les boutons poussoirs fonctionnent


Professeur:Najdi P a g e |8

BachelierInformatique&Systme 2013

Quel est l'ulitit du multiplexage :


Le multiplexage est une technique qui consiste faire passer deux ou plusieurs informations travers un seul support de transmission

Le schma Proteus :


Professeur:Najdi P a g e |9

BachelierInformatique&Systme 2013

Premier Programme :
Nous devons tout d'abord modifier le fichier Display_utils.c pour que l'affichage se fassent correctement de 0 9 case 0 : return 0x3F; aprs conversion case 1 : return 0x06; aprs conversion case 2 : return 0x5B; aprs conversion case 3 : return 0x4F; aprs conversion case 4 : return 0x66; aprs conversion case 5 : return 0x6D; aprs conversion case 6 : return 0x7D; aprs conversion case 7 : return 0x07; aprs conversion case 8 : return 0x7F; aprs conversion case 9 : return 0x6F; aprs conversion 0 | 011 1111 soit 3 et F comme nous sommes en 7 bits 0 | 100 0000 devient 4 et 0 0 | 000 0110 soit 0 et 6 0 | 111 1001 soit 7 et 9 0 | 101 1011 soit 5 et B 0 | 010 0100 soit 2 et 4 0 | 100 1111 soit 4 et F 0 | 011 0000 soit 3 et 0 0 | 110 0110 soit 6 et 6 0 | 001 1001 soit 1 et 9 0 | 110 1101 soit 6 et D 0 | 001 0010 soit 1 et 2 0 | 111 1101 soit 7 et D 0 | 000 0010 soit 0 et 2 0 | 000 0111 soit 0 et 7 0 | 111 1000 soit 7 et 8 0 | 111 1111 soit 7 et F 0 | 000 0000 soit 0 et 0 0 | 110 1111 soit 6 et F 0 | 001 0000 soit 1 et 0

Et nous devons modifier le PORTA dans le programme en C pour qu'il affiche sur AFF1 ensuite sur AFF2 et sur AFF3

Professeur:Najdi

P a g e |10

BachelierInformatique&Systme 2013

PORTA = 4 // Affichage en AFF1

PORTA = 2 // Affichage en AFF2

PORTA = 1 // Affichage en AFF3

Le code : // Header File for <Display_utils.c> unsigned short mask(unsigned short num); //-------------- Returns mask for common cathode 7-seg. display unsigned short mask(unsigned short num) { switch (num) { case 0 : return 0x40; case 1 : return 0x79; case 2 : return 0x24; case 3 : return 0x30; case 4 : return 0x19; case 5 : return 0x12; case 6 : return 0x02; case 7 : return 0x78;
Professeur:Najdi P a g e |11

BachelierInformatique&Systme 2013

case 8 : return 0x00; case 9 : return 0x10; } //case end }//~ /* * Project name: Display_1 (The 'Hello World' example for the 7Seg. display) * Copyright: (c) MikroElektronika, 2005-2008. * Description: This code demonstrates how to display number on one 7-segment display (common cathode). Display is connected to PORTD (RD0..RD7, segment A to RD0, segment B to RD1, etc); common cathode is connected to the pin RA0 on PORTA. Number is incremented every 1s. * Test configuration: MCU: P16F877A Dev.Board: EasyPIC5 Oscillator: HS, 08.0000 MHz Ext. Modules: SW: mikroC v8.0 * NOTES: None. */ //#include "Display_utils.h" unsigned short i; void main() { INTCON = 0; // Disable GIE, PEIE,INTE,RBIE,T0IE PORTA = 0; TRISA = 0; PORTD = 0; TRISD = 0; do { for (i = 0; i <= 9u; i++) { PORTA = 0; // Turn off all 7seg displays PORTD = mask(i); // bring appropriate value to PORTD PORTA = 4; // turn on appropriate 7seg. display // Soit 1 pour AAF3 2 pour AFF2 // 4 pour AFF1 et 8 pour AFF0
Professeur:Najdi P a g e |12

BachelierInformatique&Systme 2013

Delay_ms(100); } } while (1); }

//endless loop

Second Programme :
Le programme permet d'afficher le PORTA en AFF0 et AFF1 de 00 99 en s'incrment de 1 chaque tour. Nous devons modifier les deux PORTA afin que l'affichage soit correct. Soit PORTA = 8 pour les units AFF0 Soit PORTA = 4 pour les dizaines AFF1

Le code :

unsigned short mask(unsigned short num); //-------------- Returns mask for common cathode 7-seg. display unsigned short mask(unsigned short num) { switch (num) { case 0 : return 0x40; case 1 : return 0x79; case 2 : return 0x24; case 3 : return 0x30; case 4 : return 0x19; case 5 : return 0x12; case 6 : return 0x02; case 7 : return 0x78; case 8 : return 0x00; case 9 : return 0x10; } //case end }//~ /* * Project name:
Professeur:Najdi P a g e |13

BachelierInformatique&Systme 2013

Display7Seg_02 (Usage of 2 7Seg. displays) * Copyright: (c) Mikroelektronika, 2005-2008. * Description: This code demonstrates displaying numbers (0,1,2..99) on two 7-segment displays. Each digit is on for 1 second. * Test configuration: MCU: PIC16F877A Dev.Board: EasyPIC4 Oscillator: HS, 08.0000 MHz Ext. Modules: SW: mikroC v8.0.0.0 */

unsigned short digit_no, digit10, digit1, digit, i; void interrupt() { if (digit_no==0) { PORTA = 0; // Turn off all 7seg displays PORTD = digit1; // send mask for ones digit to PORTD PORTA = 8; // turn on 1st 7 seg., turn off 2nd AFF0 digit_no = 1; } else { PORTA = 0; // Turn off all 7seg displays PORTD = digit10; // send mask for tens digit to PORTD PORTA = 4; // turn on 2nd 7 seg., turn off 1st AFF1 digit_no = 0; } TMR0 = 0; // clear TMRO INTCON = 0x20; // clear TMR0IF and set TMR0IE } void main() { OPTION_REG = 0x80; // Timer0 settings TMR0 = 0; // clear TMRO INTCON = 0xA0; // Disable PEIE,INTE,RBIE,T0IE PORTA = 0; // clear PORTA (make sure both displays are off) TRISA = 0; // designate PORTA pins as output PORTD = 0; // clear PORTD (make sure LEDs are off) TRISD = 0; // designate PORTD pins as output do {
Professeur:Najdi P a g e |14

BachelierInformatique&Systme 2013

for (i = 0; i<=99; i++) { // count from 0 to 99 digit = i % 10u; digit1 = mask(digit); // prepare ones digit digit = (char)(i / 10u) % 10u; digit10 = mask(digit); // prepare tens digit Delay_ms(100); } } while (1); // endless loop }

Troisime programme :

Nousajoutons3boutonsafinquechaqueboutonpoussoirpuissentavoiruneactiondiffrentesur l'afficheur.

Professeur:Najdi

P a g e |15

BachelierInformatique&Systme 2013
Afficheurtatd'origine=6972

BT1connectenRB0remetl'afficheurl'tatzro (Button(&PORTB,0,1,1))oldstate=1; BoutonConnectauPORTBenRB0(0),timerde1,tatactif1(sortiedebouton),ancientat=1

BT2connectenRB1remetl'afficheurl'tat+1(incrmentation) (Button(&PORTB,1,1,1))oldstate=1; BoutonConnectauPORTBenRB1(1),timerde1,tatactif1(sortiedebouton),ancientat=1

BT3connectenRB2remetl'afficheurl'tat1(dcrementation) (Button(&PORTB,2,1,1))oldstate=1; BoutonConnectauPORTBenRB2(2),timerde1,tatactif1(soritedebouton),ancientat=1

Professeur:Najdi P a g e |16

BachelierInformatique&Systme 2013

unsigned short Button(unsigned short *port, unsigned short pin, unsigned short time, unsigned short active_state); short *port port de paramtre short pin nombre de la broche short time paramtre de temps en milli seconde short active_state dtermine si la touche est active sur une logique de 0 et 1
Code: unsignedshortmask(unsignedshortnum); unsignedshortmask(unsignedshortnum){ switch(num){ case0:return0x40; case1:return0x79; case2:return0x24; case3:return0x30; case4:return0x19; case5:return0x12; case6:return0x02; case7:return0x78; case8:return0x00; case9:return0x10; }//caseend }//~ /* *Projectname: Display7seg(Advanced7Seg.displayexample) *Copyright: (c)Mikroelektronika,20052008. *Description: Thiscodedemonstratesdisplayingnumberonfour7segmentdisplay(common cathode),inmultiplexmode.All7segmentdisplaysareconnectedtoPORTD (RD0..RD7,segmentAtoRD0,segmentBtoRD1,etc)withrefreshviapins RA0..RA3onPORTA.Numberincrementseverysecond. *Testconfiguration: MCU:PIC16F877A Dev.Board:EasyPIC4 Oscillator:HS,08.0000MHz Ext.Modules: SW:mikroCv8.0.0.0 *NOTES: Professeur:Najdi P a g e |17

BachelierInformatique&Systme 2013
*/ //include"Display_utils.h" unsignedshortshifter,portd_index; unsignedintdigit,number,oldstate; unsignedshortportd_array[4]; unsignedshortButton(unsignedshortportb,unsignedshortpin,unsignedshorttime,unsignedshort active_state); // Initialisation des bouton sur le PORTB correspondant une broche prcise avec un tempsallouetsontatd'actif voidinterrupt(){ PORTA=0;//Turnoffall7segdisplays PORTD=portd_array[portd_index];//bringappropriatevaluetoPORTD PORTA=shifter;//turnonappropriate7seg.display //moveshiftertonextdigit shifter<<=1; if(shifter>8u) shifter=1; //incrementportd_index portd_index++; if(portd_index>3u) portd_index=0;//turnon1st,turnoff2nd7seg. TMR0=0;//resetTIMER0value INTCON=0x20;//ClearTMR0IF }//~ voidmain(){ ADCON1=0x07;//SetANpinstoDigitalI/O CMCON=7;//Turnoffcomparators OPTION_REG=0x80;//Timer0settings digit=0; portd_index=0; shifter=1; TMR0=0; INTCON=0xA0;//EnableGIE,TMR0IE PORTA=0; TRISA=0;//SetPORTAasoutput PORTD=0; TRISD=0;//SetPORTDasoutput Professeur:Najdi P a g e |18

BachelierInformatique&Systme 2013
number=6972;//someinitialvalue do{ digit=number/1000u;//extractthousandsdigit portd_array[0]=mask(digit);//andstoreittoPORTDarray digit=(number/100u)%10u;//extracthundredsdigit portd_array[1]=mask(digit);//andstoreittoPORTDarray digit=(number/10u)%10u;//extracttensdigit portd_array[2]=mask(digit);//andstoreittoPORTDarray digit=number%10u;//extractonesdigit portd_array[3]=mask(digit);//andstoreittoPORTDarray Delay_ms(100);//oneseconddelay if(Button(&PORTB,0,1,1))oldstate=1;//BT1surRB0actifremetlecompteurzroPORTB if(oldstate&&Button(&PORTB,0,1,0)) { number=0;//reset oldstate=0; } if(Button(&PORTB,1,1,1))oldstate=1;//BT2surRB1actifpermetd'incrmenterde1PORTB if(oldstate&&Button(&PORTB,1,1,0)) { number++;//incrmentation oldstate=0; } if(Button(&PORTB,2,1,1))oldstate=1;//BT3surRB2actifpermetdedcrmenterde1PORTB if(oldstate&&Button(&PORTB,2,1,0)) { number;//dcrmentation oldstate=0; } }while(1); }

Professeur:Najdi

P a g e |19

BachelierInformatique&Systme 2013

Conclusion :
Le multiplexage est un procd simple utilis pour limiter la consommation totale en nergie et le nombre de fils de manire efficace car il n'y a en ralit qu'un afficheur qui est allum chaque fois donc on privilgiera un afficheur LCD au lieu des afficheurs 7segments.

Professeur:Najdi

P a g e |20

S-ar putea să vă placă și