Que no den errores los retardos.

Hola:

Quiero hacer un programa básico con MPLAB X 3.55 en C. Hice un código sencillo de parpadear un Led con el PIC16F88 y me da error si uso:

__delay_ms(20);

Si no pongo nada me compila bien pero no parpadea el Led.

Código C:
Código:
// CONFIG1
#pragma config FOSC = XT        // Oscillator Selection bits (XT oscillator)
#pragma config WDTE = ON        // Watchdog Timer Enable bit (WDT enabled)
#pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = ON       // RA5/MCLR/VPP Pin Function Select bit (RA5/MCLR/VPP pin function is MCLR)
#pragma config BOREN = ON       // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = ON         // Low-Voltage Programming Enable bit (RB3/PGM pin has PGM function, Low-Voltage Programming enabled)
#pragma config CPD = OFF        // Data EE Memory Code Protection bit (Code protection off)
#pragma config WRT = OFF        // Flash Program Memory Write Enable bits (Write protection off)
#pragma config CCPMX = RB0      // CCP1 Pin Selection bit (CCP1 function on RB0)
#pragma config CP = OFF         // Flash Program Memory Code Protection bit (Code protection off)

// CONFIG2
#pragma config FCMEN = ON       // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor enabled)
#pragma config IESO = ON        // Internal External Switchover bit (Internal External Switchover mode enabled)

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

#include <xc.h>
#defina XTAL_FREC 4000000 // Cuarzo 4 Mhz.

void main(void) {
    TRISB = 0b00000000;
    PORTB = 0;
    
    while(1)
    {
        PORTBbits.RB1 = 1; // Puerto B como salida.
        //__delay_ms(20);    
        PORTBbits.RB1 = 0; // Limpiamos puerto B.
        //__delay_ms(20);
    }
}
Error:
make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory 'C:/Users/Meta/MPLABXProjects/Led_16F88_C.X'
make -f nbproject/Makefile-default.mk dist/default/debug/Led_16F88_C.X.debug.elf
make[2]: Entering directory 'C:/Users/Meta/MPLABXProjects/Led_16F88_C.X'
"C:\Program Files (x86)\Microchip\xc8\v1.41\bin\xc8.exe" --pass1 --chip=16F88 -Q -G -D__DEBUG=1 --debugger=none --double=24 --float=24 --opt=+asm,+asmfile,-speed,+space,-debug,-local --addrqual=ignore --mode=free -P -N255 --warn=-3 --asmlist -DXPRJ_default=default --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%f:%l: error: (%n) %s" "--warnformat=%f:%l: warning: (%n) %s" "--msgformat=%f:%l: advisory: (%n) %s" -obuild/default/debug/Led.p1 Led.c
Led.c:30: warning: (107) illegal # directive "defina"
Led.c:30: warning: (163) unexpected text in control line ignored
Led.c:39: error: (192) undefined identifier "_XTAL_FREQ"
make[2]: *** [build/default/debug/Led.p1] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
(908) exit status = 1
nbproject/Makefile-default.mk:91: recipe for target 'build/default/debug/Led.p1' failed
make[2]: Leaving directory 'C:/Users/Meta/MPLABXProjects/Led_16F88_C.X'
nbproject/Makefile-default.mk:84: recipe for target '.build-conf' failed
make[1]: Leaving directory 'C:/Users/Meta/MPLABXProjects/Led_16F88_C.X'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed

BUILD FAILED (exit value 2, total time: 816ms)

Saludos.
 
El parámetro xtal-freq también parece estar mal... dice error..

Los warning pueden no afectar el funcionamiento...

El delay usa la configuración del osc.. si esta mal configurado no funciona.

 
Hola
Hola:

Quiero hacer un programa básico con MPLAB X 3.55 en C. Hice un código sencillo de parpadear un Led con el PIC16F88 y me da error si uso:

__delay_ms(20);

Si no pongo nada me compila bien pero no parpadea el Led.

Código C:
Código:
// CONFIG1
#pragma config FOSC = XT        // Oscillator Selection bits (XT oscillator)
#pragma config WDTE = ON        // Watchdog Timer Enable bit (WDT enabled)
#pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = ON       // RA5/MCLR/VPP Pin Function Select bit (RA5/MCLR/VPP pin function is MCLR)
#pragma config BOREN = ON       // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = ON         // Low-Voltage Programming Enable bit (RB3/PGM pin has PGM function, Low-Voltage Programming enabled)
#pragma config CPD = OFF        // Data EE Memory Code Protection bit (Code protection off)
#pragma config WRT = OFF        // Flash Program Memory Write Enable bits (Write protection off)
#pragma config CCPMX = RB0      // CCP1 Pin Selection bit (CCP1 function on RB0)
#pragma config CP = OFF         // Flash Program Memory Code Protection bit (Code protection off)

// CONFIG2
#pragma config FCMEN = ON       // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor enabled)
#pragma config IESO = ON        // Internal External Switchover bit (Internal External Switchover mode enabled)

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

