electronics forum

Rules | Recent posts | topic RSS | Search | Register  | Log in

Problem with PIC16F876A - LED Blink


Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers -> Problem with PIC16F876A - LED Blink
Author Message
amith.srivatsa



Joined: 07 Aug 2009
Posts: 16
Location: Germany


Post28 Sep 2009 18:06   

Problem with PIC16F876A - LED Blink


Hello everyone,

I am still a beginner in Microcontroller programming. I want to make LED blink using a simple C code - using PIC16F876A, compiled in CCS.

The code is:
Code:

##include <16F876A.H>
#fuses HS,NOWDT, NOPROTECT, NOBROWNOUT, PUT,NOCPD,NOPUT
#use delay(clock=1000000)
   
//====================================
void main(){

while(1)
  {
   output_high(PIN_C5);
   delay_ms(1000);
   output_low(PIN_C5);
   delay_ms(1000);
  }
}


My problem is that: The LED is blinking perfectly when I power up using PIC KIT 2. But, when I power up using my circuit, it doesn't blink. I am using 8MHz crystal (HS mode). Also, I have connected MCLR - Pin No. 1 to VDD through a voltage divider.

Is there anything else I have forgotten to do ? Any help/suggestions would be greatly appreciated.
Back to top
Google
AdSense
Google Adsense




Post28 Sep 2009 18:06   

Ads




Back to top
betwixt



Joined: 04 Jul 2009
Posts: 386
Helped: 63
Location: Wales, UK


Post28 Sep 2009 19:50   

Re: Problem with PIC16F876A - LED Blink


MCLR should not go to a voltage divider, connect it only to VCC through a resistor.

You may also have LVP mode enabled (Low Voltage Programming). It is enabled by default on these devices but you can turn it off in the configuration word. You probably have the PGM pin pulled to ground by the PICKIT2 but with it disconnected it will float high. Connect it to ground through a resistor of say 4700Ω so it stays low but can still be safely driven high if you need to reprogram the chip.

Brian.
Back to top
pasicr



Joined: 13 Aug 2005
Posts: 295
Helped: 9
Location: Macedonia


Post28 Sep 2009 22:09   

Re: Problem with PIC16F876A - LED Blink


Please attach your sch,
I think you have hardware problem...
regards
Back to top
Somphorn



Joined: 04 Sep 2009
Posts: 37
Helped: 1
Location: Johore, Malaysia


Post29 Sep 2009 1:37   

Problem with PIC16F876A - LED Blink


Your code indicate 1MHz clock. But when you use 8MHz in your circuit, wouldn't that make the blinking so rapid that it's indistinguishable?
Back to top
betwixt



Joined: 04 Jul 2009
Posts: 386
Helped: 63
Location: Wales, UK


Post29 Sep 2009 7:02   

Re: Problem with PIC16F876A - LED Blink


Even at 8MHz it would only flash four times a second so that isn't the problem. I'm pretty sure it's the PGM pin being high. When LVP mode (the default) is enabled the pin becomes the programming enable input and if it floats high, the program execution is suspended and it enters programming mode. The PICKIT normally pulls it high to program the chip then pulls it low afterward. My guess is that removing the PICKIT is let it float and hence stop running.

Brian.
Back to top
amith.srivatsa



Joined: 07 Aug 2009
Posts: 16
Location: Germany


Post29 Sep 2009 10:33   

Re: Problem with PIC16F876A - LED Blink


Hello,

