Soy nuevo en los microcontroladores y el dsPIC33 y quiero escribir un programa simple antes de entrar en algo más complejo (aunque esto ya me parece muy complejo...). Estoy tratando de alternar un LED en mi placa de desarrollo dsPICDEM MCLV-2 usando mi microcontrolador dsPIC33EP256MC506. En este momento, mi código solo hace que el LED permanezca encendido sin que yo presione el botón. ¿Alguien puede ayudarme a encontrar el problema con mi código?
Si alguien conoce algún programa de muestra que pueda ejecutar y jugar, ¡también sería muy útil!
Compilador: MPLAB X
Programador/Depurador: REAL ICE
Microcontrolador: dsPIC33EP256MC506
Placa de desarrollo: dsPICDEM MCLV-2
C Principal
int16_t main(void)
{
/* Configure the oscillator for the device */
ConfigureOscillator();
/* Initialize IO ports and peripherals */
InitApp();
TRISDbits.TRISD6 = 0; //set LED as output
TRISGbits.TRISG6 = 1; //set Button as input, port unknown
while(1)
{
if(S3 == 0) { //start/stop switch
uint32_t N = 21000000;
while(S3) //debounce
while(N--);
LATDbits.LATD6 = 1; //make LED pin high
}
}
}
usuario.h
#define S3 !PORTGbits.RG6 //S2 button
#define S2 !PORTGbits.RG7 //S3 button
#define D2 !PORTDbits.RD6 //D2 LED
#define DEBOUNCE_DELAY 30 //push button debounce delay, expressed in millisecond
/******************************************************************************/
/* User Function Prototypes */
/******************************************************************************/
/* TODO User level functions prototypes (i.e. InitApp) go here */
void InitApp(void); /* I/O and Peripheral Initialization */
Probar esto. asegúrese de que S3 sea la definición de macro correcta para el botón que está presionando, parece que lo comentó mal en el código.
while(1)
{
uint32_t N = 21000000;
uint32_t T = 21000000;
if(S3 == 1) {
LATDbits.LATD6 = 1; //make LED pin high
while(N--);
}
else { LATDbits.LATD6 = 0; //make LED pin low
while(T--); }
}
Esto no verificará el rebote del botón (si esto funciona, puede probar el rebote). En algunos microcontroladores, hay bits individuales asociados con los pines GPIO que pueden verificar el rebote del botón. Si está disponible, simplemente habilítelo para verificar el rebote.
krambo
LATDbits.LATD6 = 1;
esté sangrado no lo convierte en parte delwhile(S3)
bucle. Tal vez debería tener llaves alrededor de esas líneas sangradas.pedro bennett