Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Problem with PIC16F876A - LED Blink

Status
Not open for further replies.

amith.srivatsa

Junior Member level 1
Joined
Aug 7, 2009
Messages
17
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Germany
Activity points
1,494
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.
 

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.
 

Please attach your sch,
I think you have hardware problem...
regards
 

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?
 

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.
 

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:


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...
 
Last edited by a moderator:

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.
 

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 ???
 

Are you sure the voltage regulator pins connected correctly? Measured it?
 

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...
 

What is the voltage across VDD/VSS of PIC KIT 2? What is the minimum voltage for VDD of the microcontroller?
 

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.
 

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.
 

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.
 

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.
 

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.
 

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 ;)
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top