I was trying to do a LED flashing program, but the LED didn't turned on. I tried also with a program to just light the LED, but it didn't work either. I searched and one solution says to change the config bits, but also tried it and didn't work.

This is the XC8 code of the LED on program:

#include <xc.h>
void main(void) {
  TRISA = 0;
  while(true) {
    RA0 = 1;

Config bits are:


I'm runnng it without capacitors on the oscillator, but it also didn't work with 47pF capacitors. The source of voltage is an Arduino Mega, with the 5V and GND pins. MCLR is connected to 5V with a 10k resistor

  • 1
    \$\begingroup\$ What do you mean the pic didn’t run it? Do you mean the LED didn’t turn on? This is not the same. Stick a multimeter on the RA0 pin. Also, are you sure the LED is active high. Try putting RA0 = 0. \$\endgroup\$
    – user110971
    Commented Aug 31, 2020 at 21:43
  • 3
    \$\begingroup\$ CONFIG bits also contain FOSC1 and FOSC0. Of the four selections possible, a 4 MHz crystal requires FOSC0=high and FOSC1=low. This is oscillator "XT" mode. And have you tied not_MCLR pin to logic high? If it is low, nothing runs. \$\endgroup\$
    – glen_geek
    Commented Aug 31, 2020 at 22:04
  • \$\begingroup\$ Which compiler? How did you set the config bits? What did you do with the MCLR pin? \$\endgroup\$
    – Mike
    Commented Sep 1, 2020 at 4:44
  • \$\begingroup\$ @user110971 Thank you. RA0 has an output of 0.2V. How can I increase it? \$\endgroup\$ Commented Sep 1, 2020 at 14:44
  • \$\begingroup\$ 1. What model of programmer / flash loader are you using? 2. Do your IDE / any other software report that the firmware is loading successfully? \$\endgroup\$
    – Arseniy
    Commented Sep 1, 2020 at 14:46

1 Answer 1


I suspect that you are not turn off the ADC.

I mean when this MCU starts the ADCON1 register set to 00h. And bits PCFG3:PCFG0 are also 0000b. Thus, according the table on the pg.130 of the datasheet all pins in the port0 are analog inputs. This table tell us that we need set bits PCFG3:PCFG0 on 011Xb to use the port0 as digital input-output.

Try to add

ADCON1 = 6;


TRISA = 0;
  • \$\begingroup\$ With those changes, the most that I get from RA0 is 0.3V \$\endgroup\$ Commented Sep 1, 2020 at 16:01
  • \$\begingroup\$ Hmm. Try to use other pin or other port. Will the result change? Can you use an assembler in your IDE? Which IDE do you use? Do you have the Proteus-II to simulate your firmware? \$\endgroup\$
    – Arseniy
    Commented Sep 1, 2020 at 16:17
  • \$\begingroup\$ Now it works! But only when I touch the USB port. I thik it's because the static. \$\endgroup\$ Commented Sep 1, 2020 at 16:30
  • \$\begingroup\$ Its the static. I putted the protoboard and the arduino on a plastic table and it worked, but when i touched the arduino it stopped \$\endgroup\$ Commented Sep 1, 2020 at 16:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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