Problema con PIC16F15345

Hola y buenas. Tengo un problema con la programación de este uC PIC16F15345
No he logrado hacer que prenda y apague un LED, he programado los PIC16F628, PIC16F877 y varios modelos antiguos, pero no he podido programar correctamente este.
¿Podrían ayudarme por-favor? Gracias.

Este es el código que tengo:
C:
// PIC16F15345 Configuration Bit Settings
// 'C' source line config statements

// CONFIG1
#pragma config FEXTOSC = OFF    // External Oscillator mode selection bits (Oscillator not enabled)
#pragma config RSTOSC = HFINT1  // Power-up default value for COSC bits (HFINTOSC (1MHz))
#pragma config CLKOUTEN = OFF   // Clock Out Enable bit (CLKOUT function is disabled; i/o or oscillator function on OSC2)
#pragma config CSWEN = OFF      // Clock Switch Enable bit (The NOSC and NDIV bits cannot be changed by user software)
#pragma config FCMEN = OFF      // Fail-Safe Clock Monitor Enable bit (FSCM timer disabled)

// CONFIG2
#pragma config MCLRE = ON       // Master Clear Enable bit (MCLR pin is Master Clear function)
#pragma config PWRTE = OFF     // Power-up Timer Enable bit (PWRT enabled)
#pragma config LPBOREN = OFF    // Low-Power BOR enable bit (ULPBOR disabled)
#pragma config BOREN = ON       // Brown-out reset enable bits (Brown-out Reset Enabled, SBOREN bit is ignored)
#pragma config BORV = LO        // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (VBOR) set to 1.9V on LF, and 2.45V on F Devices)
#pragma config ZCD = OFF        // Zero-cross detect disable (Zero-cross detect circuit is disabled at POR.)

#pragma config PPS1WAY = OFF   // Peripheral Pin Select one-way control (The PPSLOCK bit can be cleared and set only once in software)
#pragma config STVREN = OFF     // Stack Overflow/Underflow Reset Enable bit (Stack Overflow or Underflow will cause a reset)

// CONFIG3
#pragma config WDTCPS = WDTCPS_31// WDT Period Select bits (Divider ratio 1:65536; software control of WDTPS)
#pragma config WDTE = OFF       // WDT operating mode (WDT Disabled, SWDTEN is ignored)
#pragma config WDTCWS = WDTCWS_7// WDT Window Select bits (window always open (100%); software control; keyed access not required)
#pragma config WDTCCS = SC      // WDT input clock selector (Software Control)

// CONFIG4
#pragma config BBSIZE = BB512   // Boot Block Size Selection bits (512 words boot block size)
#pragma config BBEN = OFF       // Boot Block Enable bit (Boot Block disabled)
#pragma config SAFEN = OFF      // SAF Enable bit (SAF disabled)
#pragma config WRTAPP = OFF     // Application Block Write Protection bit (Application Block not write protected)
#pragma config WRTB = OFF       // Boot Block Write Protection bit (Boot Block not write protected)
#pragma config WRTC = OFF       // Configuration Register Write Protection bit (Configuration Register not write protected)
#pragma config WRTSAF = OFF     // Storage Area Flash Write Protection bit (SAF not write protected)
#pragma config LVP = OFF        // Low Voltage Programming Enable bit (Low Voltage programming enabled. MCLR/Vpp pin function is MCLR.)

#define _XTAL_FREQ 1000000

// CONFIG5
#pragma config CP = OFF         // UserNVM Program memory code protection bit (UserNVM code protection disabled)
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

#include <xc.h>

void main(void) {
  TRISB = 0x00;
  ANSELB = 0x00;
  ODCONB = 0x00;
  SLRCONB = 0x00;
    INLVLB = 0x00;
    PORTB= 0xFF;

    __delay_ms(2000);

    while(1){
       PORTB = 0xFF;
      __delay_ms(200);
      PORTB = 0x00;
      __delay_ms(200);
    }
    return;
}
 
Última edición por un moderador:
Gracias por la edicion.
Otro detalle, no estoy utilizando cristal externo, es el interno.
El mplab programa bien el micro porque lo verifica correctamente.
 
No sé por qué me da la impresión que copiaste los fuses son checar.

Ahí veo que está declarado oscilador externo. 🤷🏽‍♂️
C:
pragma config FEXTOSC = OFF    // External Oscillator mode selection bits (Oscillator not enabled)
El código de pragma te lo genera el MPLAB con una función de configuración de bits.
Configuras oscilador y otras funciones, y este te arroja un texto para copiar y pegar dentro del programa main o en un archivo de cabecera.
 
Última edición por un moderador:
Si tienes osciloscopio, incluso se puede habilitar la salida del reloj por el pin correspondiente y saber si esta oscilando.

Habilitando la siguiente línea:

C:
#pragma config CLKOUTEN = OFF   // Clock Out Enable bit (CLKOUT function is disabled; i/o or oscillator function on OSC2)
 
Atrás
Arriba