Just now I have modified the following: (But still LED doesn't blink)
Code:

#include <16F876A.H>
#fuses HS,NOWDT, NOPROTECT, NOBROWNOUT, PUT,NOCPD,NOPUT,NOLVP
#use delay(clock=8000000)
   
//====================================
void main(){

while(1)
  {
   output_high(PIN_C5);
   delay_ms(1000);
   output_low(PIN_C5);
   delay_ms(1000);
  }
}


Here is the schematic:
[img]
Problem with PIC16F876A - LED Blink
[/img]

As suggested, I also connected MCLR to VDD using only a resistor, Have changed the configuration word so that LVP is disabled. Also, I have connected the PGM pin to ground through a resistor. Still doesn't work.

Should I also do something with the PGD, PGC pins ??? Am I still missing something ?

I am using a 12V battery, & so I have a voltage regulator giving me the required 5V. I don't see any problems in this but still thought of mentioning.

Any help would be great for me...

Added after 2 minutes:

Just realized that the schematic in my previous msg has a resistor missing between PGM & Ground. I have this connected on my board though...
Back to top
Somphorn



Joined: 04 Sep 2009
Posts: 37
Helped: 1
Location: Johore, Malaysia


Post29 Sep 2009 13:03   

Problem with PIC16F876A - LED Blink


If /MCLR for this chip is equivalent to RST for AT89S51 then I suggest putting a capacitor (100uF) between /MCLR and ground. Maintain R 1K as it is. The idea is to give time for the oscillator to stabilize while /MCLR is pulled low.

I got the same problem once, using AT89S51. I'm not sure whether the capacitor will help in your situation but it's worth a try.
Back to top
amith.srivatsa



Joined: 07 Aug 2009
Posts: 16
Location: Germany


Post29 Sep 2009 14:04   

Re: Problem with PIC16F876A - LED Blink


Hello,

I am guessing I have narrowed down the problem to just something to do with power supply. I have the circuit on my board & when I just connect it to VDD & VSS in the PIC KIT 2, everything works, BUT; why is it not working with my battery ???
Back to top
Somphorn



Joined: 04 Sep 2009
Posts: 37
Helped: 1
Location: Johore, Malaysia


Post29 Sep 2009 14:32   

Problem with PIC16F876A - LED Blink


Are you sure the voltage regulator pins connected correctly? Measured it?
Back to top
amith.srivatsa



Joined: 07 Aug 2009
Posts: 16
Location: Germany


Post29 Sep 2009 14:38   

Re: Problem with PIC16F876A - LED Blink


Yes, I have 4.6 volts across the output of the voltage regulator. Also, I tried to power up using a 5V battery, still no luck. But when connected to VDD & VSS of PIC KIT 2, still works...
Back to top
Somphorn



Joined: 04 Sep 2009
Posts: 37
Helped: 1
Location: Johore, Malaysia


Post29 Sep 2009 14:42   

Problem with PIC16F876A - LED Blink


What is the voltage across VDD/VSS of PIC KIT 2? What is the minimum voltage for VDD of the microcontroller?
Back to top
amith.srivatsa



Joined: 07 Aug 2009
Posts: 16
Location: Germany


Post29 Sep 2009 14:48   

Re: Problem with PIC16F876A - LED Blink


Across VDD & VSS, I have given 4.5 V. It works for lower voltages too.

The minimum voltage would be 2.5V - LED blinking at this voltage when powered across VDD & VSS of PIC KIT 2.

But for programming i.e. to download the *.hex file onto the chip, we need a minimum of 4.5V.
Back to top
Somphorn



Joined: 04 Sep 2009
Posts: 37
Helped: 1
Location: Johore, Malaysia


Post29 Sep 2009 14:52   

Re: Problem with PIC16F876A - LED Blink


If you're convinced it is the power supply problem, and as you mentioned the voltage regulator is working fine then I really don't know how else to figure this out.

Apart from the schematic I think it would help if you could show the actual PCB/stripboard layout. Sometimes in an attempt to simplify the copper routing we end up shorting or put the components in wrong order.
Back to top
betwixt



Joined: 04 Jul 2009
Posts: 386
Helped: 63
Location: Wales, UK


Post29 Sep 2009 22:20   

Re: Problem with PIC16F876A - LED Blink


If your schematic is correct, you are missing decoupling capacitors.

Try connecting two capacitors 1 x 10uF and 1x 100nF in parallel, directly across the VSS & VDD pins and as close as possible to the chip. Without them the clock may not be stable and there is a risk of noise on the supply pins causing a reset or crash in your program.

Brian.
Back to top
Somphorn



Joined: 04 Sep 2009
Posts: 37
Helped: 1
Location: Johore, Malaysia


Post30 Sep 2009 4:02   

Problem with PIC16F876A - LED Blink


Perhaps 5V supply from your PC's PSU (red & black) is stable enough.
Back to top
amith.srivatsa



Joined: 07 Aug 2009
Posts: 16
Location: Germany


Post01 Oct 2009 12:04   

Re: Problem with PIC16F876A - LED Blink


Hello guys,
I am really stumped with this problem. Have been stuck with it for quite sometime now. I also have the capacitors across VDD & VSS, but still, doesnt work. Although the LED blinks promptly when powered using PIC KIT 2.
Back to top
kroko



Joined: 23 Feb 2009
Posts: 2
Location: croatia


Post01 Oct 2009 19:23   

Re: Problem with PIC16F876A - LED Blink


Just change resistor R2 to 470 or 330 ohm. It should work.

cheers

Added after 6 minutes:


Also remove ground from RB3. Sorry I noticed this after sending message.
Back to top
emergenbernz



Joined: 04 Jun 2009
Posts: 3
Location: Philippines


Post02 Oct 2009 5:04   

Re: Problem with PIC16F876A - LED Blink


Try to use another PIC16F876 if kroko's suggestion won't work.
Back to top
eanema



Joined: 30 Sep 2009
Posts: 8


Post02 Oct 2009 6:08   

Re: Problem with PIC16F876A - LED Blink


ok, I could be way off on this, but I just recently fixed a very similar problem I was having when trying to program a pic18f4550 with an ICD2 clone. It turns out that the problem I was having was that I was programing the pic in debug mode, meaning I was able to step through the code, run it halt it etc. If you want to run your code on your chip with out the programmer/debugger attached, you need to program the PIC with the debugger set up as a programmer. To do this select your pickit2 from the programmer menu instead of from the debugger menu.

Hope this helps, know I had to search for it Wink
Back to top
Arabic versionBulgarian versionCatalan versionCzech versionDanish versionGerman versionGreek versionEnglish versionSpanish versionFinnish versionFrench versionHindi versionCroatian versionIndonesian versionItalian versionHebrew versionJapanese versionKorean versionLithuanian versionLatvian versionDutch versionNorwegian versionPolish versionPortuguese versionRomanian versionRussian versionSlovak versionSlovenian versionSerbian versionSwedish versionTagalog versionUkrainian versionVietnamese versionChinese version
Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers -> Problem with PIC16F876A - LED Blink
Page 1 of 1 All times are GMT + 1 Hour
Similar topics:
interface pic16f876a with another pic16f876a (1)
Led Blink using PIC (2)
at91rm9200 blink led start MCU (41)
How can pic16f84a blink a led without external oscillator (11)
PIC16F876A-I/SP programming Problem!! (12)
interrupt with pic16f876a (4)
!!!PIC16F876A interfacing with Bluetooth headset!!! (2)
Can pic16f876 be replaced with pic16f876A? (2)
LED MATRIX 16x40 - problem with a scrolling sentence (4)
Problem with LED MESSAGE display from www.woe.de.vu (11)


Abuse || Administrator || Moderators || Support us || sitemap
topic RSS