1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Electronics A little trouble programming a PIC16F877A

Discussion in 'Modding' started by Emon, 10 Jan 2007.

  1. Emon

    Emon What's a Dremel?

    Joined:
    14 Jun 2004
    Posts:
    680
    Likes Received:
    0
    I have a PICkit 2 and MPLAB, and I'm trying to program a 16F877A. The PICkit 2 programming software identifies the UC correctly, and can read from it just fine. But I can't seem to program it at all. It'll either stop at programming user IDs or stop at an early address, like 0x000000 or 0x000006, or something like that, I can't remember how many zeros there were (this happened last night :p).

    My code right now is the most basic of things. It's along the lines of this.

    Code:
    #include <16f877a.inc>
    
    Start
    
        end
    
    When I try to verify the UC, it always fails on verifying user IDs. What's going on here? I have the feeling it's something very obvious, but for some reason I'm overlooking it.
     
  2. Hazer

    Hazer In time,you too will be relixalated

    Joined:
    14 Apr 2003
    Posts:
    957
    Likes Received:
    2
    You need a config word, and probably wouldnt hurt to include "org 0x000".
     
  3. Macaba

    Macaba What's a Dremel?

    Joined:
    4 Mar 2006
    Posts:
    107
    Likes Received:
    1
    The following code accounts for all scenarios that I know of.
    Code:
           	ORG     0x00
           	GOTO    START
    	ORG	0x04
    	GOTO    ISR
           	ORG     0x05
     
  4. SteveyG

    SteveyG Electromodder

    Joined:
    23 Nov 2002
    Posts:
    3,049
    Likes Received:
    8
    The PICkit2 is a little fussy about it's electrical requirements which tends to lead to bad programming. Try powering the PIC and PICkit from a separate power supply. Remember to change the settings in the programmer menu to reflect this.

    Absolute code using org 0x000 etc. is old school stuff. Use the linker to assign code sections to suitable areas of memory.
     
  5. K2V

    K2V What's a Dremel?

    Joined:
    2 Apr 2006
    Posts:
    12
    Likes Received:
    0
    if you are using PIC16F877A, try something called the bootloader, more info look here http://www.microchipc.com/PIC16bootload/

    Unless you are programming the bootloader program on the chip 1st time.
     
  6. SteveyG

    SteveyG Electromodder

    Joined:
    23 Nov 2002
    Posts:
    3,049
    Likes Received:
    8
    Bootloaders are more useful when you don't have a Microchip programmer/debugger in my opinion. The PICkit2 can be used directly from MPLAB, and offers debugging support on some devices (more to come in future releases of MPLAB), so it's a lot easier than faffing about with another piece of software just to program the device.
     
  7. Emon

    Emon What's a Dremel?

    Joined:
    14 Jun 2004
    Posts:
    680
    Likes Received:
    0
    That's what I've been doing.

    Alright, I'll take a look into that this evening.
     
  8. SteveyG

    SteveyG Electromodder

    Joined:
    23 Nov 2002
    Posts:
    3,049
    Likes Received:
    8
    It won't help with the errors you're getting. Something else is wrong.

    How long are the wires from your PICkit2 to PGC/PGD/MCLR?
     
  9. Emon

    Emon What's a Dremel?

    Joined:
    14 Jun 2004
    Posts:
    680
    Likes Received:
    0
    The ribbon I have from my PICkit2 to breadboard is maybe 6-8 inches max, then from there maybe another 2-3.
     
  10. SteveyG

    SteveyG Electromodder

    Joined:
    23 Nov 2002
    Posts:
    3,049
    Likes Received:
    8
    Try shortening it as far as possible. 8" is pushing it. Make sure PGM is tied low aswell.
     
  11. Emon

    Emon What's a Dremel?

    Joined:
    14 Jun 2004
    Posts:
    680
    Likes Received:
    0
    That's what I was thinking. I wouldn't think the code would affect the programming process at all. I'll try shortening the wires.
     

Share This Page