# PIC16 only runs on debugger

I'm running a Hello World that toggles RB7:

#include <p16f1509.inc>
__config _CONFIG1, _FOSC_INTOSC

udata
delay0  res 1
delay1  res 1
delay2  res 1
delay3  res 1
ledState res 1

delay32 macro delay
goto $+1 goto$+1

banksel delay3

movlw   (delay - 1) & 0xFF
movwf   delay0

movlw   (delay - 1) >> 0x08 & 0xFF
movwf   delay1

movlw   (delay - 1) >> 0x10 & 0xFF
movwf   delay2

movlw   (delay - 1) >> 0x18 & 0xFF
movwf   delay3

call    doDelay32
endm

rst code 0x00

start:
clrf    PORTB
banksel TRISB
clrf    TRISB

banksel ANSELB
clrf    ANSELB

movlw   0x80
movwf   PORTB

banksel ledState
movlw   0x00
movwf   ledState

loop:
banksel ledState
movf   ledState, 0
xorlw   0x80
movwf   ledState
movwf   PORTB

delay32 d'2500'

goto loop

doDelay32
movlw   0xFF

btfsc   STATUS, C
clrw

btfsc   STATUS, C
clrw

btfsc   STATUS, C
clrw

btfsc   STATUS, C
clrw

iorwf   delay0, W
iorwf   delay1, W
iorwf   delay2, W
iorwf   delay3, W

btfss   STATUS, Z
goto    doDelay32
retlw   0

end


This runs perfectly on the MPLABX debugger using a PicKit3, but does not run otherwise.

This appears to be a common problem, but a day of Googling has turned up nothing useful. Here's what I've learned:

1. Most people fail to pull MCLR high. I have a 10k between MCLR and VDD.

2. The clock config bit defaults to an exteral clock. Setting it to INTOSC didn't help.

3. Some people suggest setting the !DEBUG bit, but the data sheet claims that this is totally taken care of by the debugger. I tried it anyway; it didn't help.

Any suggestions would be appreciated. Thanks

Also: Does anybody know if it's possible to program a PIC using a Beaglebone's by connecting I2C to ICSPDAT and ICSPCLK?

• When you aren't running the debugger, have you released the MCU from reset to get it to run? Even with an external pull-up resistor, the PICKit will be pulling the reset pin low unless you allow it to run (either with Debug mode, or normal running). – Tom Carpenter Jul 17 '15 at 0:57
• There are ton of fuses you haven't defined yet, like whether or not the watchdog timer (WDT) is on. It probably defaults to on, and the PIC is resetting itself every few milliseconds. Or the brownout detect, if power from the debugger is "good" but your supply is slightly lower. You will end up going through everything with a fine-toothed comb... might as well start now. – rdtsc Jul 17 '15 at 1:20
• This is pretty basic, but have you re-compiled your program in Release mode rather then Debug mode, and then re-selected the the PICkit3 before before programming the microcontroller? – tcrosley Jul 17 '15 at 4:16

The screenshot below is from the datasheet showing the CONFIG1 register. Notice the default values for WDTE are $11_2$, which corresponds to "WDT Enabled".