pic16F877A not functioning

Discussion in 'Embedded Systems and Microcontrollers' started by daredavel, Mar 4, 2010.

  1. daredavel

    Thread Starter Member

    Feb 22, 2010
    32
    0
    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.. [​IMG] 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:
    Code ( (Unknown Language)):
    1. __CONFIG   _CP_OFF & _WDT_OFF & _PWRTE_ON & _HS_OSC
    2.  
    Should i replace it with:
    Code ( (Unknown Language)):
    1. __CONFIG   _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC
    2.  
    I'll consult it to you guys before i do anything..to avoid any damages to the my pic.. Thank you!!:D
     
  2. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    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?
     
  3. daredavel

    Thread Starter Member

    Feb 22, 2010
    32
    0
    yes sir! i have 22pF(2).. You mean that the CONFIG is fine sir?
     
  4. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    Looks fine. Is MCLR pulled up to Vdd (preferably with a resistor)?
     
  5. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    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.
     
  6. daredavel

    Thread Starter Member

    Feb 22, 2010
    32
    0
    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?
     
  7. AlexR

    Well-Known Member

    Jan 16, 2008
    735
    54
    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.
     
  8. Boo

    Member

    Oct 27, 2009
    40
    0
    Sounds like a problem with how your hooking it up...whats your voltage source?
     
  9. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    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?
     
  10. sasek

    Member

    Jan 3, 2010
    64
    0
    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????
     
  11. daredavel

    Thread Starter Member

    Feb 22, 2010
    32
    0
    I have attached the codes sir..please! do take a look sir.. thank you so much!
     
  12. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    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.
     
  13. AlexR

    Well-Known Member

    Jan 16, 2008
    735
    54
    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.
     
  14. Boo

    Member

    Oct 27, 2009
    40
    0
    PORTB is NOT in bank 1
     
  15. daredavel

    Thread Starter Member

    Feb 22, 2010
    32
    0
    i'll try to make the necessary changes..thank you so much!!
     
  16. daredavel

    Thread Starter Member

    Feb 22, 2010
    32
    0
    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
     
  17. Boo

    Member

    Oct 27, 2009
    40
    0
    That sounds like a MCRL problem , I would turn it off and see if it still happens...
     
  18. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    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.
     
  19. daredavel

    Thread Starter Member

    Feb 22, 2010
    32
    0
    i'll connect the MCLR pin of the pic to the ground sir? what will happen sir? it wont damage my pic? thank you!!
     
  20. daredavel

    Thread Starter Member

    Feb 22, 2010
    32
    0
    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..
     
Loading...