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
- PIC12F629: GP3 is input-only; use GP0/1/2/4/5 for LEDs. [Elektroda, Mark Harrington, post #21669907]
- Set outputs with TRISIO=0b00001000; then drive pins via GPIO/GPx. [Elektroda, Sean Ulyate, post #21669896]
- Disable the comparator (CMCON=0b00000111) before using digital I/O. [Elektroda, RAJENDRA BHATT, post #21669898]
- No ANSEL register on 12F629; “undefined identifier ANSEL” is expected. [Elektroda, Geoff Lancaster, post #21669905]
- Load OSCCAL from 0x3FF and note the value before programming. [Elektroda, Mark Harrington, post #21669901]
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?
- 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]