PIC16F877A breadboard connection is not working

Discussion in 'The Projects Forum' started by abhiananth, Dec 16, 2014.

  1. abhiananth

    Thread Starter New Member

    Jul 24, 2014
    18
    1
    Hi,
    I created a program for blinking led and generated hex file. Uploaded the hex file using pickit2. Then placed the microcontroller in breadboard and connected both Vss to ground and both Vdd to +4.5V. Power supply is generated from 3 AA size 1.5V battery. Connected 4Mhz crystal to clock pins and connected 22pf capacitors. But led is not glowed.

    Then created program for led glow in PortB. Still its not worked.

    Please guide me on this issue.
     
  2. Dodgydave

    Distinguished Member

    Jun 22, 2012
    4,965
    743
    can you upload your asm file.
     
  3. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    Do you have MCLR enabled in the configuration bits? If so, you need a pull up resistor on MCLR (pin 1).

    Yes, please provide your code. There are plenty of things that would prevent it from doing what you might expect.

    Have you looked into the simulator to verify the values are, indeed, changing?

    It's hard to see your connections, either sketch out the connections or take a clearer photograph of your setup.
     
    abhiananth likes this.
  4. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    In addition to MCLR do you have the power going to the chip? Looks to me like both + and - go to the same rail.

    Also, make the wiring to the crystal much much shorter, meaning the crystal right on the two pins and the caps from the same pins to the rail. When you have it correct you will need no jumpers. This is due to crystals being sensative to capaitive loading, and all that wire is a huge cap load.

    Getting the crystal correct can be such a pain I stick to PIC units having an internal oscillator even if I am adding the crystal: it gets things up faster during initial debugging.

    Last, you need a resistor between the pin and the LED. The way you wired it the pin should go hi to turn the LED on. Also make sure the LED is in the correct way: it goes in two ways but only one way provides joy.
     
    abhiananth likes this.
  5. abhiananth

    Thread Starter New Member

    Jul 24, 2014
    18
    1
    Thanks all for ur reply.

    I am newbie in this area. So don't
    know much about MCLR.

    Controller pin diagram:
    pin diagram.jpg

    controller connection:
    breadboard connection.jpg

    My program is:

    Blinking led program:
    void main() {
    TRISB = 0;
    do
    {
    PORTB = 1;
    Delay_ms(1000);
    PORTB = 0;
    Delay_ms(1000);
    }while(1); // Infinite Loop
    }


    Led program(No blinking):
    void main()
    {
    TRISB = 0;
    while(1)
    {
    PORTB = 1;
    }
    }

    Checked whether led is glowing with/without 220 ohm resistor. The image I shared is the one without resistor.

    +5V is going to Vdd
    GND is going to Vss

    Haven't tried by placing crystal oscillator near controller. Will try that and post it.

    How to use internal oscillator?

    How to check whether MCLR is enabled or not?

    What is MCLR?
     
    Last edited: Dec 17, 2014
  6. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    Have you read the datasheet? Have you looked those questions up there? That's a good place to start. MCLR is the master reset for the PIC.

    The 16F877A does not have an internal oscillator.

    You cannot hope to program a microcontroller without looking at the datasheet.

    What language/compiler are you using? MikroC defines the configuration bits in the IDE, where XC8/Hi-Tech C define it in the source files. You can find it in MPLABX in one of the windows, I can't remember which at the moment.

    Your LED should have a resistor.

    Screenshot_2014-12-17-07-20-50~2.jpg
    This part of your picture looks like you've connected the two supply pins together, could you verify this is not the case?
     
    abhiananth likes this.
  7. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    MCLR and the oscillator settings are made in the configuration word. You truly need to read that part of the data sheet until you understand them (or think you do ;-) ).

    HOW these are set depends on which compiler you use. You have not shared that with us so we have no help there.
     
    abhiananth likes this.
  8. abhiananth

    Thread Starter New Member

    Jul 24, 2014
    18
    1
    Thanks all for your help.

    In datasheet, I took oscillator circuit.
    oscillator circuit.jpg

    Capacitor value
    capacitor range.jpg
    I am using MikroC complier and Pic2Kit
    Before connecting ground to controller, all PORT pins are generating +3.21V from it. When I connected ground to the controller, no output is detected even in PORTB pins

    I read about MCLR and I connected it to +5V through 1K ohm resistor.
    Still there was no output.

    Then I pressed crystal oscillator. The controller worked and the led glowed(led glow program)
    20141218_124649.jpg

    When I downloaded the led blinking program with 1 sec delay Delay_ms(1000), the controller doesn’t work. I kept configuration as XT oscillator.

    I tried by pressing crystal oscillator. No response. Then I changed the configuration as HS oscillator. The controller worked but the delay was less than 1 sec. I took video but couldn't upload it.

    I am using 4MHz crystal. In datasheet, it is mentioned as for 4MHz, we have to set configuration as XT oscillator. But for me HS oscillator configuration only worked. Please clarify me on this.

    And also why I am not gettnig 1 sec delay using Delay_ms(1000) syntax.
     
    ErnieM likes this.
  9. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    Congratulations, you made new life appear!

    If HS works keep using it. That is just setting the gain by changing Rf in your figure. If HS works then keep using it.

    The MikroC compiler needs to know how fast your PIC is running to get the delay functions to work properly. I don't have the user manual here but I know they mention how to do it. Without telling it a default value is used and that probably incorrect.

    If problem persists, then your oscillator is running off frequency and you can ignore my 2nd paragraph.
     
    Last edited: Dec 20, 2014
    abhiananth likes this.
  10. abhiananth

    Thread Starter New Member

    Jul 24, 2014
    18
    1
Loading...