0
\$\begingroup\$

I have been playing around with the PIC16F628 for a while, and now I want to transfer to something that has more pins. Specifically the PIC16F876, but I can't get it working. I just want to turn an LED on/off and nothing ever happens. This is my circuit:

PIC 16F987 circuit

I program my PICs in the mikroC editor and these are the settings:

  • OSCILLATOR: HS
  • WATCHDOG: Disabled
  • POWER-UP TIMER: Disabled
  • FLASH code protection: Disabled
  • Brown-out reset: Enabled
  • Low voltage programming: Disabled
  • Flash program memory write: Enabled
  • In-circuit debug: Disabled

And this is my code:

void main(){
    TRISB = 0x00;
    while(1){
        PORTB = 0b11111111;
        delay_ms(500);
        PORTB = 0b00000000;
        delay_ms(500);
    }
}

And nothing works. I tried with 4.10 and 11 MHz oscillator values and nothing. What did I do wrong?

\$\endgroup\$
12
  • \$\begingroup\$ I assume "nothing works" means the LED does not even lit? Did you define your clock (something like #define F_CPU 10000000L) for 10MHz? The delay works from that definition. Though, you say it is 500ms, it might be longer/shorter. Can RB7 pin deliver enough current for the LED? You might need some buffer. Did you choose the correct resistor? \$\endgroup\$
    – Nazar
    Aug 6, 2015 at 11:55
  • 1
    \$\begingroup\$ Silly thought perhaps, but is the LED the right way around? \$\endgroup\$ Aug 6, 2015 at 12:18
  • 2
    \$\begingroup\$ ... Decoupling? \$\endgroup\$
    – Dzarda
    Aug 6, 2015 at 13:09
  • 1
    \$\begingroup\$ Does the program compile? \$\endgroup\$
    – DerStrom8
    Aug 6, 2015 at 13:20
  • 2
    \$\begingroup\$ I tried your code with all your settings on a 16F876 and it worked perfectly - even without a decoupling capacitor. Assuming your chip is not fried, the only thing I can think of is a wiring error. \$\endgroup\$ Aug 6, 2015 at 21:25

1 Answer 1

7
\$\begingroup\$

With the bypass cap missing, nothing else matters.

I'd also move the LED off of RB6 or RB7 since those are the programming and debugging lines. You won't be able to use either of those pins while debugging. RB5 is a good choice. I don't understand why you'd use a pin multiplexed with anything else when all you're trying to do is test that code is running by seeing a LED blink.

Tie the PGM pin (RB3) to ground.

Don't forget to clear the TRIS bit for the pin you are using.

Test the code in the simulator first. There's no point trying it on hardware until the basic code is working correctly.

\$\endgroup\$

Your Answer

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

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