#include <xc.h>
#defina XTAL_FREC 4000000 // Cuarzo 4 Mhz.

void main(void) {
    TRISB = 0b00000000;
    PORTB = 0;
    
    while(1)
    {
        PORTBbits.RB1 = 1; // Puerto B como salida.
        //__delay_ms(20);    
        PORTBbits.RB1 = 0; // Limpiamos puerto B.
        //__delay_ms(20);
    }
}
Error:


Saludos.
Bueno ., yo con PIC no trabajo​
Pero por lo que indican los errores ., te señala lo fundamental ., que es __delay_ms(i)​
Me parece que te faltan la librerias #include "util delay.H o Delay.H ., donde se define o fija el valor de (i)​
Yo no lo veo ni tratado ni definido en tu programa​
A menos que el compilador lo maneje de otra manera​
 
Última edición:
Código:
// CONFIG1
#pragma config FOSC = XT        // Oscillator Selection bits (XT oscillator)
#pragma config WDTE = ON        // Watchdog Timer Enable bit (WDT enabled)
#pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = ON       // RA5/MCLR/VPP Pin Function Select bit (RA5/MCLR/VPP pin function is MCLR)
#pragma config BOREN = ON       // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = ON         // Low-Voltage Programming Enable bit (RB3/PGM pin has PGM function, Low-Voltage Programming enabled)
#pragma config CPD = OFF        // Data EE Memory Code Protection bit (Code protection off)
#pragma config WRT = OFF        // Flash Program Memory Write Enable bits (Write protection off)
#pragma config CCPMX = RB0      // CCP1 Pin Selection bit (CCP1 function on RB0)
#pragma config CP = OFF         // Flash Program Memory Code Protection bit (Code protection off)

// CONFIG2
#pragma config FCMEN = ON       // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor enabled)
#pragma config IESO = ON        // Internal External Switchover bit (Internal External Switchover mode enabled)

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

// https://www.youtube.com/watch?v=rKy24g_g0gQ

#include <xc.h>
#define XTAL_FREQ 4000000 // Cuarzo 4 Mhz.

void main(void) {
    TRISB = 0b00000000; // Puerto B como salida.
    PORTB = 0;          // Limpiamos puerto B.
    
    while(1)
    {
        PORTBbits.RB1 = 1; 
        __delay_ms(20);    
        PORTBbits.RB1 = 0; 
        __delay_ms(20);
    }
}


make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory 'C:/Users/Meta/MPLABXProjects/Led_16F88_C.X'
make -f nbproject/Makefile-default.mk dist/default/debug/Led_16F88_C.X.debug.elf
make[2]: Entering directory 'C:/Users/Meta/MPLABXProjects/Led_16F88_C.X'
"C:\Program Files (x86)\Microchip\xc8\v1.41\bin\xc8.exe" --pass1 --chip=16F88 -Q -G -D__DEBUG=1 --debugger=none --double=24 --float=24 --opt=+asm,+asmfile,-speed,+space,-debug,-local --addrqual=ignore --mode=free -P -N255 --warn=-3 --asmlist -DXPRJ_default=default --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%f:%l: error: (%n) %s" "--warnformat=%f:%l: warning: (%n) %s" "--msgformat=%f:%l: advisory: (%n) %s" -obuild/default/debug/Led.p1 Led.c
Led.c:39: error: (192) undefined identifier "_XTAL_FREQ"
make[2]: *** [build/default/debug/Led.p1] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
(908) exit status = 1
nbproject/Makefile-default.mk:91: recipe for target 'build/default/debug/Led.p1' failed
make[2]: Leaving directory 'C:/Users/Meta/MPLABXProjects/Led_16F88_C.X'
nbproject/Makefile-default.mk:84: recipe for target '.build-conf' failed
make[1]: Leaving directory 'C:/Users/Meta/MPLABXProjects/Led_16F88_C.X'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed

BUILD FAILED (exit value 2, total time: 2s)
 
reviz esto...
Led.c:39: error: (192) undefined identifier "_XTAL_FREQ"

algo no esta bien con ese parametro

quizas revizando la libreria xc.h
 
Hola.
Creo que el fallo viene porque has puesto:
#define XTAL_FREQ 4000000 // Cuarzo 4 Mhz.
y hay que poner:
#define _XTAL_FREQ 4000000 // Cuarzo 4 Mhz.

con el guion bajo antes de XTAL_FREQ

Saludos
 
Funciona como dices.

Código:
#include <xc.h>
#define _XTAL_FREQ 4000000 // Cuarzo 4 Mhz.

void main(void) {
    TRISB = 0b00000000; // Puerto B como salida.
    PORTB = 0;          // Limpiamos puerto B.
    
    while(1)
    {
        PORTBbits.RB1 = 1; 
        __delay_ms(20);    
        PORTBbits.RB1 = 0; 
        __delay_ms(20);
    }
}

Al menos me compila, ahora a comprobar en el simulador de MPLAB X.
 
Arriba