logo elektroda
logo elektroda
X
logo elektroda

PIC16F1779 not running code after programming with MPLABX and PICKit3, MPASM code

204 20
Best answers

Why does my PIC16F1779 program verify after programming with MPLABX and PICkit3 but appear to do nothing when it runs?

Your PIC16F1779 code was not running because MPLABX v3.15 assembled the `MOVLB` instruction incorrectly for that device, so bank switching never happened and the code kept accessing bank 0 instead of the intended SFR banks [#21679507] Single-stepping showed that `BSR` did not change after `MOVLB`, and the generated opcode was `h'014n'` instead of the correct `h'002n'`; replacing `MOVLB bank_no` with `movlw bank_no` / `movwf BSR` made the test program work immediately [#21679507] The same bad encoding was confirmed on the PIC16F1777/1778/1779 parts, while 1773/1776 assembled correctly [#21679510] Installing MPLABX v3.65 fixed the assembler for the PIC16F1779, and the application then ran normally [#21679511]
Generated by the language model.
ADVERTISEMENT
  • #1 21679491
    Paul Bowden
    Anonymous  
  • ADVERTISEMENT
  • #2 21679492
    Elizabeth Simon
    Anonymous  
  • #3 21679493
    Rick Curl
    Anonymous  
  • #4 21679494
    Paul Bowden
    Anonymous  
  • #5 21679495
    Paul Bowden
    Anonymous  
  • #6 21679496
    Paul Bowden
    Anonymous  
  • #7 21679497
    Mike Hibbett
    Anonymous  
  • ADVERTISEMENT
  • #8 21679498
    Rick Curl
    Anonymous  
  • #9 21679499
    Rick Curl
    Anonymous  
  • #10 21679500
    Paul Bowden
    Anonymous  
  • ADVERTISEMENT
  • #11 21679501
    Aubrey Kagan
    Anonymous  
  • #12 21679502
    Paul Bowden
    Anonymous  
  • #13 21679503
    Peter White
    Anonymous  
  • ADVERTISEMENT
  • #14 21679504
    Peter White
    Anonymous  
  • #15 21679505
    Paul Bowden
    Anonymous  
  • #16 21679506
    Mike Hibbett
    Anonymous  
  • #17 21679507
    Paul Bowden
    Anonymous  
  • #18 21679508
    Rick Curl
    Anonymous  
  • #19 21679509
    Paul Bowden
    Anonymous  
  • #20 21679510
    Paul Bowden
    Anonymous  
  • #21 21679511
    Paul Bowden
    Anonymous  

Topic summary

✨ A user experienced an issue where a PIC16F1779 microcontroller programmed with MPASM code via MPLABX and PICKit3 would not execute the code despite successful programming and verification. The oscillator functioned correctly, and pins remained in their default high-impedance state without toggling as expected. The same code worked on a PIC16F1789 device. Troubleshooting steps included verifying correct TRIS, PORT, LAT, and ANSEL register settings, disabling MCLR and low-voltage programming (LVP), checking power and ground connections, and ensuring no peripherals conflicted with the toggled pins. Debugging revealed that the MOVLB instruction, used to switch register banks, was incorrectly assembled by the MPLABX assembler in version 3.15 for the PIC16F1779, generating an invalid opcode (0x014n instead of 0x002n). This caused bank switching to fail, preventing proper register access and program execution. Workarounds included replacing MOVLB with MOVLW and MOVWF BSR instructions. Attempts to upgrade MPLABX to version 4.15 failed on the user's Windows XP system, but version 3.65 installed successfully and contained the corrected assembler behavior for MOVLB. After switching to MPLABX v3.65, the code assembled correctly, and the PIC16F1779 ran the program as expected. The issue was traced to a Microchip assembler bug affecting the PIC16F1777/78/79 devices in the enhanced PIC16F1XXX family, where MOVLB was wrongly encoded. This problem did not affect other family members like PIC16F1773/76. The discussion highlights the importance of verifying assembler output and toolchain versions when encountering unexpected device behavior.
Generated by the language model.

FAQ

TL;DR: On PIC16F177x, 60% of tested parts assembled MOVLB incorrectly in MPASM v3.15; “Microchip appear to have really messed up.” Update to MPLAB X v3.65 or replace MOVLB with MOVLW/MOVWF BSR. [Elektroda, Anonymous, post #21679510]

Why it matters: If your PIC16F1779 "programs fine but does nothing," this pinpoints the toolchain bug and the fix, fast.

Quick-Facts

Quick Facts

How do I fix a PIC16F1779 that verifies but then does nothing after programming?

Update your toolchain. MPLAB X v3.65 assembles MOVLB correctly for PIC16F177x and resolved the “runs nothing” symptom in this case. If you cannot update immediately, replace MOVLB with MOVLW/MOVWF BSR as a stopgap. After updating, the original code ran without changes. [Elektroda, Anonymous, post #21679511]

What was the root cause in this thread?

MPASM assembled MOVLB to 0x014n instead of 0x002n, so BSR never changed banks. Writes to TRIS, LAT, ANSEL, and OSCCON targeted the wrong bank, leaving pins Hi‑Z and clocks at defaults. “MOVLB was completely ignored.” [Elektroda, Anonymous, post #21679507]

Which PIC16F177x devices showed the MOVLB opcode issue?

A short build test showed: 16F1773 and 16F1776 correct; 16F1777, 16F1778, and 16F1779 wrong. That is 3 of 5 devices affected. [Elektroda, Anonymous, post #21679510]

What’s a quick workaround if I can’t edit many files?

Replace each MOVLB bank instruction with MOVLW bank followed by MOVWF BSR. It works immediately but is impractical for large codebases or libraries. Use it only to unblock testing. [Elektroda, Anonymous, post #21679509]

How can I confirm whether my code is actually running on-chip?

Use MPLAB X with PICkit 3 to single‑step and watch SFRs. Check BSR while executing MOVLB. If BSR doesn’t change, you’re hitting the assembler bug. Then manually set BSR and observe pins toggling. [Elektroda, Anonymous, post #21679507]

Why are my pins stuck in Hi‑Z or reading analog?

ANSELx defaults to analog on POR. Clear ANSEL registers to enable digital GPIO, then set TRIS/LAT as needed. Without this, outputs won’t drive and inputs read analog. [Elektroda, Anonymous, post #21679506]

Why won’t the internal oscillator change when I write OSCCON?

If MOVLB is wrong, your OSCCON write hits the wrong bank. The device stays at its 500 kHz POR frequency, making it look unresponsive. Fix MOVLB or set BSR correctly. [Elektroda, Anonymous, post #21679500]

Should I disable MCLR or LVP while debugging?

You can disable MCLR in CONFIG if needed. If MCLR is enabled, use a pull‑up. Ensure LVP is off unless you require it. These settings avoided false resets here. [Elektroda, Anonymous, post #21679494]

Could wiring or power cause the "programs but doesn’t run" symptom?

Verify both VDD and both VSS are connected and decoupled. Keep ICSP leads short and stable. If powering from the programmer, raise target V slightly. Poor grounding or long leads can complicate debugging. [Elektroda, Anonymous, post #21679497]

What is MPASM, MOVLB, and BSR in plain English?

MPASM is Microchip’s assembly tool. MOVLB selects a memory bank. BSR is the Bank Select Register that MOVLB should update. If MOVLB encodes wrong, BSR stays unchanged and your SFR writes miss. [Elektroda, Anonymous, post #21679507]

Which MPLAB X versions and OS details mattered here?

MPLAB X v3.15 showed the MPASM error on 16F177x. MPLAB X v3.65 fixed MOVLB. MPLAB X v4.15 didn’t install on the user’s Windows XP, so they stayed on v3.65. [Elektroda, Anonymous, post #21679511]

What is ANSEL and why must I clear it?

ANSEL controls analog mode per pin. On POR, many pins default to analog. Clear relevant ANSELx bits to use pins as digital GPIO. “You do have to turn that ‘off’ to get GPIO functionality.” [Elektroda, Anonymous, post #21679506]

How can I quickly test if any pins are actually toggling?

Declare several pins as outputs and toggle them all. If none move, suspect bank selection or configuration prevents writes from reaching LAT/PORT. This isolated the issue here. [Elektroda, Anonymous, post #21679499]

Can PICkit 3 report a good verify while the MCU still does nothing?

Yes. Programming and verify can pass while the app never leaves POR‑like behavior due to mis‑assembled MOVLB and incorrect banked SFR writes. [Elektroda, Anonymous, post #21679491]

Give me a 3‑step way to diagnose the MOVLB/BSR issue fast.

  1. Single‑step MOVLB while watching BSR in the debugger.
  2. If BSR stays unchanged, temporarily write BSR with MOVLW/MOVWF and retest.
  3. Rebuild with a toolchain that encodes MOVLB correctly. [Elektroda, Anonymous, post #21679507]
Generated by the language model.
ADVERTISEMENT