logo elektroda
logo elektroda
X
logo elektroda

PIC12f629 LED Not Lighting Using XC8 MPLAB X, Microbrn, K150 Programmer

393 19
ADVERTISEMENT
  • #1 21669896
    Sean Ulyate
    Anonymous  
  • ADVERTISEMENT
  • #2 21669897
    Geoff Lancaster
    Anonymous  
  • #3 21669895
    Geoff Lancaster
    Anonymous  
  • ADVERTISEMENT
  • #4 21669898
    RAJENDRA BHATT
    Anonymous  
  • #5 21669899
    Geoff Lancaster
    Anonymous  
  • #6 21669900
    RAJENDRA BHATT
    Anonymous  
  • #7 21669901
    Mark Harrington
    Anonymous  
  • #8 21669902
    Geoff Lancaster
    Anonymous  
  • ADVERTISEMENT
  • #9 21669903
    Geoff Lancaster
    Anonymous  
  • #10 21669904
    Syed Shadab
    Anonymous  
  • #11 21669905
    Geoff Lancaster
    Anonymous  
  • #12 21669906
    Geoff Lancaster
    Anonymous  
  • #13 21669907
    Mark Harrington
    Anonymous  
  • #14 21669908
    Mark Harrington
    Anonymous  
  • #15 21669909
    Geoff Lancaster
    Anonymous  
  • #16 21669910
    Mark Harrington
    Anonymous  
  • #17 21669911
    Mark Harrington
    Anonymous  
  • #18 21669912
    Mark Harrington
    Anonymous  
  • #19 21669913
    zubair ahmed
    Anonymous  
  • ADVERTISEMENT
  • #20 21669914
    zubair ahmed
    Anonymous  

Topic summary

✨ The discussion addresses an issue with lighting an LED using a PIC12F629 microcontroller programmed via MPLAB X and the XC8 compiler, with Microbrn and a K150 programmer. The main problem is that the LED connected to GP0 does not illuminate despite setting GP0 high in code. Key troubleshooting steps include correctly configuring the TRISIO register to set GP0 as an output (TRISIO bit 0 = 0), disabling analog functions by clearing ANSEL (though this caused compilation errors due to undefined identifier), and disabling the comparator by setting CMCON. The importance of loading the OSCCAL calibration value from the chip to ensure proper oscillator operation was emphasized, as failure to do so can cause erratic behavior. Suggestions also included verifying that GP3 is input-only and not used as output, checking for port failures, and ensuring no conflicting compilers are in the system path. Debugging via MPLAB's simulator was recommended to observe register states and pin outputs. Alternative approaches such as using MikroC Pro for PIC and writing in assembler were proposed. Sample code snippets were shared to initialize GPIO, disable analog inputs, and set GP0 high in an infinite loop. The discussion also touched on fuse settings and configuration bits necessary for proper device operation. Overall, the resolution involves proper pin direction setup, disabling analog inputs and comparators, loading oscillator calibration, and careful debugging to confirm hardware and software correctness.

FAQ

