first test 16F876A pic not working

Discussion in 'Embedded Systems and Microcontrollers' started by supertony, Jan 15, 2013.

  1. supertony

    Thread Starter New Member

    Jan 15, 2013
    5
    0
    Hi.
    I am using MPLAB and PICKIT3 for programming a 16F876A pic.
    This is the program:

    Code ( (Unknown Language)):
    1.  
    2.     list        p=16f876a    
    3.     #include    <p16f876a.inc>    
    4.  
    5.         cblock    0x20    
    6.             CounterA
    7.             CounterB
    8.             CounterC    
    9.         endc
    10.  
    11.     org 0x0000
    12.     goto main
    13.     org 0x0004
    14.     retfie
    15.  
    16. main:
    17.     bsf STATUS, RP0
    18.     movlw 0x0
    19.     movwf PORTB
    20.     movwf PORTC
    21.     bcf STATUS, RP0
    22.  
    23. Loop    
    24.     movlw    0xff
    25.     movwf    PORTC    
    26.     movwf    PORTB
    27.     call    Delay            
    28.     movlw    0x00
    29.     movwf    PORTC
    30.     movwf    PORTB            
    31.     call    Delay
    32.     goto    Loop            
    33.  
    34. Delay    
    35.     movlw    D'168'
    36.     movwf    CounterC
    37.     movlw    D'168'
    38.     movwf    CounterB
    39.     movlw    D'168'
    40.     movwf    CounterA
    41. loop    
    42.     decfsz    CounterA,1
    43.     goto    loop
    44.     decfsz    CounterB,1
    45.     goto    loop
    46.     decfsz    CounterC,1
    47.     goto    loop
    48.     retlw    0x00
    49.     END
    50.  
    This is just my first test with breadboard and pickit3 for blinking
    a led. I guess I have connected the device properly because when I make
    the file and program it I get this message:


    PICkit 3 detected
    Connecting to PICkit 3...

    Firmware Suite Version...... 01.27.20

    Firmware type......................Midrange

    PICkit 3 Connected.Device ID Revision = 00000008
    ...

    With no error message while programming and verify.


    After programming I have red the flash memory with pickit3 software
    and the program is in the pic. The breadboard has no power supply
    which I provide directly with the kitpic3 (5 V).

    The connection for pickit are just ok, as I have followed the instruction
    on the manual. On breadboard I use a 10MHz xtal and two capacitors of 22pf
    connected to Vss. A restistor of 5Kohm between Vdd and MCLR.

    I tested the software also with ISIS Proteus and works. The led
    blinks. But on the breadboad nothing happen and led is off.

    What's wrong?
    :confused:
     
    Last edited by a moderator: Jan 15, 2013
  2. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    As I can see it. You have not set config bits. You find the information you need in the include file at the end
    Code ( (Unknown Language)):
    1.  
    2. ;==========================================================================
    3. ;
    4. ;       Configuration Bits
    5. ;
    6. ;   NAME            Address
    7. ;   CONFIG            2007h
    8. ;
    9. ;==========================================================================
    10. ; The following is an assignment of address values for all of the
    11. ; configuration registers for the purpose of table reads
    12. _CONFIG          EQU  H'2007'
    13. ;----- CONFIG Options --------------------------------------------------
    14. _FOSC_LP             EQU  H'3FFC'    ; LP oscillator
    15. _LP_OSC              EQU  H'3FFC'    ; LP oscillator
    16. _FOSC_XT             EQU  H'3FFD'    ; XT oscillator
    17. _XT_OSC              EQU  H'3FFD'    ; XT oscillator
    18. _FOSC_HS             EQU  H'3FFE'    ; HS oscillator
    19. _HS_OSC              EQU  H'3FFE'    ; HS oscillator
    20. _FOSC_EXTRC          EQU  H'3FFF'    ; RC oscillator
    21. _RC_OSC              EQU  H'3FFF'    ; RC oscillator
    22. _WDTE_OFF            EQU  H'3FFB'    ; WDT disabled
    23. _WDT_OFF             EQU  H'3FFB'    ; WDT disabled
    24. _WDTE_ON             EQU  H'3FFF'    ; WDT enabled
    25. _WDT_ON              EQU  H'3FFF'    ; WDT enabled
    26. _PWRTE_ON            EQU  H'3FF7'    ; PWRT enabled
    27. _PWRTE_OFF           EQU  H'3FFF'    ; PWRT disabled
    28. _BOREN_OFF           EQU  H'3FBF'    ; BOR disabled
    29. _BODEN_OFF           EQU  H'3FBF'    ; BOR disabled
    30. _BOREN_ON            EQU  H'3FFF'    ; BOR enabled
    31. _BODEN_ON            EQU  H'3FFF'    ; BOR enabled
    32. _LVP_OFF             EQU  H'3F7F'    ; RB3 is digital I/O, HV on MCLR must be used for programming
    33. _LVP_ON              EQU  H'3FFF'    ; RB3/PGM pin has PGM function; low-voltage programming enabled
    34. _CPD_ON              EQU  H'3EFF'    ; Data EEPROM code-protected
    35. _CPD_OFF             EQU  H'3FFF'    ; Data EEPROM code protection off
    36. _WRT_HALF            EQU  H'39FF'    ; 0000h to 0FFFh write-protected; 1000h to 1FFFh may be written to by EECON control
    37. _WRT_1FOURTH         EQU  H'3BFF'    ; 0000h to 07FFh write-protected; 0800h to 1FFFh may be written to by EECON control
    38. _WRT_256             EQU  H'3DFF'    ; 0000h to 00FFh write-protected; 0100h to 1FFFh may be written to by EECON control
    39. _WRT_OFF             EQU  H'3FFF'    ; Write protection off; all program memory may be written to by EECON control
    40. _DEBUG_ON            EQU  H'37FF'    ; In-Circuit Debugger enabled, RB6 and RB7 are dedicated to the debugger
    41. _DEBUG_OFF           EQU  H'3FFF'    ; In-Circuit Debugger disabled, RB6 and RB7 are general purpose I/O pins
    42. _CP_ON               EQU  H'1FFF'    ; All program memory code-protected
    43. _CP_ALL              EQU  H'1FFF'    ; All program memory code-protected
    44. _CP_OFF              EQU  H'3FFF'    ; Code protection off
    You use the config bit like this. Also see section 14 in the datasheet
    Code ( (Unknown Language)):
    1. list  p=16f876A ; list directive to define processor
    2.  #include <p16f876A.inc> ; processor specific variable definitions
    3.  
    4.  __CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _RC_OSC & _WRT_OFF & _LVP_ON & _CPD_OFF
    5. ; '__CONFIG' directive is used to embed configuration data within .asm file.
    6. ; The lables following the directive are located in the respective .inc file.
    7. ; See respective data sheet for additional information on configuration word.
     
  3. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    Also, I don't see where you set the TRIS B & C registers to zero to make the pins outputs. And, if this PIC has any analog functions (I did not check) they need be turned off: analog is on by default.

    I didn't check your bank selection, good to see it there. There is a MPASM macro "banksel" that will set these bits for you:
    Code ( (Unknown Language)):
    1. main:
    2.     banksel PORTB
    3.     movlw   0x0
    4.     movwf   PORTB
    5.     movwf   PORTC
    6.     banksel TRISB
    7.     movwf   TRISB
    8.     movwf   TRISC
    9.  
     
    Last edited: Jan 15, 2013
  4. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    It's there, he just called them PORTB and PORTC, they refer to the same registers if in the correct bank, but it's clearer to call them TRISB and TRISC.
    I also much prefer
    decfsz Counter, F
    to
    decfsz Counter, 1
     
  5. supertony

    Thread Starter New Member

    Jan 15, 2013
    5
    0
    Still not blinking... ::(
     
  6. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    Did you add in the configuration bits? You need to specify the oscillator the device is going to use.

    Note: If you used the sample configuration t06afre gave, you are telling the uC to use a RC-oscillator, you need to change it to support your 10MHz crystal.

    Post your current code with configuration bits specified.
     
  7. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Well what is your code at the moment. And please post your schematic. As you use Proteus it should be easy
     
  8. supertony

    Thread Starter New Member

    Jan 15, 2013
    5
    0
    Hi.
    On the breadboard this is the connection I have made:

    http://3.bp.blogspot.com/-5sLwQ0WMRUk/TlgOD5O3PgI/AAAAAAAAAHs/OER1-0vuPPg/s1600/diagram.png

    Al pin are properly connected. I am using two 22pf capacitor connected as usual to xtal (10 MHZ) and Vss. Also a resistor between Vdd and MCLR. PicKit3 use pins RB7/PGD RB6/PGC for programming.

    This is the last program version:

    list p=16f876A ; list directive to define processor
    #include <p16f876A.inc> ; processor specific variable definitions

    __CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _RC_OSC & _WRT_OFF & _LVP_ON & _CPD_OFF
    ; '__CONFIG' directive is used to embed configuration data within .asm file.
    ; The lables following the directive are located in the respective .inc file.
    ; See respective data sheet for additional information on configuration word.

    cblock 0x20
    CounterA
    CounterB
    CounterC
    endc

    org 0x0000
    goto main
    org 0x0004
    retfie

    main:
    banksel PORTB
    movlw 0x0
    movwf PORTB
    movwf PORTC
    banksel TRISB
    movwf TRISB
    movwf TRISC
    bsf STATUS, RP0
    movlw 0x0
    movwf PORTB
    movwf PORTC
    bcf STATUS, RP0

    Loop
    movlw 0xff
    movwf PORTC
    movwf PORTB
    call Delay
    movlw 0x00
    movwf PORTC
    movwf PORTB
    call Delay
    goto Loop

    Delay
    movlw D'20'
    movwf CounterC
    movlw D'20'
    movwf CounterB
    movlw D'168'
    movwf CounterA
    loop
    decfsz CounterA,1
    goto loop
    decfsz CounterB,1
    goto loop
    decfsz CounterC,1
    goto loop
    retlw 0x00
    END

    On the outputs pin I have a led which I also tried to switch the terminals. No blinking while the same hex program in isis works great. After programming the pic should I reset the micro? Are there any option to setup in MPLAB? What i do is simple setting Power target circuti with
    pickit3 -> make file -> program pic..and it does. Here it's not important my program, it is important that i start see breadboard working with pic so I know the steps for testing my future projects. Thanks a lot for your help.
     
  9. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    See my previous post where I said
    You need to do that...

    Instead of
    You should have:
     
  10. supertony

    Thread Starter New Member

    Jan 15, 2013
    5
    0
    Hi.
    Before adding the config work in code I used the one set by mplab for 10 mhz. Now I changed with your configration and I have programmed the pic once again.

    ----------------------------------------------------------------------
    Release build of project `M:\ISIS\16f87.mcp' started.
    Language tool versions: MPASMWIN.exe v5.46, mplink.exe v4.44, mplib.exe v4.44
    Tue Jan 15 23:53:50 2013
    ----------------------------------------------------------------------
    Clean: Deleting intermediary and output files.
    Clean: Deleted file "C:\Users\Antonio\Desktop\blinkled\blink.o".
    Clean: Deleted file "C:\Users\Antonio\Desktop\blinkled\blink.err".
    Clean: Deleted file "C:\Users\Antonio\Desktop\blinkled\blink.hex".
    Clean: Deleted file "C:\Users\Antonio\Desktop\blinkled\blink.lst".
    Clean: Deleted file "M:\ISIS\blink.cof".
    Clean: Done.
    Executing: "C:\Program Files\Microchip\MPASM Suite\MPASMWIN.exe" /q /p16F876A "blink.asm" /l"blink.lst" /e"blink.err"
    Warning[205] C:\USERS\ANTONIO\DESKTOP\BLINKLED\BLINK.ASM 1 : Found directive in column 1. (list)
    Warning[205] C:\USERS\ANTONIO\DESKTOP\BLINKLED\BLINK.ASM 4 : Found directive in column 1. (__CONFIG)
    Executing: "C:\Program Files\Microchip\MPASM Suite\mplink.exe" /p16F876A "C:\Users\Antonio\Desktop\blinkled\blink.o" /z__MPLAB_BUILD=1 /o"blink.cof" /M"blink.map" /W /x
    MPLINK 4.43, Linker
    Device Database Version 1.9
    Copyright (c) 1998-2011 Microchip Technology Inc.
    Errors : 0

    Loaded M:\ISIS\blink.cof.
    ----------------------------------------------------------------------
    Release build of project `M:\ISIS\16f87.mcp' succeeded.
    Language tool versions: MPASMWIN.exe v5.46, mplink.exe v4.44, mplib.exe v4.44
    Tue Jan 15 23:53:52 2013
    ----------------------------------------------------------------------
    BUILD SUCCEEDED


    PICkit 3 detected
    Connecting to PICkit 3...
    Firmware Suite Version...... 01.27.20
    Firmware type......................Midrange
    PICkit 3 Connected.
    Device ID Revision = 00000008

    Programming...
    Programming/Verify complete

    Programming...
    Programming/Verify complete

    Programming...
    Programming/Verify complete

    no blink. I have also changed the led. :(((((
     
  11. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    As a bit of an aside, the Pickit 3 automatically releases from reset, right?

    Have you verified your supply voltages with a DMM?

    Perhaps drawing schematic will help us figure out your problem, though I am inclined to believe it is an oscillator problem...
     
  12. absf

    Senior Member

    Dec 29, 2010
    1,492
    372
    Show a photograph of your breadboard connections.

    Allen
     
  13. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    I was thinking about the same. If the PICKIT 3 is used for power. The power must be turned on in MPLAB. Also Tony. Since you use Isis Proteus post your schematic. Showing how you connect to your PIC. Remember all power pins should be connected. Your PIC has two ground pins. PIN 8 and 19
     
Loading...