Program PIC16F876A with PICkit3

Discussion in 'Embedded Systems and Microcontrollers' started by James_2012, May 24, 2012.

  1. James_2012

    Thread Starter New Member

    May 24, 2012
    5
    0
    Greetings All,

    Someone please help me troubleshoot what the issue is with my code and my PIC.

    I'm using MPlab X IDE 1.10 and PICkit3 trying to burn a simple code to turn on a LED using the I/O ports. The PICkit3 supply the power to the target board which in ICSP program mode with PIN1 connected to a 22KΩ pull-up resistor connected to Vpp. PIN1 also connected to a capacitor across ground.

    1)The code compiled with a warming "Found directive in column 1. (__CONFIG)" which i think its alright.
    2)It also programed without any issues "Programming...
    Programming/Verify complete"
    3) The LED is connected correctly and the board has power Vpp = 4.8V supplied by PICkit3.

    PROBLEM::confused:
    1) Nothing happen after program is complete, i measured the voltage on all the pins at porta i got 0V

    Below is my complete code in assembly.
    ******************************************************

    #include P16F876A.INC
    #define XTAL FREQ 20MHZ ; using 20Mhz ceramic crystal oscillator.
    __CONFIG (_XT_OSC & _WDT_OFF & _PWRTE_OFF & _BOREN_OFF & _LVP_OFF & _CPD_OFF & _WRT_OFF & _CP_OFF );

    ORG 0x00
    MOVLW 0x7
    MOVWF ADCON1
    MOVLW 0x00
    MOVWF TRISA ;Set PortA output
    MOVLW 0x00
    MOVWF PORTA ;Clear PortA
    HERE
    MOVLW 0xFF ;Set all portA high
    MOVWF PORTA
    GOTO HERE
    END
    ****************************************************************

    Please help

    Thank you all in advance!
     
  2. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Have you checked the level on the MCLR pin? Also I think in your case. You should configure for HS oscillator. Looking at your code. I can not see any setting of the data memory banking bits. That is the main culprit I think Read section 2.2 in the datasheet. Try This
    Code ( (Unknown Language)):
    1.  
    2. #include P16F876A.INC
    3. #define XTAL FREQ 20MHZ ; using 20Mhz ceramic crystal oscillator.
    4. __CONFIG (_XT_OSC & _WDT_OFF & _PWRTE_OFF & _BOREN_OFF & _LVP_OFF & _CPD_OFF & _WRT_OFF & _CP_OFF );
    5.  
    6. ORG 0x00
    7. MOVLW 0x7
    8. banksel ADCON1
    9. MOVWF ADCON1
    10. MOVLW 0x00
    11. MOVWF TRISA ;Set PortA output
    12. banksel PORTA
    13. MOVLW 0x00
    14. MOVWF PORTA ;Clear PortA
    15. HERE
    16. MOVLW 0xFF ;Set all portA high
    17. MOVWF PORTA
    18. GOTO HERE
    19. END
    20.  
    21.  
     
    James_2012 likes this.
  3. James_2012

    Thread Starter New Member

    May 24, 2012
    5
    0
    Thank you t06afre,

    Voltage level on the MCLR pin is about 4.5V. I tried what you recommended but still nothing happening.

    James_2012
     
  4. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Can you post your schematic.
     
    James_2012 likes this.
  5. James_2012

    Thread Starter New Member

    May 24, 2012
    5
    0
    Thank you t06afre! it works now.
    after i added the banksel and burned to the PIC i notice my led flashes when i unplugged the PICkit3 so I i unplugged the PICkit3 power supply and and use an external power source and the led lid up like it should (probably got to do with the whole thing in a breadboard). And off when i burn a different program.

    Haven't figure out how to make it flash yet in assembly language.

    Any way attached is my schematic and the code below. hope it will be helpful to others in the future.
    *********************************************************************
    #include P16F876A.INC
    #define XTAL FREQ 20MHZ ; using 20Mhz ceramic crystal oscillator.
    __CONFIG (_XT_OSC & _WDT_OFF & _PWRTE_OFF & _BOREN_OFF & _LVP_OFF & _CPD_OFF & _WRT_OFF & _CP_OFF );

    ORG 0x00
    MOVLW 0x6
    banksel ADCON1
    MOVWF ADCON1
    MOVLW 0x00
    MOVWF TRISA ;Set PortA output
    banksel PORTA
    MOVLW 0x00
    MOVWF PORTA ;Clear PortA
    HERE
    MOVLW 0xFF
    MOVWF PORTA
    GOTO HERE
    END

    ***********************************************************************

    Again Thank You t06afree for your help.:):)
     
  6. coldpenguin

    Active Member

    Apr 18, 2010
    165
    9
    Might be a stupid question, I don't use the PickKit, I use the ICD2.

    When I burn a program using MpLAB, I then have to go to Programmer->Release from Reset

    This clears the MCLR pin, and the PIC runs.

    Similarly, unplugging the PicKit would do the same thing..... (assuming it isn't an oscillator issue). I was kinda expecting two capacitors either side of the crystal (10-22nf is what I use) connected to ground.
     
  7. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    That sounds correct. I use newer PICs. And they have an option to disable the MCLR function and the MCLR pin will be normal input pin. In my projects I always prefer to do this.
     
  8. MrChips

    Moderator

    Oct 2, 2009
    12,440
    3,361
    What do you mean by this?

    Isn't this in fact what you have actually done?
     
  9. James_2012

    Thread Starter New Member

    May 24, 2012
    5
    0
    You're correct coldpenguin, i used a 20 MHZ ceramic crystal with an internal capacitors.

    @ MrChips - no it doesn't flash yet, it only turns on the LED. I'm not that familiar with assembly, but from what i read it doesn't have a delay function.:confused:
     
  10. nerdegutta

    Moderator

    Dec 15, 2009
    2,515
    785
    Ref the pencil drawn schematic.

    Shouldn't the crystal be connected to GND with some caps? Like this:
    [​IMG]
    Pin name and number differ. Just for explanation of the crystal/cap wiring.

    EDIT:
    Got distracted before I hit the submit button....
     
    Last edited: May 25, 2012
  11. tracecom

    AAC Fanatic!

    Apr 16, 2010
    3,869
    1,393
    You are correct; the data sheet calls for small caps as you have them drawn (often 22pF), but I have found (by accident) that the crystals will sometimes oscillate without the caps.
     
  12. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    In this case the OP use a resonator. Which is kind of poor mans crystal. Some these come in a 3 pin package with internal caps. Just like the OP use. If you go to your component pusher. And search for resonator and select those with 3 pins. You will get a selction of the latter.
    You can also take a look here http://www.oscilent.com/catalog/Category/ceramic_resonator.htm
     
  13. coldpenguin

    Active Member

    Apr 18, 2010
    165
    9
    I don't see MCLRE being disabled in the _Config bits......, looking through the .inc, _LVP_OFF makes MCLRE be used

    No real delay, you just hang around doing nothing.

    Add around 500k
    Code ( (Unknown Language)):
    1. NOP
    just before your goto HERE.
    (Sorry, can't remember how to count in ASM)
     
  14. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    That is because the chip the OP use. Do not offer that option
     
  15. James_2012

    Thread Starter New Member

    May 24, 2012
    5
    0
    Hi All,

    Just to clarify i repost the schematic here and a copy of the oscillator data sheet. oscillator have built-in 15pf cap.
     
  16. coldpenguin

    Active Member

    Apr 18, 2010
    165
    9
    OK, sorry, I have always used the MCLRE and am not very good at interpereting the .inc files.

    My p16f876a.inc has the following
    Code ( (Unknown Language)):
    1.  
    2. ;==========================================================================
    3. ;
    4. ;       Configuration Bits
    5. ;
    6. ;   NAME            Address
    7. ;   CONFIG            2007h
    8. ;
    9. ;==========================================================================
    10.  
    11. ; The following is an assignment of address values for all of the
    12. ; configuration registers for the purpose of table reads
    13. _CONFIG          EQU  H'2007'
    14.  
    15. ;----- CONFIG Options --------------------------------------------------
    16. _FOSC_LP             EQU  H'3FFC'    ; LP oscillator
    17. _LP_OSC              EQU  H'3FFC'    ; LP oscillator
    18. _FOSC_XT             EQU  H'3FFD'    ; XT oscillator
    19. _XT_OSC              EQU  H'3FFD'    ; XT oscillator
    20. _FOSC_HS             EQU  H'3FFE'    ; HS oscillator
    21. _HS_OSC              EQU  H'3FFE'    ; HS oscillator
    22. _FOSC_EXTRC          EQU  H'3FFF'    ; RC oscillator
    23. _RC_OSC              EQU  H'3FFF'    ; RC oscillator
    24.  
    25. _WDTE_OFF            EQU  H'3FFB'    ; WDT disabled
    26. _WDT_OFF             EQU  H'3FFB'    ; WDT disabled
    27. _WDTE_ON             EQU  H'3FFF'    ; WDT enabled
    28. _WDT_ON              EQU  H'3FFF'    ; WDT enabled
    29.  
    30. _PWRTE_ON            EQU  H'3FF7'    ; PWRT enabled
    31. _PWRTE_OFF           EQU  H'3FFF'    ; PWRT disabled
    32.  
    33. _BOREN_OFF           EQU  H'3FBF'    ; BOR disabled
    34. _BODEN_OFF           EQU  H'3FBF'    ; BOR disabled
    35. _BOREN_ON            EQU  H'3FFF'    ; BOR enabled
    36. _BODEN_ON            EQU  H'3FFF'    ; BOR enabled
    37.  
    38. [COLOR=Red]_LVP_OFF             EQU  H'3F7F'    ; RB3 is digital I/O, HV on MCLR must be used for programming[/COLOR]
    39. _LVP_ON              EQU  H'3FFF'    ; RB3/PGM pin has PGM function; low-voltage programming enabled
    Which made me think, given the comment that MCLR was enabled 'cos the _config in the code had _LVP_OFF (and would otherwise be disabled). Confusing.
     
  17. maxpower097

    Well-Known Member

    Feb 20, 2009
    795
    388
    Try you project in MPLAB 8. I recently had to do some work on a PIC16LF877A and was all stoked about the mplabX and its features. Well with the PK3 or what ever it just wasn't happening. I couldn't get jack or S#$^ to run right. I switched back to MPlab8 and bam no code modification and it ran perfectly. Also every once and a while the PK3 won't detect the chip right. Just override it and program it anyways and it will program and verify. Its one of those errors saying (Device ID mismatch 0X00 was received when 0x08 was expected) Sometimes it follows the code from computer to computer, sometimes it resets and works right. So you got bugs in the PK3 for the PIC16 and bugs in MPlabX. So I would try mplab 8 and re-evaluate your sitcheation.
     
Loading...