TL;DR: On a PIC12F629, only 5 of 6 GPIOs can drive LEDs, and you must set TRISIO and disable comparators; “The exception is GP3, which is input only.” [Elektroda, Mark Harrington, post #21669907]

Why it matters: This FAQ helps beginners fix the exact XC8/MPLAB X/K150 issues that keep a simple LED from lighting on the PIC12F629.

Quick Facts

How do I fix “LED on GP0 won’t light” on PIC12F629 with XC8?

Configure pins as digital outputs, disable the comparator, then set GP0 high. Example: TRISIO=0b00001000; CMCON=0b00000111; GPIO=0; while(1){GP0=1;} This matches working snippets shared by members and ensures GP0 is driven as an output. [Elektroda, RAJENDRA BHATT, post #21669898]

Why does ANSEL cause an “undefined identifier” compile error?

PIC12F629 does not define ANSEL. That register appears on related devices, so XC8 reports “undefined identifier ANSEL.” Remove the ANSEL line and rely on CMCON and TRISIO for digital configuration on the 12F629. [Elektroda, Geoff Lancaster, post #21669905]

Which pins on PIC12F629 can actually drive an LED?

Use GP0, GP1, GP2, GP4, and GP5. Do not use GP3; it is input-only on this device. Quote: “The exception is GP3, which is input only.” This is a common beginner pitfall. [Elektroda, Mark Harrington, post #21669907]

Do I need to set TRISIO before writing to GP0?

Yes. Set the TRISIO bit for GP0 to 0 to make it an output. A concise init looks like TRISIO=0b00001000 and GPIO=0 to start low. Then write GP0=1 in the loop to turn the LED on. [Elektroda, Sean Ulyate, post #21669896]

What’s the minimum setup to ensure digital I/O works on 12F629?

Disable the comparator and configure outputs. Three steps: 1) CMCON=0b00000111; 2) TRISIO=0b00001000; 3) GPIO=0, then set GPx as needed. This avoids analog or comparator interference with GPIO. [Elektroda, RAJENDRA BHATT, post #21669898]

Why mention OSCCAL, and how do I load it?

OSCCAL calibrates the internal oscillator. Load the value from address 0x3FF at reset, and record it before programming to prevent odd timing issues. “Always read this chip first before attempting to write.” [Elektroda, Mark Harrington, post #21669901]

MPLAB X debugger: simulator or real-hardware for this PIC?

Use the simulator. It lets you step through assembly, watch registers, and verify pin logic changes without hardware. That helps confirm TRISIO, CMCON, and GPIO behavior before reprogramming the device. [Elektroda, Mark Harrington, post #21669910]

Could this be a compiler or IDE path problem?

It can be. Conflicting compiler versions in PATH or a problematic MPLAB X/XC8 install can cause strange results. Members fixed issues by checking PATH or reinstalling the IDE and compiler cleanly. [Elektroda, Mark Harrington, post #21669907]

Does my K150/MicroBrn setup work if a flashing HEX blinks the LED?

Yes. If a downloaded HEX blinks the LED after programming with MicroBrn and K150, your programmer and wiring are proven. Focus on project configuration and code init for your own build. [Elektroda, Geoff Lancaster, post #21669895]

What’s a safe, simple 3‑step How‑To to light an LED on GP0?

  1. CMCON=0b00000111 to disable the comparator. 2. TRISIO=0b00001000; GPIO=0. 3. while(1){GP0=1;} Use a series resistor and avoid GP3. [Elektroda, RAJENDRA BHATT, post #21669898]

I set all outputs high but one pin doesn’t change—what gives?

You may be toggling GP3, which is input-only, or a pin is misconfigured in TRISIO. Also check interrupt-on-change and weak pull-ups. Edge case: a damaged port pin can fail. [Elektroda, Mark Harrington, post #21669907]

Do I need to worry about fuses (config bits) for a simple LED test?

Yes. Set fuses consistently (e.g., internal RC, watchdog off if unused, MCLRE per wiring). Incorrect fuses can prevent expected I/O behavior and timing. Review and set them before testing. [Elektroda, Mark Harrington, post #21669910]

Is there a known working code pattern I can copy into XC8?

Use the shared pattern: disable comparator, set TRISIO, clear GPIO, then set GP0 high in a loop. This exact sequence has been confirmed by contributors. “Disable comparator.” [Elektroda, RAJENDRA BHATT, post #21669898]

What clock value should I assume for delays on 12F629?

Assume 4 MHz internal RC unless you changed fuses. Example code sets _XTAL_FREQ to 4,000,000 for delay macros. Pair this with a valid OSCCAL load for accuracy. [Elektroda, zubair ahmed, post #21669913]

Can switching to another IDE/compiler help diagnose this?

Some users tested with MikroC or assembler to isolate issues. If alternate toolchains work with the same hardware, focus on your MPLAB X/XC8 setup and configuration bits. [Elektroda, Syed Shadab, post #21669904]

What’s the fastest sanity check before diving deeper?

Confirm you’re using GP0/1/2/4/5, not GP3. Then set TRISIO correctly and disable the comparator. If that fails, verify OSCCAL and configuration bits. [Elektroda, Sean Ulyate, post #21669896]
ADVERTISEMENT