pic16F877A not functioning

Thread Starter

daredavel

Joined Feb 22, 2010
32
the code is clean and running in proteus, but when i program it in my pic16f877a its not functioning..doesn't even output logic 1.. vdd/vss are connected correctly..but no reading from the output ports.. I can read/write in my pic..i think its not broken..
I even tested it to output 2 ports.. still no output..can't even lit an LED.. what could be possible wrong? Does it have to do with the CONFIG Osc? I'm using a 4MHz xtal osc..

Here's the CONFIG:
Rich (BB code):
__CONFIG   _CP_OFF & _WDT_OFF & _PWRTE_ON & _HS_OSC
Should i replace it with:
Rich (BB code):
__CONFIG   _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC
I'll consult it to you guys before i do anything..to avoid any damages to the my pic.. Thank you!!:D
 

Markd77

Joined Sep 7, 2009
2,806
The datasheets for some other PIC say to use HS_OSC for crystals above 3.5MHz but the 877 datasheet seems to say that either is fine at 4MHz.
Have you got the 2 capacitors to ground from the oscillator pins?
 

SgtWookie

Joined Jul 17, 2007
22,230
Usually, you pull MCLR to Vdd/Vcc using a 10k resistor - particularly if you are using an ICSP programmer.

Are you certain that the crystal itself is good?

They are rather fragile. If they have been dropped on a hard surface from more than a foot or so height, the crystal can break loose from it's mountings. You can break a crystal by using the wrong type of diagonal cutters when trimming excess lead lengths, or using the cutters improperly. Proper cutters have their blades designed so that any sudden shock is on the side away from the component.
 

Thread Starter

daredavel

Joined Feb 22, 2010
32
Thank you guys!! MCLR & Vdd are connected with 10k resistor.. I dont know if the clock is damage or not.. can it be tested to know if its ok, or not?
 

AlexR

Joined Jan 16, 2008
732
It might be a faulty crystal but it's not very likely. It is far more likely to be an error in your program. Just because a program appears OK in a simulator does not guarantee that it will work in the real device. Simulators are notorious for not checking that analogue ports have been configured correctly.

It may be an idea to post your complete program listing so we can see if there are any obvious oversights.
 

t06afre

Joined May 11, 2009
5,934
Your PIC can run on RC OSCILLATOR. You could make a test with this just to see if your PIC wakes up. Also post your code. It could be an error in the code as mentioned. Which device do use for programming?
 

sasek

Joined Jan 3, 2010
64
first check your program, i think your hardware is ok maybe error at coding.

first initialize the port;

void main(){

TRISB = 0b00001111; //making RB7-4 output otherwise input
PORTB = 0b00000000;

while(1){

if(RB0==1){RB7 = 1;}
else{RB7 = 0;}

}
}

this help u testing input and output.

did u do CONFIG, define XTAL_FREQ and include need header file????
 

Markd77

Joined Sep 7, 2009
2,806
I don't mean this to sound harsh but it probably will.
I've taken a look at the code and found it really hard to follow. Almost all of the defines are unnecessary and make the program harder to understand. It must take twice as long to write as well.
A few of them are almost OK but could be easier:
#define LED7200 movlw 63 ;7-Segment '0'
would be better replaced with:
LED7200 equ 63

and then instead of using LED7200 in the code you could use movlw LED7200

I think it would make it a lot easier for you and anyone looking at the code if you made these changes.
 

AlexR

Joined Jan 16, 2008
732
I totally agree with Markd77's comments. Also your program is quite complex so while you are having hardware problems I would put it away and write a simple program that just lights one led. Once you get that working modify it to light all your leds/segments.
Write similar simple programs to test your switches or whatever sensors you have. In other words write simple routine to test all your hardware. Once you are sure of your hardware you can go back to you original program and debug that with the knowledge that any odd behaviour is due to software and is not a hardware glitch.
 

Thread Starter

daredavel

Joined Feb 22, 2010
32
its somehow working now sir..but the problem now, is that if you turn it on..it wont power-up..but the supply is running in the pic..i have tested it with the voltmeter..and the supply is good.. You have to turn it on/off a couple of times to activate it.. What could possibly wrong? about the program..its clean..its just to output '00' in the 7segment..i have tested it to porteus..and it also did work in actual..only that it gets haywire a times.. thank you guys!!:confused:

here's a video sir of what i mean:

http://www.youtube.com/watch?v=2RSxU6WyU6E
 

Markd77

Joined Sep 7, 2009
2,806
If you have MCLR connected up to Vdd with a resistor, try powering up then touching MCLR pin to ground. It's possible that the power supply is insufficient or that the LEDs are drawing enough current to reset the PIC.
 

Thread Starter

daredavel

Joined Feb 22, 2010
32
If you have MCLR connected up to Vdd with a resistor, try powering up then touching MCLR pin to ground. It's possible that the power supply is insufficient or that the LEDs are drawing enough current to reset the PIC.
i'll connect the MCLR pin of the pic to the ground sir? what will happen sir? it wont damage my pic? thank you!!
 

Thread Starter

daredavel

Joined Feb 22, 2010
32
What is the best thing that i could do to solve this guys? my MCLR is connected to a vcc 5v with a 10k resistor..and may VDD is connected directly to the 5v.. If i connect the MCLR and VDD the pic wont start.. if i seperate the connection, it somehow start.. in a few times of turning it on/off..but if the 2 are connected..it wont start, even how many times you turn it on/off..
 
Top