Sunteți pe pagina 1din 21

RoboCEPT

Séance 07

PROGRAMMATION EN C DES PICS


LES INTERRUPTIONS

Séance présentée par : Rostem M’HEDHBI


élève ingénieur en troisième année à l’EPT,
option : SISY
Plan de la séance

But:
C’est quoi une interruption ?
Se familiariser avec la notion
d’interruption Mécanisme d’interruption

Etre capable d’écrire des


Sources d’interruptions
programmes en langage C (sur
MikroC) pour gérer les interruptions
Les registres d’interruptions
Qu’est-ce qu’une interruption ?
Qu’est-ce qu’une interruption ?

Votre programme se déroule normalement.

Un événement spécifique survient.

Le programme principal est interrompu (donc, subit


une INTERRUPTION).

Le PIC traite l’événement

Le PIC reprend le programme principal à l’endroit où il


a été interrompu.
Mécanisme d’Interruption

 L’adresse de début des interruptions est 0X04.


 Toute interruption provoque le saut du programme vers
cette adresse (PC) pour exécuter le code.
 Toutes les sources d’interruption 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).
Mécanisme d’Interruption

Une routine d’interruption doit


1) sauvegarder le contexte (valeur des registres)
2) prendre en charge la demande d’interruption
3) la traiter (le + rapidement possible)
4) Restaurer le contexte
5) Retour au programme
(instruction RETFIE pour les PIC, RETI en
général)
Les sources d’interruptions

3 types d’interruptions:

 Interruptions d’erreurs

 Interruptions matérielles

 Interruptions logicielles
Le registre INTCON

Bit 7 : GIE = Global Interrupt Enable bit


Bit 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 PIE1

Bit 7 : PSPIE = Parallel Slave Port Interrupt Enable bit


Bit 6 : ADIE = A/D converter Interrupt Enable bit
Bit 5 : RCIE = USART Receive Interrupt Enable bit
Bit 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.
Le registre PIR1

Bit 7 : PSPIF = Parallel Slave Port Interrupt Flag bit


Bit 6 : ADIF = A/D converter Interrupt Flag bit
Bit 5 : RCIF = USART Receive Interrupt Flag bit
Bit 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.
Exemple sur MicroC

 Led qui clignotte en utilisant une interruption:


 Exemple 1: TMR0
 Exemple 2 : PORTB0
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
}
}
}
Exemple 1 :

void interrupt()
{
cnt++; // Increment value of cnt on every interrupt
TMR0 = 96;
INTCON = 0b00100000; // Set T0IE , clear T0IF
}
Simulation sur ISIS
Exemple 2 :

void interrupt()
{
PORTB.B4 = 1;
delay_ms(1000);
PORTB.B4 = 0;
INTCON.B1 = 0;
}

void main() {
INTCON = 0b10010000;
while(1);
}
Simulation sur ISIS
Merci Pour Votre Attention

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