I'm just getting started with PIC programming and I'm giving up already. I just want to make an LED blink! I'm working with a PIC16F1773, MPLABX IDE v4.05 and Pickit3.
These are the configuration bits that I've defined in a header file:
// CONFIG1
#pragma config FOSC = INTOSC // Oscillator Selection Bits (INTOSC oscillator: I/O function on CLKIN pin)
#pragma config WDTE = OFF // Watchdog Timer Enable (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable (PWRT disabled)
#pragma config MCLRE = OFF // MCLR Pin Function Select (MCLR/VPP pin function is digital input)
#pragma config CP = OFF // Flash Program Memory Code Protection (Program memory code protection is disabled)
#pragma config BOREN = OFF // Brown-out Reset Enable (Brown-out Reset disabled)
#pragma config CLKOUTEN = OFF // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin)
#pragma config IESO = OFF // Internal/External Switchover Mode (Internal/External Switchover Mode is disabled)
#pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is disabled)
// CONFIG2
#pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off)
#pragma config PPS1WAY = ON // Peripheral Pin Select one-way control (The PPSLOCK bit cannot be cleared once it is set by software)
#pragma config ZCD = OFF // Zero-cross detect disable (Zero-cross detect circuit is disabled at POR)
#pragma config PLLEN = ON // Phase Lock Loop enable (4x PLL is always enabled)
#pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset)
#pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
#pragma config LPBOR = OFF // Low-Power Brown Out Reset (Low-Power BOR is disabled)
#pragma config LVP = ON
#define _XTAL_FREQ 8000000 // INTOSC 8MHz
And this is the actual code:
#include <xc.h>
void main(void) {
OSCCON = 0x72;
TRISB = 0x00;
PORTBbits.RB0 = 0;
while (1) {
if (PORTBbits.RB0 == 0) {
PORTBbits.RB0 = 1;
}else {
PORTBbits.RB0 = 0;
}
// Delay for 1 sec
for (int count = 0; count < 20; count++) {
__delay_ms(50);
}
}
return;
}
I've defined the OSCCON register as 0x72 following the datasheet but nothing lights up. I'm measuring a constant voltage of 0.42V in RB0.
EDIT: The datasheet:
I'm powering the PIC through the Pickit3. RB0 is connected to a resistor in series to the LED and to ground.
What am I doing wrong?