first test 16F876A pic not working

Thread Starter

supertony

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

Rich (BB code):
    list        p=16f876a    
    #include    <p16f876a.inc>    
 
        cblock    0x20    
            CounterA
            CounterB
            CounterC    
        endc
 
    org 0x0000
    goto main
    org 0x0004
    retfie
 
main:
    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'168'
    movwf    CounterC
    movlw    D'168'
    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
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:

t06afre

Joined May 11, 2009
5,934
As I can see it. You have not set config bits. You find the information you need in the include file at the end
Rich (BB code):
;==========================================================================
;
;       Configuration Bits
;
;   NAME            Address
;   CONFIG            2007h
;
;==========================================================================
; The following is an assignment of address values for all of the
; configuration registers for the purpose of table reads
_CONFIG          EQU  H'2007'
;----- CONFIG Options --------------------------------------------------
_FOSC_LP             EQU  H'3FFC'    ; LP oscillator
_LP_OSC              EQU  H'3FFC'    ; LP oscillator
_FOSC_XT             EQU  H'3FFD'    ; XT oscillator
_XT_OSC              EQU  H'3FFD'    ; XT oscillator
_FOSC_HS             EQU  H'3FFE'    ; HS oscillator
_HS_OSC              EQU  H'3FFE'    ; HS oscillator
_FOSC_EXTRC          EQU  H'3FFF'    ; RC oscillator
_RC_OSC              EQU  H'3FFF'    ; RC oscillator
_WDTE_OFF            EQU  H'3FFB'    ; WDT disabled
_WDT_OFF             EQU  H'3FFB'    ; WDT disabled
_WDTE_ON             EQU  H'3FFF'    ; WDT enabled
_WDT_ON              EQU  H'3FFF'    ; WDT enabled
_PWRTE_ON            EQU  H'3FF7'    ; PWRT enabled
_PWRTE_OFF           EQU  H'3FFF'    ; PWRT disabled
_BOREN_OFF           EQU  H'3FBF'    ; BOR disabled
_BODEN_OFF           EQU  H'3FBF'    ; BOR disabled
_BOREN_ON            EQU  H'3FFF'    ; BOR enabled
_BODEN_ON            EQU  H'3FFF'    ; BOR enabled
_LVP_OFF             EQU  H'3F7F'    ; RB3 is digital I/O, HV on MCLR must be used for programming
_LVP_ON              EQU  H'3FFF'    ; RB3/PGM pin has PGM function; low-voltage programming enabled
_CPD_ON              EQU  H'3EFF'    ; Data EEPROM code-protected
_CPD_OFF             EQU  H'3FFF'    ; Data EEPROM code protection off
_WRT_HALF            EQU  H'39FF'    ; 0000h to 0FFFh write-protected; 1000h to 1FFFh may be written to by EECON control
_WRT_1FOURTH         EQU  H'3BFF'    ; 0000h to 07FFh write-protected; 0800h to 1FFFh may be written to by EECON control
_WRT_256             EQU  H'3DFF'    ; 0000h to 00FFh write-protected; 0100h to 1FFFh may be written to by EECON control
_WRT_OFF             EQU  H'3FFF'    ; Write protection off; all program memory may be written to by EECON control
_DEBUG_ON            EQU  H'37FF'    ; In-Circuit Debugger enabled, RB6 and RB7 are dedicated to the debugger
_DEBUG_OFF           EQU  H'3FFF'    ; In-Circuit Debugger disabled, RB6 and RB7 are general purpose I/O pins
_CP_ON               EQU  H'1FFF'    ; All program memory code-protected
_CP_ALL              EQU  H'1FFF'    ; All program memory code-protected
_CP_OFF              EQU  H'3FFF'    ; Code protection off
You use the config bit like this. Also see section 14 in the datasheet
Rich (BB code):
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.
 

ErnieM

Joined Apr 24, 2011
8,377
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:
Rich (BB code):
main:
    banksel PORTB
    movlw   0x0
    movwf   PORTB
    movwf   PORTC
    banksel TRISB
    movwf   TRISB
    movwf   TRISC
 
Last edited:

Markd77

Joined Sep 7, 2009
2,806
Also, I don't see where you set the TRIS B & C registers to zero to make the pins outputs.
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
 

tshuck

Joined Oct 18, 2012
3,534
Still not blinking... ::(
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.
 

Thread Starter

supertony

Joined Jan 15, 2013
33
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.
 

tshuck

Joined Oct 18, 2012
3,534
See my previous post where I said
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.
You need to do that...

Instead of
__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _RC_OSC & _WRT_OFF & _LVP_ON & _CPD_OFF
You should have:
__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _FOSC_HS & _WRT_OFF & _LVP_ON & _CPD_OFF
 

Thread Starter

supertony

Joined Jan 15, 2013
33
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. :(((((
 

tshuck

Joined Oct 18, 2012
3,534
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...
 

t06afre

Joined May 11, 2009
5,934
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...
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
 
Top