sbit LedD1 at GPIO.B5; sbit LedD2 at GPIO.B4; sbit LedD3 at GPIO.B2; sbit LedD4 at GPIO.B1; sbit LedD5 at GPIO.B0; unsigned char ActiveLeds; void init() { TRISIO = 0x08, // On configure l'entrée GP3 en entrée GPIO = 0x00; // On met les sorties à l'état logique bas "0" CMCON = 0x07; // On désactive le module de comparaison ADCON0 = 0x00; // On désactive le module Analogique Numérique (pas de consommation de courant) ANSEL = 0x00; // On configure toutes les broches en sortie numérique TMR1ON_bit = 1; // On active le TIMER1 T1CKPS0_bit = 1; //| T1CKPS1_bit = 1; //| On configure le prescaler à 1:8 TMR1CS_bit = 0; // On utlise l'horloge interne (Fosc/4) INTCON.GIE = 1; // On active les interruptions générales INTCON.PEIE = 1; // et on active les masques d'interrutpion PIE1.TMR1IE = 1; // On active les interruptions du TIMER1 PIR1.TMR1IF = 0; // On met à zéro le drapeau de débordement TMR1L = 0x00; // On commence à zéro pour compter! TMR1H = 0x00; ActiveLeds = 1; // Permet d'activer à tour de rôle les leds } void interrupt() { if (GPIO.GP3 == 1) { if ((PIR1.TMR1IF == 1) && (ActiveLeds == 1)) { LedD1 = 1; LedD2 = 0; LedD3 = 0; LedD4 = 0; LedD5 = 1; ActiveLeds = 2; PIR1.TMR1IF = 0; } if ((PIR1.TMR1IF == 1) && (ActiveLeds == 2)) { LedD1 = 1; LedD2 = 1; LedD3 = 0; LedD4 = 0; LedD5 = 0; ActiveLeds = 3; PIR1.TMR1IF = 0; } if ((PIR1.TMR1IF == 1) && (ActiveLeds == 3)) { LedD1 = 0; LedD2 = 1; LedD3 = 1; LedD4 = 0; LedD5 = 0; ActiveLeds = 4; PIR1.TMR1IF = 0; } if ((PIR1.TMR1IF == 1) && (ActiveLeds == 4)) { LedD1 = 0; LedD2 = 0; LedD3 = 1; LedD4 = 1; LedD5 = 0; ActiveLeds = 5; PIR1.TMR1IF = 0; } if ((PIR1.TMR1IF == 1) && (ActiveLeds == 5)) { LedD1 = 0; LedD2 = 0; LedD3 = 0; LedD4 = 1; LedD5 = 1; ActiveLeds = 1; PIR1.TMR1IF = 0; } } if (GPIO.GP3 == 0) { if ((PIR1.TMR1IF == 1) && (ActiveLeds == 1)) { LedD1 = 1; LedD2 = 0; LedD3 = 0; LedD4 = 0; LedD5 = 0; ActiveLeds = 2; PIR1.TMR1IF = 0; } if ((PIR1.TMR1IF == 1) && (ActiveLeds == 2)) { LedD1 = 0; LedD2 = 1; LedD3 = 0; LedD4 = 0; LedD5 = 0; ActiveLeds = 3; PIR1.TMR1IF = 0; } if ((PIR1.TMR1IF == 1) && (ActiveLeds == 3)) { LedD1 = 0; LedD2 = 0; LedD3 = 1; LedD4 = 0; LedD5 = 0; ActiveLeds = 4; PIR1.TMR1IF = 0; } if ((PIR1.TMR1IF == 1) && (ActiveLeds == 4)) { LedD1 = 0; LedD2 = 0; LedD3 = 0; LedD4 = 1; LedD5 = 0; ActiveLeds = 5; PIR1.TMR1IF = 0; } if ((PIR1.TMR1IF == 1) && (ActiveLeds == 5)) { LedD1 = 0; LedD2 = 0; LedD3 = 0; LedD4 = 0; LedD5 = 1; ActiveLeds = 1; PIR1.TMR1IF = 0; } } } void main() { init(); while (1) { // On ne fait rien dans le programme principal } }