1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Breadboard Programming for PIC16F877A

Discussion in 'Microcontrollers' started by aaronchay, Nov 6, 2008.

  1. aaronchay

    aaronchay New Member

    Joined:
    Aug 30, 2008
    Messages:
    37
    Likes:
    0
    Hi, I would like to know can I just connect the wires from the Pickit 2 directly to the pins on my Microcontroller? Must I add a pull up resistor or something? I tried to connect the wires directly but I couldn't program it.
     
  2. futz

    futz Active Member

    Joined:
    Sep 15, 2007
    Messages:
    2,043
    Likes:
    24
    Location:
    Vancouver, B.C.
    Yes you can.

    Pin 1. VPP to MCLR pin on PIC. You need a 10K to 33K pullup resistor on this pin too.

    Pin 2. VDD to VDD. The PICkit 2 can supply power to your target (the breadboard), but not too much. I forget the exact amount of current, but it's enough to do small circuits.

    Pin 3. Ground to Ground

    Pin 4. PGD to PGD pin on PIC.

    Pin 5. PGC to PGC pin on PIC.

    Here's a typical schematic showing how it's connected. See the upper left area.
    [​IMG]
     
  3. SMUGangsta

    SMUGangsta New Member

    Joined:
    Oct 16, 2008
    Messages:
    219
    Likes:
    2
    Location:
    Wales, Centre of the Universe
    Whats the pull-up for - I regularly connect my pickit2 directly to my breadboarded circuits and they work fine - apart from the times I connect the pins the wrong way round (i really need a keyed socket :( )
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. futz

    futz Active Member

    Joined:
    Sep 15, 2007
    Messages:
    2,043
    Likes:
    24
    Location:
    Vancouver, B.C.

    The pullup is for when you try to run the circuit without the PICkit 2 connected. Keeps the reset pin from floating, which can cause random resets. As long as the PICkit 2 is connected it controls the pin. So it's just a good habit to get into.
     
    • Like Like x 1
  6. SMUGangsta

    SMUGangsta New Member

    Joined:
    Oct 16, 2008
    Messages:
    219
    Likes:
    2
    Location:
    Wales, Centre of the Universe
    ahh a good hint there, just thinking - most of my recent projects have used small pics, so ive probably had the mclr disabled and using the pin as an input - thats probably why i havn't had any problems.
     
  7. aaronchay

    aaronchay New Member

    Joined:
    Aug 30, 2008
    Messages:
    37
    Likes:
    0
    Hi fut, thanks for the verification. I connected as instructed and did a Blank Check on my device using the pickit 2 Programmer. However, it stated "Program Memory is not blank starting at address 0x00000"
     
  8. futz

    futz Active Member

    Joined:
    Sep 15, 2007
    Messages:
    2,043
    Likes:
    24
    Location:
    Vancouver, B.C.
    It connects then? If so then try an erase. If all seems normal, program the chip with your hex file and continue.
     
  9. aaronchay

    aaronchay New Member

    Joined:
    Aug 30, 2008
    Messages:
    37
    Likes:
    0
    I tried to program using the MPLAB Programmer. It shows the following error when I select Pickit2 as the programmer.

    PKWarn0003: Unexpected device ID: Please verify that a PIC16F877A is correctly installed in the application. (Expected ID = 0xE20, ID Read = 0x0)

    When I try to write, it shows the following error:
    PK2Error0027: Failed verify (Address = 0x2007 - Expected Value 0x2FCF - Value Read 0x4B)
     
  10. futz

    futz Active Member

    Joined:
    Sep 15, 2007
    Messages:
    2,043
    Likes:
    24
    Location:
    Vancouver, B.C.
    Then it's not connecting. Trying to write is pointless until it does.

    With the PIC wired properly, hit Programmer/Connect and it should connect to the PIC and tell you what type it is. If you can't get that to happen, the rest is never going to work.

    If your project has the wrong target PIC specified that could cause the problem. Confirm that your project has the correct PIC selected.

    The above was typed without MPLAB in front of me so I may have misnamed certain menus. Adjust to suit.
     
  11. aaronchay

    aaronchay New Member

    Joined:
    Aug 30, 2008
    Messages:
    37
    Likes:
    0
    I tried to wire my P16F877A like this:

    [​IMG][​IMG]

    However, I am still getting the same error.

    I tried using the Pickit2 programmer and checked for blank. It Displayed "Device was blank" until I connected the MCLR to ground then after that it coundn't work.
     
    Last edited: Nov 8, 2008
  12. futz

    futz Active Member

    Joined:
    Sep 15, 2007
    Messages:
    2,043
    Likes:
    24
    Location:
    Vancouver, B.C.
    I can't tell anything from that jumble of wires. I would have to see the PICkit 2 end as well. You should try to get in the habit of wiring your breadboard more like this. Check out one of Pommie's breadboards if you want to see REALLY neat. Mine look sloppy beside his.

    Rather than a bunch of loose wires as a programming cable you really should build some proper cables to make your life SO MUCH easier, and programming/debugging much more reliable (like 100% :p). Like this:

    [​IMG]

    Look about halfway down in this thread for more pictures.

    Umm... Why would you connect MCLR to ground?? As long as MCLR is held low the PIC is in reset. Reset means nothing happens until that pin goes high again. Put a pullup resistor (10K to 33K) from MCLR to VCC (5 volts) to make sure MCLR stays high.
     
    Last edited: Nov 8, 2008
  13. futz

    futz Active Member

    Joined:
    Sep 15, 2007
    Messages:
    2,043
    Likes:
    24
    Location:
    Vancouver, B.C.
    Is that a resonator over at the left there? Keep the wires to it as short as possible!.

    You should also connect all VDD and VSS pins, even though they usually work fine with just one pair connected.

    But judging by a closer look at the picture, assuming the PICkit 2 end is good, it should work.

    How long are the wires between the PICkit 2 and the breadboard? Keep them under 12 inches or so (even less if it's practical).

    It's unlikely that this is the problem, but you should get in the habit of putting "decoupling" capacitors between the VDD and VSS pins of the PIC, as close as possible to the chip. Use 0.1uF ceramics for this. Sometimes you'll have trouble getting things to run properly without them.

    If nothing else works, start up the PICkit 2 software (shut down MPLAB) and connect to the chip. Do an erase. Then shut that off and start MPLAB again and see if it connects normally then.
     
    Last edited: Nov 8, 2008
  14. mvs sarma

    mvs sarma Well-Known Member

    Joined:
    Oct 29, 2006
    Messages:
    3,512
    Likes:
    76
    Location:
    Hyderabad, India.
    For programming purpose, why at all the resonator is needed, I wonder?Does he/she mean ICSP mode
     
    Last edited: Nov 8, 2008
  15. aaronchay

    aaronchay New Member

    Joined:
    Aug 30, 2008
    Messages:
    37
    Likes:
    0
    I've redone the wiring today and I'm still getting the same error message as before. Could it be a bad chip? It's quite difficult to get a damaged chip right?

    [​IMG][​IMG]

    [​IMG][​IMG]

    [​IMG][​IMG]

    I've removed the Resonator too and wires are 4.1 Inch or 10.5cm
     
    Last edited: Nov 9, 2008
  16. 3v0

    3v0 Coop Build Coordinator Forum Supporter

    Joined:
    Jul 14, 2006
    Messages:
    9,404
    Likes:
    227
    Location:
    OKLAHOMA USA
    When I run into this sort of problem I like to use the PICkit2 application instead of MPLAB. It seems to make connections work that have failed in MPLAB.

    The only thing you should be looking at is connect (in MPLAB) or tools>check_communication in PICkit2. Do not bother with reading or erasing the chip till after these work.

    You do not need a crystal or resinator to program the chip.

    You do not need the pullup unless you intend to run then you also need a clock source (crystal or resonator).

    I would add the 2 missing bypass caps. Check for shorts on the header that connects to the PICkit2.

    I have never seen a PIC that was bad from the factory but it is possible but rare to mess one up.

    The one thing I did not look at was the ICSP CLK and DATA lines. They could be mixed up.
     
  17. aaronchay

    aaronchay New Member

    Joined:
    Aug 30, 2008
    Messages:
    37
    Likes:
    0
    I've checked the connection for the PGC and PGD. I've also checked for shorts on the wire itself.

    I would add the 2 missing bypass caps. Check for shorts on the header that connects to the PICkit2.

    Would you mind explaining this sentence?
     
  18. 3v0

    3v0 Coop Build Coordinator Forum Supporter

    Joined:
    Jul 14, 2006
    Messages:
    9,404
    Likes:
    227
    Location:
    OKLAHOMA USA
    OK. You already tested for shorts. The uC has 2 sets of power connections. Add a .1 uf capacitor between power and gnd on each side of the chip.

    On the top side of the chip you need a cap between breadboard locations 18 and 19 and on the bottom between locations 20 and 21.

    EDIT: I strongly suggest you use the PICkit2 application while you attempt to get the connection established. I was just working with a 18F2321 that I programmed with MPLAB. The processor was running and MPLAB could not connect. I switched to PICkit2 and it connected. Once you have a working connection switch back to MPLAB.
     
    Last edited: Nov 9, 2008
  19. aaronchay

    aaronchay New Member

    Joined:
    Aug 30, 2008
    Messages:
    37
    Likes:
    0
    Would I be able to do fine without the capacitors at the moment? I would still be able to program right? I also tried to detect my PIC18F452 and I got the same error too. I'm using the Pickit2 Application.
     
  20. arhi

    arhi Member

    Joined:
    Apr 17, 2008
    Messages:
    887
    Likes:
    12
    Location:
    Belgrade, .rs
    actually - no
    omitting the capacitor on the power pins (as close as possible to the pic) will usually lead to bunch of "strange" behaviours, one of the often seen one is "pickit does not recognise my uC / pickit do not want to program / read my uC"

    just add a capacitors on the power pins, at least 0.1uF but any bigger will do the job, even some 100uF electrolyte will solve the problem just pay attention to polarize it properly
     
  21. aaronchay

    aaronchay New Member

    Joined:
    Aug 30, 2008
    Messages:
    37
    Likes:
    0
    tried adding the capacitors already. No difference. Do I have to do anything on the software part?

    I opened Pickit2, Go to Programmer - Manually select Device and I chose PIC16F877A
     

Share This Page