//arlotto 2007 : Démonstration des interruptions sur 18F4520 // L'it overflow Timer3 inverse RB1 tout les 4.Tosc.4.2^16 // soit 262.144ms // L'it overflow Timer1 inverse RB2 tout les 4.Tosc.8.2^16 //soit 524.288 ms // ici les it sont utilisées dans le mode pic18 // avec priorité (RCONbits.IPEN = 1 ) // L'autorisation se fait par les bits GIE et PEIE de INTCON. #include #include // pour fonctions UART // configuration PICDEM2+ quartz #pragma config OSC = HS #pragma config WDT = OFF #pragma config LVP = OFF #pragma config PBADEN = OFF #define Button PORTBbits.RB0 #define GreenLed PORTBbits.RB1 #define RedLed PORTBbits.RB2 //prototypes des gestionnaires d'interruption void InterruptHandlerHigh (void); void InterruptHandlerLow (void); void main(void){ GreenLed= 0 ; RedLed = 0 ; TRISBbits.TRISB1=0; TRISBbits.TRISB2=0; OpenTimer1(TIMER_INT_ON & T1_16BIT_RW & T1_SOURCE_INT & T1_PS_1_8 & T1_OSC1EN_OFF & T1_SYNC_EXT_OFF ); IPR1bits.TMR1IP=0; // T1 basse priorité OpenTimer3( TIMER_INT_ON & T3_16BIT_RW & T3_SOURCE_INT & T3_PS_1_4 & T3_SYNC_EXT_OFF ); IPR2bits.TMR3IP=1; // T3 haute priorité RCONbits.IPEN = 1; INTCONbits.GIEL = 1 ; // autorisation low INTCONbits.GIEH = 1 ; // autorisation high for( ;; ) { } } //Placement d'un saut vers le gestionnaire d'interruption //---------------------------------------------------------------------------- // High priority interrupt vector #pragma code InterruptVectorHigh = 0x08 void InterruptVectorHigh (void) { _asm goto InterruptHandlerHigh //jump to interrupt routine _endasm } // Low priority interrupt vector #pragma code InterruptVectorLow = 0x18 void InterruptVectorLow (void) { _asm goto InterruptHandlerLow //jump to interrupt routine _endasm } // Routines gestionnaire d'interruption //---------------------------------------------------------------------------- // High priority interrupt routine #pragma code #pragma interrupt InterruptHandlerHigh void InterruptHandlerHigh () { if(PIR2bits.TMR3IF ){ PIR2bits.TMR3IF = 0 ; GreenLed = !GreenLed ; } // Placer ici les autres parties // if(Autre bit F) // { // Raz du bit F ; // Traitement ; // } } // Low priority interrupt routine #pragma code #pragma interrupt InterruptHandlerLow void InterruptHandlerLow () { if(PIR1bits.TMR1IF ){ PIR1bits.TMR1IF = 0 ; RedLed = !RedLed ; } // Placer ici les autres parties // if(Autre bit F) // { // Raz du bit F ; // Traitement ; // } }