Les Interruptions

download Les Interruptions

of 21

Transcript of Les Interruptions

  • 8/8/2019 Les Interruptions

    1/21

    RoboCEPT

    Sance 07

    PROGRAMMATION EN C DES PICS

    LES INTERRUPTIONS

    Sance prsente par : Rostem MHEDHBIlve ingnieur en troisime anne lEPT,

    option : SISY

  • 8/8/2019 Les Interruptions

    2/21

    Plan de la sance

    But:

    Se familiariser avec la notion

    dinterruption

    Etre capable dcrire desprogrammes en langage C (sur

    MikroC) pour grer les interruptions

    Cest quoi une interruption ?

    Mcanisme dinterruption

    Sources dinterruptions

    Les registres dinterruptions

  • 8/8/2019 Les Interruptions

    3/21

  • 8/8/2019 Les Interruptions

    4/21

    Quest-ce quune interruption ?

  • 8/8/2019 Les Interruptions

    5/21

    Quest-ce quune interruption ?

    Votre programme se droule normalement.

    Un vnement spcifique survient.

    Le programme principal est interrompu (donc, subitune INTERRUPTION).

    Le PIC traite lvnement

    Le PIC reprend le programme principal lendroit o ila t interrompu.

  • 8/8/2019 Les Interruptions

    6/21

  • 8/8/2019 Les Interruptions

    7/21

    Mcanisme dInterruption

    Ladresse de dbut des interruptions est 0X04.

    Toute interruption provoque le saut du programme vers

    cette adresse (PC) pour excuter le code. Toutes les sources dinterruption arrivent sur cette

    adresse.

    Le contenu du PC est sauvegard dans la pile interne (8

    niveau). Une interruption ne peut pas tre interrompue par une

    autre interruption (GIE=0).

  • 8/8/2019 Les Interruptions

    8/21

    Mcanisme dInterruption

    Une routine dinterruption doit

    1) sauvegarder le contexte (valeur des registres)2) prendre en charge la demande dinterruption

    3) la traiter (le + rapidement possible)4) Restaurer le contexte5) Retour au programme

    (instruction RETFIE pour les PIC, RETI en

    gnral)

  • 8/8/2019 Les Interruptions

    9/21

  • 8/8/2019 Les Interruptions

    10/21

    3 types dinterruptions:

    Interruptions derreurs

    Interruptions matrielles

    Interruptions logicielles

    Les sources dinterruptions

  • 8/8/2019 Les Interruptions

    11/21

  • 8/8/2019 Les Interruptions

    12/21

    Bit 7 : GIE = Global Interrupt Enable bitBit 6 : PEIE = Peripheral Interrupt Enable bit.Bit 5 : TOIE = Timer TMR0 Overflow Interrupt Enable bit.Bit 4 : INTE = RB0/Int Interrupt Enable bit.Bit 3 : RBIE = RB Port Change Interrupt Enable bit.Bit 2 : TOIF = Timer TMR0 Overflow Interrupt Flag bit.Bit 1 : INTF = RB0/Int Interrupt Flag bit.Bit 0 : RBIF = RB Port Change Interrupt Flag bit.

    Le registre INTCON

  • 8/8/2019 Les Interruptions

    13/21

    Le registre PIE1

    Bit 7 : PSPIE = Parallel Slave Port Interrupt Enable bitBit 6 : ADIE = A/D converter Interrupt Enable bitBit 5 : RCIE = USART Receive Interrupt Enable bitBit 4 : TXIE = USART Transmit Interrupt Enable bit.Bit 3 : SSPIE = Synchronous Serial Port Interrupt Enable bit.Bit 2 : CCP1IP = CCP1 Interrupt Enable bit.Bit 1 : TMR2IE = TMR2 Interrupt Enable bit.Bit 0 : TMR1IE = TMR1 Interrupt Enable bit.

  • 8/8/2019 Les Interruptions

    14/21

    Le registre PIR1

    Bit 7 : PSPIF = Parallel Slave Port Interrupt Flag bitBit 6 : ADIF = A/D converter Interrupt Flag bitBit 5 : RCIF = USART Receive Interrupt Flag bitBit 4 : TXIF = USART Transmit Interrupt Flag bit.Bit 3 : SSPIF = Synchronous Serial Port Interrupt Flag bit.Bit 2 : CCP1IF = CCP1 Interrupt Flag bit.Bit 1 : TMR2IF = TMR2 Interrupt Flag bit.Bit 0 : TMR1IF = TMR1 Interrupt Flag bit.

  • 8/8/2019 Les Interruptions

    15/21

    Exemple sur MicroC

    Led qui clignotte en utilisant une interruption:

    Exemple 1: TMR0

    Exemple 2 : PORTB0

  • 8/8/2019 Les Interruptions

    16/21

    Exemple 1 :

    unsigned int cnt;

    void main()

    {

    OPTION_REG = 0x84; // Assign prescaler to TMR0

    TRISB = 0; // PORTB is output

    PORTB = 0b11111111; // Initialize PORTB

    TMR0 = 96; // Timer0 initial value

    INTCON = 0b10100000; // Enable TMRO interrupt

    cnt = 0; // Initialize cnt

    while (1) {

    if (cnt == 400) {

    PORTB = ~PORTB; // Toggle PORTB LEDs

    cnt = 0; // Reset cnt

    }

    }

    }

  • 8/8/2019 Les Interruptions

    17/21

    Exemple 1 :

    void interrupt()

    {

    cnt++; // Increment value of cnt on every interrupt

    TMR0 = 96;

    INTCON = 0b00100000; // Set T0IE , clear T0IF

    }

  • 8/8/2019 Les Interruptions

    18/21

    Simulation sur ISIS

  • 8/8/2019 Les Interruptions

    19/21

    Exemple 2 :

    void interrupt()

    {

    PORTB.B4 = 1;

    delay_ms(1000);

    PORTB.B4 = 0;

    INTCON.B1 = 0;

    }

    void main() {

    INTCON = 0b10010000;

    while(1);

    }

  • 8/8/2019 Les Interruptions

    20/21

    Simulation sur ISIS

  • 8/8/2019 Les Interruptions

    21/21

    Merci Pour Votre Attention