IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C Discussion :

Fonction "OpenRB0INT" sous C18 compiler


Sujet :

C

  1. #1
    Membre à l'essai
    Inscrit en
    Novembre 2007
    Messages
    32
    Détails du profil
    Informations forums :
    Inscription : Novembre 2007
    Messages : 32
    Points : 15
    Points
    15
    Par défaut Fonction "OpenRB0INT" sous C18 compiler
    Bonjour,
    je souhaite tout d'abord réaliser un truc tout simple , suite à un appui sur un BP brancher sur RB0, cela génère une interruption, et ensuite cela allume une LED sur RA0. Et après un autre appui sur le BP, cela l'éteint et ainsi de suite...

    Je pensai réaliser cela avec la fonction OpenRB0INT de la librairie PORTB du compiler C18, et j'arrive a cela..:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    //fichier de declaration des registres internes du microcontroleur
    #include <p18f4682.h>
    #include <portb.h>    /* for the RB0/INT0 interrupt */
     
    //Déclaration des PORTXbits.RXX utilisés
    #define LED_ON PORTAbits.RA0
     
    //Configuration Bits
    #pragma config OSC = XT			//Config du type de l'oscillateur
     
    //Sous programmes
    void init_uc(void);
    void EnableHighInterrupts (void);
    void LED (void);
    void initializeLED(void);
    //Déclarations des variables
     
     
    /***************************************************************************
    *********************Programme Principal************************************
    ***************************************************************************/
    void main (void)
    {
    init_uc();				//Appel SP Initialisation du microcontroleu
    EnableHighInterrupts ( );
    initializeLED();
     
    OpenRB0INT (PORTB_CHANGE_INT_ON & /* enable the RB0/INT0 interrupt */
                  PORTB_PULLUPS_ON &    /* configure the RB0 pin for input */
                  FALLING_EDGE_INT);    /* trigger interrupt upon S3 button
                                           depression */
    LED ();
    }//Fin Programme Principal
     
     
     
     
     
    /***************************************************************************
    Nom   : void init_uc(void)
    Role  : Configuration et initialisation des Ports E/S
    ----------------------------------------------------------------------------
    Contraintes           : Aucune
    Donnees en entree     : Aucune
    Donnees en sortie     : Aucune
    Donnees glob. modif.  : Aucune
    *****************************************************************************/
    void init_uc(void)
    {
     TRISA=0x00;					// PORTA en sortie
     TRISB=0x0F;					// RB7-RB4 en sortie RB3-RB0 en entrée
     TRISC=0x1F;					// RC7-RC5 en sortie RC4-RC0 en entrée
     TRISD=0x4F;					// PORTD en sortie sauf RD7 RD5 RD4
     TRISE=0x00;					// PORTE en sortie
     
     PORTA=0x00;
     PORTB=0x00;
     PORTC=0x00;
     PORTD=0x00; 
     PORTE=0x00;
     
     ADCON1=0b00001111;				//Configuration du portA en numérique
    }
     
     
    void EnableHighInterrupts (void)
    {
      RCONbits.IPEN = 1;         /* enable interrupt priority levels */
      INTCONbits.GIEH = 1;       /* enable all high priority interrupts */
    }
     
     
    void LED (void)
    {
      LED_ON = 1;            /* turn the buzzer on */
      while (1);                 /* wait for the S3 button to be pressed */
    }
     
    void initializeLED(void)
    {
    if(LED_ON==0)LED_ON=1;
    if(LED_ON==1)LED_ON=0;
    INTCONbits.INT0IF = 0;     /* clear flag to avoid another interrupt */
    }
    Qu"en pensez vous..
    je vous remercie d'avance
    Nicolas

  2. #2
    Membre du Club
    Profil pro
    Inscrit en
    Novembre 2006
    Messages
    52
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 52
    Points : 62
    Points
    62
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    if(LED_ON==0)LED_ON=1;
    if(LED_ON==1)LED_ON=0;
    Coupe l'alimentation de suite, ça devrait faire le même effet.


    Ta procédure d'interruption n'est pas initialisée.
    Il doit manquer quelque chose comme un
    #pragma interrupt initializeLED

    le while(1); est un peu sauvage dans la fonction led.
    Même si dans ton cas ca revient au même, il est préférable de faire la boucle infinie clairement dans le main() pour rajouter plus facilement d'autres fonctionnalités.

    Bon courage

  3. #3
    Membre à l'essai
    Inscrit en
    Novembre 2007
    Messages
    32
    Détails du profil
    Informations forums :
    Inscription : Novembre 2007
    Messages : 32
    Points : 15
    Points
    15
    Par défaut
    Bonjour,

    A quoi sert cette ligne je ne comprend pas trop...

    #pragma interrupt initializeLED

    Je te remercie

    Nicolas

  4. #4
    Membre à l'essai
    Inscrit en
    Novembre 2007
    Messages
    32
    Détails du profil
    Informations forums :
    Inscription : Novembre 2007
    Messages : 32
    Points : 15
    Points
    15
    Par défaut
    Je suis un peu perdu...Quelqu'un pourrai me donner un petit cou de pouce...

    MErci

    Nicolas

  5. #5
    Membre à l'essai
    Inscrit en
    Novembre 2007
    Messages
    32
    Détails du profil
    Informations forums :
    Inscription : Novembre 2007
    Messages : 32
    Points : 15
    Points
    15
    Par défaut
    J'ai rééecri mon programme avec lequel je souhaite juste allumer une LED sur RB3 suite a lappui sur un BP sur RB0 et après un autre appui elle s'éteint et ainsi de suite...voila ce que j'ai mais cela ne marche pas..
    Auriez vous quelques idées..
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    //fichier de declaration des registres internes du microcontroleur
    #include <p18f4682.h>
    #include <portb.h>    /* for the RB0/INT0 interrupt */
     
    //Déclaration des PORTXbits.RXX utilisés
    #define LED_ON PORTBbits.RB3
     
    //Configuration Bits
    #pragma config OSC = XT			//Config du type de l'oscillateur
     
    //Sous programmes
    void init_uc(void);
    void EnableHighInterrupts (void);
    void ChargeurON (void);
     
     
     
    /* fonction interruption */
    void ChargeurON(void);
     
    // on déclare que lors d'une interruption
    #pragma code highVector=0x008
    void atInterrupthigh(void)
    {
    // on doit éxecuter le code de la fonction MyHighInterrupt
    _asm GOTO ChargeurON _endasm		
    }
    #pragma code // retour à la zone de code
     
    // ************************
    // ****  Interruptions ****
    // ************************
    #pragma interrupt ChargeurON 
    void ChargeurON(void)
    {
    LED_ON=1;
    INTCONbits.RBIF = 0; // Clear PORTB Interrupt Flag. 
    }
     
     
     
    /***************************************************************************
    *********************Programme Principal************************************
    ***************************************************************************/
    void main (void)
    {
    init_uc();				//Appel SP Initialisation du microcontroleur
     
    OpenRB0INT (PORTB_CHANGE_INT_ON & /* enable the RB0/INT0 interrupt */
                  PORTB_PULLUPS_ON &    /* configure the RB0 pin for input */
                  FALLING_EDGE_INT);    /* trigger interrupt upon S3 button
                                           depression */
    EnableHighInterrupts ( );
    while(1)
     {
     
     }
     
    }//Fin Programme Principal
     
     
     
     
     
    /***************************************************************************
    Nom   : void init_uc(void)
    Role  : Configuration et initialisation des Ports E/S
    ----------------------------------------------------------------------------
    Contraintes           : Aucune
    Donnees en entree     : Aucune
    Donnees en sortie     : Aucune
    Donnees glob. modif.  : Aucune
    *****************************************************************************/
    void init_uc(void)
    {
     TRISA=0x00;					// PORTA en sortie
     TRISB=0x07;					// RB7-RB4 en sortie RB3-RB0 en entrée
     TRISC=0x1F;					// RC7-RC5 en sortie RC4-RC0 en entrée
     TRISD=0x4F;					// PORTD en sortie sauf RD7 RD5 RD4
     TRISE=0x00;					// PORTE en sortie
     
     PORTA=0x00;
     PORTB=0x00;
     PORTC=0x00;
     PORTD=0x00; 
     PORTE=0x00;
     
     ADCON1=0b00001111;				//Configuration du portA en numérique
    }
     
     
    void EnableHighInterrupts (void)
    {
      RCONbits.IPEN = 1;         /* enable interrupt priority levels */
      INTCONbits.GIEH = 1;       /* enable all high priority interrupts */
    }
    Je vous remercie pour votre aide

    Nicolas

  6. #6
    Membre du Club
    Profil pro
    Inscrit en
    Novembre 2006
    Messages
    52
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 52
    Points : 62
    Points
    62
    Par défaut
    En admettant que tes initialisations soient correctes (Entrées, sorties et IT).

    Dans ta fonction d'interruption, il faut que tu relise ta sortie LED si cela est possible (dépend du microcontroleur) et que tu la complemente.
    Si la relecture de la sortie est impossible, gère une variable globale que tu complémente a chaque passage dans l'IT et recopie cette variable sur la sortie.
    Dans ton code actuel, la sortie est positionnée a 1 définitivement à la première IT.

    autre piège à débutant, les rebonds, suivant le montage utilisée pour l'entrée du BP, tu risques pour un appui de générer plusieurs IT, et si ce nombre est pair, ta led ne changera pas d'état.

    As tu vérifié que ton montage marche (Variation de la tension sur l'entrée lors de l'appuie sur le BP, allumage extinction de la led avec un prog minimum initialisant la sortie et la positionnant a 1 puis à 0, des fois que ta led soit soudée a l'envers.

    Bon courage

  7. #7
    Membre à l'essai
    Inscrit en
    Novembre 2007
    Messages
    32
    Détails du profil
    Informations forums :
    Inscription : Novembre 2007
    Messages : 32
    Points : 15
    Points
    15
    Par défaut
    Bonjour,
    En ce qui concerne l'anti rebond, je l'ai réalisé de façon matériel,et pour la diode elle fonctionne correctement..je l'ai déja testé.
    Pour la partie programmation...je cherche....
    Et j'ai ouvert une nouvelle discussion, avec justement le changement de l'état de la LED, mais cela ne marche tjs pas...

    http://www.developpez.net/forums/sho...d.php?t=457858

    MErci
    Nicolas

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo