probleme 2 interruption pic 18f4550 pic ->plante
Répondre à la discussion
Affichage des résultats 1 à 6 sur 6

probleme 2 interruption pic 18f4550 pic ->plante



  1. #1
    invite4ec38ea0

    probleme 2 interruption pic 18f4550 pic ->plante


    ------

    Bonjour, j'essaye de programmer deux interruptions (timer 0+int0 (patte 1 du portB) sur un pic en C avec mplab et C18 mais sans y parvenir. voici mon code:


    #include <p18f4550.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <delays.h>

    #pragma config FOSC=HS
    #pragma config WDT=OFF
    #pragma config LVP=OFF
    #pragma config PBADEN=OFF
    #pragma interrupt interrupt_portc
    #pragma interrupt interrupt_porta_porte

    void interrupt_portc(void);
    void interrupt_porta_porte(void);

    /*Tableaux correspondants aux LEDs*/

    volatile int stop=0;
    volatile int cpt=0;
    volatile int j=11;


    void interrupt_portc()
    {
    if (INTCONbits.TMR0IF)
    {
    if (cpt==0)
    {
    PORTD=0b00000001;
    cpt++;
    }else if (cpt==1)
    {
    PORTD=0b00000010;
    cpt++;
    } else if (cpt==2)
    {
    PORTD=0b00000100;
    cpt=0;
    }
    stop++;
    INTCONbits.TMR0IF=0;
    //T0CONbits.TMR0ON=0;
    TMR0L=0x00;
    TMR0H=0x00;
    }
    }

    void interrupt_porta_porte()
    {
    if (INTCONbits.INT0IF)
    {
    // j=1;
    INTCONbits.INT0IF=0;
    }
    else if (INTCON3bits.INT1IF)
    {
    // j=2;
    INTCON3bits.INT1IF=0;
    }
    else if (INTCON3bits.INT2IF)
    {
    // j=3;
    INTCON3bits.INT2IF=0;
    }

    // else j=9;
    }


    void main (void)
    {
    const unsigned char taba[12]={0b11000000,0b11111001,0b1110 0100,0b11110000,0b11011001,0b1 1010010,0b11000010,0b11111000, 0b11000000,0b11010000,0b111000 01,0b11100011};//0x3F,0x06,0x1B,0x0F,0x26,0x2D, 0x3D,0x07,0x3F,0x2F,0x1E,0x1C
    const unsigned char tabe[12]={0b11111111,0b11111111,0b1111 1110,0b11111110,0b11111110,0b1 1111110,0b11111110,0b11111111, 0b11111110,0b11111110,0b111111 10,0b11111111};//0x3F,0x06,0x1B,0x0F,0x26,0x2D, 0x3D,0x07,0x3F,0x2F,0x1E,0x1C

    unsigned char i;
    unsigned char tabaa=0,tabee=0;

    /*Paramétrages des PORTS A à E, 0=Output, 1=Input*/
    TRISA=0x00;
    TRISB=0b00001111;
    TRISC=0b00111000;
    TRISD=0b00000000;
    TRISE=0b11111000;

    /*Initialisation des PORTS A à E*/
    PORTA=0x3F;
    PORTB=0x00;
    PORTC=0xFF;
    PORTD=0b00000001;
    PORTE=0xFF;



    /*init timer*/

    RCONbits.IPEN=0;
    // T0CONbits.TMR0ON=1; // Validation du timer0
    T0CONbits.T08BIT=1;
    T0CONbits.PSA =0; // Prédiviseur affecté au timer 0
    T0CONbits.T0CS= 0; // Timer 0 utilise l'horloge interne
    T0CONbits.T0PS2 = 1; // Prédivision de 2
    T0CONbits.T0PS1 = 1;
    T0CONbits.T0PS0= 1;
    INTCONbits.TMR0IF=0;
    //INTCON2bits.TMR0IP=0; //priorité de l'interruption du timer 0, haute
    INTCONbits.TMR0IE=1; //active l'interruption sur le timer
    //INTCONbits.GIE=1;


    /*Interruptions Init*/


    /* INTCON2bits.INTEDG0=1;
    INTCON2bits.INTEDG1=1;
    INTCON2bits.INTEDG2=1;
    INTCON3bits.INT1IF=0;
    INTCON3bits.INT2IF=0;
    INTCONbits.INT0IF=0;
    INTCON3bits.INT2IP=0;
    INTCON3bits.INT1IP=0;
    INTCON3bits.INT2IE=1;
    INTCON3bits.INT1IE=1;
    */
    INTCONbits.INT0IE=1;

    //INTCONbits.GIE=1;
    //INTCONbits.PEIE=1;

    INTCONbits.GIE=1;

    T0CONbits.TMR0ON=1;

    while(1)
    {
    for(i=0;i<4;i++)
    {
    if (i==0)PORTC=0b11000010;
    if (i==1)PORTC=0b11000001;
    if (i==2)PORTC=0b10000011;
    if (i==3)PORTC=0b01000011;
    if (stop>50)
    { stop=0;
    j++;
    PORTA=taba[j];
    PORTE=tabe[j];
    }
    if(j>10) j=0;
    //else
    //{
    // PORTA=taba[11];
    // PORTE=tabe[11];
    //}
    //if(stop>=8) stop=0;
    Delay1KTCYx(1);
    }
    }
    }


    le problème est le suivant: si je met que le code de l'interruption timer, tout fonctionne correctement. si je met que le code de l'interruption sur int0 pas de problème tout fonctionne correctement. mais si je met le code des deux interruptions ensemble, l'interruption sur le timer fonctionne mais dès que j'ai l'interruption sur le portB patte 1 (int0) le pic plante. Une idée????
    Peut être cela vient des init registres qui ne seraient pas dans le bonne ordre ou mal initialiser???? (J'ai déjà essayer pas mal de solution)

    -----

  2. #2
    zhal

    Re : probleme 2 interruption pic 18f4550 pic ->plante

    Bonjour,

    Je connais très mal le compilateur MPLAB, j'utilise CCS bien plus pratique.

    Il faudrai verifier la procedure dans le DATASHEET.

  3. #3
    RISC

    Re : probleme 2 interruption pic 18f4550 pic ->plante

    Salut,

    Ton code est difficile à lire sans les balises...Utilise "code" et "/code" (crochets à la place de mes ") autour de. ton code pour garder le formatage.

    Je pense que ta routine d'interruption n'est pas correcte. Tu semble en avoir 2 hors tu déclare le mode une seule interruption.

    Va faire un tour ici tu trouveras du code qui montre comment utiliser correctement les interruptions.

    a+

  4. #4
    bird12358

    Re : probleme 2 interruption pic 18f4550 pic ->plante

    Bonjour
    Tu ne traites aucunes de tes interruptions...
    Le fait de mettre
    Code:
    void interrupt_portc()
    {
    ...
    }
    ne suffit pas à les traiter.
    Tout d'abord tu ne semble pas vouloir utiliser la priorité des interruptions.
    Code:
    #pragma interrupt interrupt_port
    void interrupt_port()
     {
    //ce que tu met pour traiter les INT
    
    }
    #pragma code  IT=0x08
    void prog_IT()
    {
     _asm goto interrupt_port _end_asm
    }
    #pragma code
    Cela va te permettre de pointer chaque vecteur d'interruption sur la fonction que tu crée pour traiter l'interruption.

    Essayes comme ca.

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

    Re : probleme 2 interruption pic 18f4550 pic ->plante

    Voici le nouveau code merci de m'aider car pas de meilleur résultat

    <code>
    #include <p18f4550.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <delays.h>

    #pragma config FOSC=HS
    #pragma config WDT=OFF
    #pragma config LVP=OFF
    #pragma config PBADEN=OFF

    void interrupt_portc(void);
    void interrupt_porta_porte(void);

    #pragma code vecteurh=0x08 //
    void Vers_TIMER(void)
    {
    _asm goto interrupt_portc _endasm
    }
    #pragma code

    #pragma code vecteurl=0x18 //
    void Vers_INT08(void)
    {
    _asm goto interrupt_porta_porte _endasm
    }
    #pragma code


    /*Tableaux correspondants aux LEDs*/

    volatile int stop=0;
    volatile int cpt=0;
    volatile int j=11;

    //#pragma code_INTERRUPT_VECTORH=0x00330 0
    #pragma interrupt interrupt_portc
    void interrupt_portc(void)
    {
    if (INTCONbits.TMR0IF)
    {
    if (cpt==0)
    {
    PORTD=0b00000001;
    cpt++;
    }else if (cpt==1)
    {
    PORTD=0b00000010;
    cpt++;
    } else if (cpt==2)
    {
    PORTD=0b00000100;
    cpt=0;
    }
    stop++;
    INTCONbits.TMR0IF=0;
    //T0CONbits.TMR0ON=0;
    TMR0L=0x00;
    TMR0H=0x00;
    }
    }

    #pragma interrupt interrupt_porta_porte
    void interrupt_porta_porte(void)
    {

    if (INTCONbits.INT0IF)
    {
    // j=1;
    INTCONbits.INT0IF=0;
    }
    /* else if (INTCON3bits.INT1IF)
    {
    // j=2;
    INTCON3bits.INT1IF=0;
    }
    else if (INTCON3bits.INT2IF)
    {
    // j=3;
    INTCON3bits.INT2IF=0;
    }

    // else j=9;*/
    }


    void main (void)
    {
    const unsigned char taba[12]={0b11000000,0b11111001,0b1110 0100,0b11110000,0b11011001,0b1 1010010,0b11000010,0b11111000, 0b11000000,0b11010000,0b111000 01,0b11100011};//0x3F,0x06,0x1B,0x0F,0x26,0x2D, 0x3D,0x07,0x3F,0x2F,0x1E,0x1C
    const unsigned char tabe[12]={0b11111111,0b11111111,0b1111 1110,0b11111110,0b11111110,0b1 1111110,0b11111110,0b11111111, 0b11111110,0b11111110,0b111111 10,0b11111111};//0x3F,0x06,0x1B,0x0F,0x26,0x2D, 0x3D,0x07,0x3F,0x2F,0x1E,0x1C

    unsigned char i;
    unsigned char tabaa=0,tabee=0;

    /*Paramétrages des PORTS A à E, 0=Output, 1=Input*/
    TRISA=0x00;
    TRISB=0b00001111;
    TRISC=0b00111000;
    TRISD=0b00000000;
    TRISE=0b11111000;

    /*Initialisation des PORTS A à E*/
    PORTA=0x3F;
    PORTB=0x00;
    PORTC=0xFF;
    PORTD=0b00000001;
    PORTE=0xFF;


    /*init timer*/
    RCONbits.IPEN=1;
    // T0CONbits.TMR0ON=1; // Validation du timer0
    T0CONbits.T08BIT=1;
    T0CONbits.PSA =0; // Prédiviseur affecté au timer 0
    T0CONbits.T0CS= 0; // Timer 0 utilise l'horloge interne
    T0CONbits.T0PS2 = 1; // Prédivision de 2
    T0CONbits.T0PS1 = 1;
    T0CONbits.T0PS0= 1;
    INTCONbits.TMR0IF=0;
    //INTCON2bits.TMR0IP=0; //priorité de l'interruption du timer 0, haute
    INTCONbits.TMR0IE=1; //active l'interruption sur le timer
    //INTCONbits.GIE=1;


    /*Interruptions Init*/


    /* INTCON2bits.INTEDG0=1;
    INTCON2bits.INTEDG1=1;
    INTCON2bits.INTEDG2=1;
    INTCON3bits.INT1IF=0;
    INTCON3bits.INT2IF=0;
    INTCONbits.INT0IF=0;
    INTCON3bits.INT2IP=0;
    INTCON3bits.INT1IP=0;
    INTCON3bits.INT2IE=1;
    INTCON3bits.INT1IE=1;
    */
    INTCONbits.INT0IE=1;

    INTCONbits.GIEH=1;
    INTCONbits.GIEL=1;

    T0CONbits.TMR0ON=1;

    while(1)
    {
    for(i=0;i<4;i++)
    {
    if (i==0)PORTC=0b11000010;
    if (i==1)PORTC=0b11000001;
    if (i==2)PORTC=0b10000011;
    if (i==3)PORTC=0b01000011;
    if (stop>50)
    { stop=0;
    j++;
    PORTA=taba[j];
    PORTE=tabe[j];
    }
    if(j>10) j=0;
    //else
    //{
    // PORTA=taba[11];
    // PORTE=tabe[11];
    //}
    //if(stop>=8) stop=0;
    //Delay1KTCYx(1);
    }
    }
    }

    </code>


    merci

  7. #6
    bird12358

    Re : probleme 2 interruption pic 18f4550 pic ->plante

    C'est à dire pas de meilleur résusltat?

    Tout d'abord si tu n'utilise pas les interruptions priorisées alors ce code ne sert pas à grand chose:
    Code:
    #pragma code vecteurl=0x18 //
    void Vers_INT08(void)
    {
    _asm goto interrupt_porta_porte _endasm
    }
    Ensuite si tu n'utilise pas les interruptions priorisées alors ce code ne sert pas à grand chose :
    INTCONbits.GIEH=1;
    INTCONbits.GIEL=1;

    Il faut mettre juste INTCONbits.GIE=1;

    ET si tu voulais utiliser la gestion des interruptions de bas niveau alors ce code la est faux:

    Code:
    #pragma interrupt interrupt_porta_porte
    void interrupt_porta_porte(void)
    {
    
    if (INTCONbits.INT0IF)
    {
    // j=1;
    INTCONbits.INT0IF=0;
    }
    /* else if (INTCON3bits.INT1IF)
    {
    // j=2;
    INTCON3bits.INT1IF=0;
    }
    else if (INTCON3bits.INT2IF)
    {
    // j=3;
    INTCON3bits.INT2IF=0;
    }
    Il faudrait mettre
    Code:
    #pragma interruptlow interrupt_porta_porte
    void interrupt_porta_porte(void)
    {
    ....
    }

    Voila, essayes comme ca.

Discussions similaires

  1. Réponses: 1
    Dernier message: 17/07/2010, 06h34
  2. Problème interruption PIC
    Par Pilou81 dans le forum Électronique
    Réponses: 19
    Dernier message: 17/06/2010, 15h15
  3. Probleme interruption PIC (en C)
    Par Pilou81 dans le forum Électronique
    Réponses: 6
    Dernier message: 27/04/2010, 10h08
  4. pic 18f4550
    Par invite8a14e47c dans le forum Électronique
    Réponses: 3
    Dernier message: 06/04/2010, 21h41
  5. Probleme interruption pic 18f2620
    Par invite595a8f70 dans le forum Électronique
    Réponses: 2
    Dernier message: 04/06/2009, 09h50
Dans la rubrique Tech de Futura, découvrez nos comparatifs produits sur l'informatique et les technologies : imprimantes laser couleur, casques audio, chaises gamer...