Bonjour,
je souhaite tout d'abord réaliser un truc tout simple , suite à un appui sur un BP brancher sur RB0, cela génère une interruption, et ensuite cela allume une LED sur RA0. Et après un autre appui sur le BP, cela l'éteint et ainsi de suite...

Je pensai réaliser cela avec la fonction OpenRB0INT de la librairie PORTB du compiler C18, et j'arrive a cela..:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//fichier de declaration des registres internes du microcontroleur
#include <p18f4682.h>
#include <portb.h>    /* for the RB0/INT0 interrupt */
 
//Déclaration des PORTXbits.RXX utilisés
#define LED_ON PORTAbits.RA0
 
//Configuration Bits
#pragma config OSC = XT			//Config du type de l'oscillateur
 
//Sous programmes
void init_uc(void);
void EnableHighInterrupts (void);
void LED (void);
void initializeLED(void);
//Déclarations des variables
 
 
/***************************************************************************
*********************Programme Principal************************************
***************************************************************************/
void main (void)
{
init_uc();				//Appel SP Initialisation du microcontroleu
EnableHighInterrupts ( );
initializeLED();
 
OpenRB0INT (PORTB_CHANGE_INT_ON & /* enable the RB0/INT0 interrupt */
              PORTB_PULLUPS_ON &    /* configure the RB0 pin for input */
              FALLING_EDGE_INT);    /* trigger interrupt upon S3 button
                                       depression */
LED ();
}//Fin Programme Principal
 
 
 
 
 
/***************************************************************************
Nom   : void init_uc(void)
Role  : Configuration et initialisation des Ports E/S
----------------------------------------------------------------------------
Contraintes           : Aucune
Donnees en entree     : Aucune
Donnees en sortie     : Aucune
Donnees glob. modif.  : Aucune
*****************************************************************************/
void init_uc(void)
{
 TRISA=0x00;					// PORTA en sortie
 TRISB=0x0F;					// RB7-RB4 en sortie RB3-RB0 en entrée
 TRISC=0x1F;					// RC7-RC5 en sortie RC4-RC0 en entrée
 TRISD=0x4F;					// PORTD en sortie sauf RD7 RD5 RD4
 TRISE=0x00;					// PORTE en sortie
 
 PORTA=0x00;
 PORTB=0x00;
 PORTC=0x00;
 PORTD=0x00; 
 PORTE=0x00;
 
 ADCON1=0b00001111;				//Configuration du portA en numérique
}
 
 
void EnableHighInterrupts (void)
{
  RCONbits.IPEN = 1;         /* enable interrupt priority levels */
  INTCONbits.GIEH = 1;       /* enable all high priority interrupts */
}
 
 
void LED (void)
{
  LED_ON = 1;            /* turn the buzzer on */
  while (1);                 /* wait for the S3 button to be pressed */
}
 
void initializeLED(void)
{
if(LED_ON==0)LED_ON=1;
if(LED_ON==1)LED_ON=0;
INTCONbits.INT0IF = 0;     /* clear flag to avoid another interrupt */
}
Qu"en pensez vous..
je vous remercie d'avance
Nicolas