Bouton poussoir sur PIC 16F690
Répondre à la discussion
Affichage des résultats 1 à 5 sur 5

Bouton poussoir sur PIC 16F690



  1. #1
    Tobi86

    Bouton poussoir sur PIC 16F690


    ------

    Bonjour à tous,
    Je suis en Terminal BAC PRO Systèmes Electroniques Et Numériques et je suis dans la Spé EIE (Electroniques Industrielles Embarquées).
    Je travaille actuellement sur le projet d'un "compte tours" avec Micro C pro for PIC. Avec un PIC 16F690.

    Je vous expose mon problème. sur ma plaque d’expérimentation qui contient 5 afficheurs à segments je dois afficher le nombre de fois ou le bouton poussoir a été enfoncé.
    Voici mon code acctuel :
    Code:
     //segments des afficheurs
     #define SegA 0xEF    //11101111       
     #define SegB 0xDF    //11011111
     #define SegC 0xEF    //11101111
     #define SegD 0xFD    //11111101
     #define SegE 0xFE    //11111110
     #define SegF 0xF7    //11110111
     #define SegG 0x7F    //01111111
     
     // les afficheurs
     #define AFF1 0xBF    //10111111
     #define AFF2 0x7F    //11110111
     #define AFF3 0xBF    //10111111
     #define AFF4 0xDF    //11011111
     #define AFF5 0xFB    //11111011
     
     // mon bouton poussoir
     #define press RA2    //Configure le port A sur la broche 2 le bouton poussoir
    
    
        unsigned int const tempo=50; //20ms
    
    void init(){
      ANSEL  = 0;            // Configure AN pins as digital
      ANSELH = 0;
     
      C1ON_bit = 0;          // Disable comparators
      C2ON_bit = 0;
    
      TRISA = 0x00;
      TRISB = 0x00;          // set direction to be output
      TRISC = 0x00;          // set direction to be output
    
    
      PORTB = 0xff;
      PORTC = 0xff;          // L'afficheur est totalement éteind
    
     /* INTCON = 0b10110000 ;
      OPTION_REG = 0b11010001;
      OSCCON = OSCCON | 0b01110000;      //Fréquence 8MHz  */
    
    }
    
    
    void aff_off(){
    PORTB = PORTB | 0b11111111;
    PORTC = PORTC | 0b11111111;
                               delay_ms(50);
    }
    
    void test_seg() {          //test de tous les segments de AFF1 à AFF5 temps par seg 50ms
    
     //AFF1
     aff_off();
     PORTC = PORTC & AFF1 & SegA;
     delay_ms(tempo);
     aff_off();
     PORTC = PORTC & AFF1 & SegB;
     delay_ms(tempo);
     aff_off();
     PORTC = PORTC & AFF1;
     PORTB = PORTB & SegC;
     delay_ms(tempo);
     aff_off();
     PORTC = PORTC & AFF1 & SegD;
     delay_ms(tempo);
     aff_off();
     PORTC = PORTC & AFF1 & SegE;
     delay_ms(tempo);
     aff_off();
     PORTC = PORTC & AFF1 & SegF;
     delay_ms(tempo);
      aff_off();
     PORTC = PORTC & AFF1;
     PORTB = PORTB & SegG;
     delay_ms(tempo);
     
     //AFF2
      aff_off();
     PORTC = PORTC & AFF2 & SegA;
     delay_ms(tempo);
     aff_off();
     PORTC = PORTC & AFF2 & SegB;
     delay_ms(tempo);
     aff_off();
     PORTC = PORTC & AFF2;
     PORTB = PORTB & SegC;
     delay_ms(tempo);
     aff_off();
     PORTC = PORTC & AFF2 & SegD;
     delay_ms(tempo);
     aff_off();
     PORTC = PORTC & AFF2 & SegE;
     delay_ms(tempo);
     aff_off();
     PORTC = PORTC & AFF2 & SegF;
     delay_ms(tempo);
      aff_off();
     PORTC = PORTC & AFF2;
     PORTB = PORTB & SegG;
     delay_ms(tempo);
     
     //AFF3
      aff_off();
     PORTC = PORTC & SegA;
     PORTB = PORTB & AFF3;
     delay_ms(tempo);
     aff_off();
     PORTC = PORTC & SegB;
     PORTB = PORTB & AFF3;
     delay_ms(tempo);
     aff_off();
     PORTB = PORTB & SegC & AFF3 ;
     delay_ms(tempo);
     aff_off();
     PORTC = PORTC & SegD;
     PORTB = PORTB & AFF3;
     delay_ms(tempo);
     aff_off();
     PORTC = PORTC & SegE;
     PORTB = PORTB & AFF3;
     delay_ms(tempo);
     aff_off();
     PORTC = PORTC & SegF;
     PORTB = PORTB & AFF3;
     delay_ms(tempo);
      aff_off();
     PORTB = PORTB & SegG & AFF3;
     delay_ms(tempo);
     
     //AFF4
      aff_off();
     PORTC = PORTC & SegA;
     PORTB = PORTB & AFF4;
     delay_ms(tempo);
     aff_off();
     PORTC = PORTC & SegB;
     PORTB = PORTB & AFF4;
     delay_ms(tempo);
     aff_off();
     PORTB = PORTB & SegC & AFF4;
     delay_ms(tempo);
     aff_off();
     PORTC = PORTC & SegD;
     PORTB = PORTB & AFF4;
     delay_ms(tempo);
     aff_off();
     PORTC = PORTC & SegE;
     PORTB = PORTB & AFF4;
     delay_ms(tempo);
     aff_off();
     PORTC = PORTC & SegF;
     PORTB = PORTB & AFF4;
     delay_ms(tempo);
      aff_off();
     PORTB = PORTB & SegG & AFF4;
     delay_ms(tempo);
     
     //AFF5
      aff_off();
     PORTC = PORTC & AFF5 & SegA;
     delay_ms(tempo);
     aff_off();
     PORTC = PORTC & AFF5 & SegB;
     delay_ms(tempo);
     aff_off();
     PORTC = PORTC & AFF5;
     PORTB = PORTB & SegC;
     delay_ms(tempo);
     aff_off();
     PORTC = PORTC & AFF5 & SegD;
     delay_ms(tempo);
     aff_off();
     PORTC = PORTC & AFF5 & SegE;
     delay_ms(tempo);
     aff_off();
     PORTC = PORTC & AFF5 & SegF;
     delay_ms(tempo);
      aff_off();
     PORTC = PORTC & AFF5;
     PORTB = PORTB & SegG;
     delay_ms(tempo);
     }
     
     void valid_test (){  //valide le test en faisant clignoter 4fois tous les afficheurs
     aff_off ();
     PORTC =PORTC & SegA & SegB & SegD & SegE & SegF & AFF1 & AFF2 & AFF5;
     PORTB = PORTB & SegC & SegG & AFF3 & AFF4;
     delay_ms(tempo);
     aff_off ();
     PORTC =PORTC & SegA & SegB & SegD & SegE & SegF & AFF1 & AFF2 & AFF5;
     PORTB = PORTB & SegC & SegG & AFF3 & AFF4;
     delay_ms(tempo);
     aff_off ();
     PORTC =PORTC & SegA & SegB & SegD & SegE & SegF & AFF1 & AFF2 & AFF5;
     PORTB = PORTB & SegC & SegG & AFF3 & AFF4;
     delay_ms(tempo);
     aff_off ();
     PORTC =PORTC & SegA & SegB & SegD & SegE & SegF & AFF1 & AFF2 & AFF5;
     PORTB = PORTB & SegC & SegG & AFF3 & AFF4;
     delay_ms(tempo);
     }
     
     void chif1 () {  // allume segs a,b,c sur l'afficheur 1
    PORTC = PORTC & SegB;
    PORTB = PORTB & SegC;
    PORTC = PORTC & AFF1;
                        delay_ms(500);
    }
    
    
     aff_off();
    
    
     void chif2 () {
    PORTC = PORTC & SegA & SegB & SegE & SegD;
    PORTB = PORTB & SegG;
    PORTC = PORTC & AFF1;
                         delay_ms(500);
    }
    
    void main() {
    init ();
    test_seg();
    valid_test ();
                while(1)   {
               chif1();
               aff_off();
               chif2 ();
               aff_off();
                            }
               }

    Le problème est que je sais pas comment m'y prendre pour plusieurs raisons :

    Je ne pas pas faire de "#designe" pour les chiffres de 1 à 9 puisque les segments des afficheurs ne sont pas tous sur les mêmes port (B et C)
    Comment pourrais-je faire ça ?

    Est-ce possible de faire ça : "#define press RA2 //Configure le port A2 le bouton poussoir"

    J'espère être assez claire...
    En espèrant que ca ne soit pas bloqué parce que c'est considéré comme une aide (même plus) d'exercice...

    Et je remercie d'avance les personnes qui m'aiderons

    Tobi86

    -----

  2. #2
    jojo150393

    Re : Bouton poussoir sur PIC 16F690

    bonjour!

    je n'est pas lu entièrement ton code car il est un peu long par contre j'ai repéré cette ligne qui pour moi ne sert à rien :
    Code:
    PORTB = PORTB | 0b11111111;
    PORTC = PORTC | 0b11111111;
    à remplacer par :
    Code:
    PORTB = 0xff;
    PORTC = 0xff;
    En effet 1 OU x = 1.

    Maintenant concernant ton problème, pourrait tu être un peu plus clair car je ne discerne pas vraiment ton problème.
    Dernière modification par jojo150393 ; 24/10/2012 à 19h45.

  3. #3
    invite03481543

    Re : Bouton poussoir sur PIC 16F690

    Bonsoir,

    il vous faut definir pour chaque chiffre le code a envoyer pour chaque afficheur, selon le mode que vous avez choisi (multiplexage ou statique), puis faire une routine de conversion qui permettra d'afficher le chiffre appele.

    exemple:

    codage chiffres pour cathode commune:

    Code:
    unsigned short mask(unsigned short num) {
      switch (num) {
        case 0 : return 0x3F;                                
        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;
      }
    }

  4. #4
    Tobi86

    Re : Bouton poussoir sur PIC 16F690

    Tout d’abord merci de prendre de votre temps pour mon problème !


    Merci pour le petit conseil concernant aff_off.

    Donc mon problème est que je ne vois pas comment coder cette action :

    Si j'appuie sur le bouton alors mon chiffre passe au suivant (ex: j'appuie sur le bouton étant a 1 je passe a 2.)

    et si je suis à 9 sur AFF1 alors je passe à 10
    (10 = 1-> sur AFF2 et 0-> AFF1)

    Voyez-vous ?

  5. A voir en vidéo sur Futura
  6. #5
    Tobi86

    Re : Bouton poussoir sur PIC 16F690

    HULK28 merci de votre réponse.


    Mais cela pauserais problème des différents segments ?

    Par manque de temps je ne pourrais pas m'amuser à faire chiffre par chiffre et afficheurs par afficheurs ...

Discussions similaires

  1. pic + bouton poussoir ne fonctionne pas !!!
    Par little01 dans le forum Électronique
    Réponses: 26
    Dernier message: 13/07/2012, 10h55
  2. Branchement bouton poussoir à un pic
    Par invitef408b661 dans le forum Électronique
    Réponses: 3
    Dernier message: 14/03/2011, 15h40
  3. [C/PIC] - Gestion bouton poussoir
    Par jorg1n dans le forum Électronique
    Réponses: 6
    Dernier message: 29/04/2009, 07h07
  4. Solution bouton poussoir et PIC
    Par Olfox dans le forum Électronique
    Réponses: 7
    Dernier message: 04/03/2009, 10h49
  5. Pic 12F675 et bouton poussoir
    Par invite92bb58f7 dans le forum Électronique
    Réponses: 8
    Dernier message: 18/04/2008, 16h47
Découvrez nos comparatifs produits sur l'informatique et les technologies.