I'm running a Hello World that toggles RB7:

#include <p16f1509.inc>
    __config _CONFIG1, _FOSC_INTOSC

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

rst code 0x00

    clrf    PORTB
    banksel TRISB
    clrf    TRISB

    banksel ANSELB
    clrf    ANSELB

    movlw   0x80
    movwf   PORTB

    banksel ledState
    movlw   0x00
    movwf   ledState

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

    delay32 d'2500'

    goto loop

    movlw   0xFF

    addwf   delay0, F
    btfsc   STATUS, C

    addwf   delay1, F
    btfsc   STATUS, C

    addwf   delay2, F
    btfsc   STATUS, C

    addwf   delay3, F
    btfsc   STATUS, C

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

    btfss   STATUS, Z
    goto    doDelay32
    retlw   0


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?

  • \$\begingroup\$ 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). \$\endgroup\$ – Tom Carpenter Jul 17 '15 at 0:57
  • 3
    \$\begingroup\$ 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. \$\endgroup\$ – rdtsc Jul 17 '15 at 1:20
  • \$\begingroup\$ 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? \$\endgroup\$ – tcrosley Jul 17 '15 at 4:16

This is most likely due to the watchdog timer (WDT) resetting your chip. The WDT is enabled by default in all PICs, so you must explicitly disable it if you don't have specific instructions in your code to clear the timer. See section 9 in your datasheet for more information about the WDT.

The WDT is configured in the CONFIG1 register, so it will become part of your "__config CONFIG1" line of code.

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".

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.