J'ai un petit problème sur mon programme. Il consiste à allumer une led rouge (RB7) à l'aide d'un bouton poussoir (RC5). Quand j'appuie sur le bouton, la LED s'allume au bout d'un certain temps et s'éteint après plusieurs appuis. Je n'arrive pas simplement à allumer et éteindre une led avec ce bouton poussoir. J'utilise MPLAB X IDE v4.01 pour la programmation du PIC. Si quelqu'un pourrait m'aider, avec plaisir !
Voici le programme actuel
Code : Tout sélectionner
// CONFIG1
#pragma config FEXTOSC = OFF // FEXTOSC External Oscillator mode Selection bits (Oscillator not enabled)
#pragma config RSTOSC = HFINT1 // Power-up default value for COSC bits (HFINTOSC with 2x PLL (32MHz))
#pragma config CLKOUTEN = OFF // Clock Out Enable bit (CLKOUT function is enabled; FOSC/4 clock appears at OSC2)
#pragma config CSWEN = ON // Clock Switch Enable bit (Writing to NOSC and NDIV is allowed)
#pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is disabled)
// CONFIG2
#pragma config MCLRE = ON // Master Clear Enable bit (MCLR/VPP pin function is MCLR; Weak pull-up enabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config WDTE = OFF // Watchdog Timer Enable bits (WDT disabled; SWDTEN is ignored)
#pragma config LPBOREN = OFF // Low-power BOR enable bit (ULPBOR disabled)
#pragma config BOREN = SBOREN // Brown-out Reset Enable bits (Brown-out Reset enabled according to SBOREN)
#pragma config BORV = LOW // Brown-out Reset Voltage selection bit (Brown-out voltage (Vbor) set to 2.45V)
#pragma config PPS1WAY = OFF // PPSLOCK bit One-Way Set Enable bit (The PPSLOCK bit can be set and cleared repeatedly (subject to the unlock sequence))
#pragma config STVREN = OFF // Stack Overflow/Underflow Reset Enable bit (Stack Overflow or Underflow will not cause a Reset)
#pragma config DEBUG = OFF // Debugger enable bit (Background debugger disabled)
// CONFIG3
#pragma config WRT = OFF // User NVM self-write protection bits (Write protection off)
#pragma config LVP = ON // Low Voltage Programming Enable bit (Low Voltage programming enabled. MCLR/VPP pin function is MCLR. MCLRE configuration bit is ignored.)
// CONFIG4
#pragma config CP = OFF // User NVM Program Memory Code Protection bit (User NVM code protection disabled)
#pragma config CPD = OFF // Data NVM Memory Code Protection bit (Data NVM code protection disabled)
#include <xc.h>
// PORT A
#define ICSPDAT RA0 // Port de programmation
#define POWER RA1 // Retour d etat charge batterie
#define MCLR RA3 // Port de programmation
// PORT B
#define ledR RB7 // +LED rouge
// PORT C
#define BP RC5 // Bouton poussoir
#define _XTAL_FREQ 16000000
int etat_Bp = 0;
unsigned char unite;
void main(void)
{
// Reglages des entrees/sorties
TRISA = 0b00001011; // Choix entrees/sorties
LATA = 0b00000000; // RAZ des ports
ANSELA = 0; // Choix mode analogique/numerique
INLVLA = 0b00000010; // Niveaux TTL
WPUA = 0b00000010; // Resistances de pull-up interne
TRISB = 0b01010000; // Choix entrees/sorties
LATB = 0b10000000; // RAZ des ports
ANSELB = 0; // Choix mode analogique/numerique
INLVLB = 0b10000000; // Niveaux TTL
SLRCONB = 0b10101111; // Slew rate
WPUB = 0; // Resistances de pull-up interne
TRISC = 0b00111000; // Choix entrees/sorties
LATC = 0b11000000; // RAZ des ports
ANSELC = 0b00011000; // Choix mode analogique/numerique
INLVLC = 0b11000111; // Niveaux TTL
SLRCONC = 0b11111111; // Slew rate
WPUC = 0b00100000; // Resistances de pull-up interne
while(1) // boucle infinie
{
if (BP == 1){
__delay_ms(30);
etat_Bp = 1;
ledR = 1;
}
if (etat_Bp == 1 && (BP == 0))
{
unite ++;
etat_Bp = 0;
ledR = 0;
__delay_ms(30);
}
}
}

du rebond sur mon clavier !