# PICKit 3 programming problems!

#### ruuhkis

Joined Jan 19, 2012
8
Hello guys!
I've finally got my PICKit to succesfully program code on my PIC but it doesn't seem to work properly. MPLab identifies my PIC and it programs and verifies the program correctly but the code doesn't seem to run! I've also tried to use any led blink code that I found online, it builds correctly and programs but doesn't seem to run at all. I've tried to measure the power levels from the pins with mutlimeter also did hook up led there but it didn't lit. I've also changed the code so it will only turn the pin on etc. but still nothing happens. I used diagram from PICKit 3 user guide link at the page DS51795B-page 2 with title " PROPER CONNECTIONS FOR PROGRAMMIN" I ended up with this kind of setup. link to HUGE image
I read somewhere that I'd need some components such as diode and capacitor added somewhere to filter noise. Also is it okay that I use 10k ohm resistor instead of 4.7k resistors as I don't have one around? I am using PIC PIC16F628A. Any help / suggestions are great!

Also! Heres the code:

Rich (BB code):
include <p16f628a.inc>

LED equ 02h;
TRISA equ 85h;
PORTA equ 05h;

org	0

BSF STATUS, RP0; GO TO BANK 1
MOVLW 00h ;SET W REGISTER TO 0
MOVWF TRISA; MOVE W REGISTER TO TRISA REGISTER SETTING PINS TO OUTPUT
BCF STATUS, RP0; GO TO BANK 0

MOVLW LED; SET W REGISTER TO 2
MOVWF PORTA; MOVE W TO PORTA SETTING PINS HIGH

end

#### peter_morley

Joined Mar 12, 2011
179
Is it possible that your program runs for less than micro seconds and so the led turns on and off at a frequency your eye can not detect?

I have never tried this but will the port pins stay in the same state they were in during the program, even after the program is done executing.

#### ruuhkis

Joined Jan 19, 2012
8
Is it possible that your program runs for less than micro seconds and so the led turns on and off at a frequency your eye can not detect?

I have never tried this but will the port pins stay in the same state they were in during the program, even after the program is done executing.
You woke plenty of questions in my mind.. Gonna run some tests now!
Will comment back when I am done!! (I thought the program wud loop and loop forever.. )
Why don't this work out I made it go on infinite loop etc. and it still doesn't output any voltage!
None of what I tried did work

Last edited:

#### t06afre

Joined May 11, 2009
5,934
Try this. Also do you power the 16f628 from the PICKIT or a power supply. You can power the PIC from the PICKIT. But by default this option is turned off
Rich (BB code):
;not tested in mplab so it may be errors
include <p16f628a.inc>

LED equ 02h;
;TRISA equ 85h;
;PORTA equ 05h;
;The latter is defined in the p16f628a.inc file not needed

org    0

CLRF PORTA ;Initialize PORTA by
;setting
;output data latches
MOVLW 0x07 ;Turn comparators off and
MOVWF CMCON ;enable pins for I/O
;functions
BCF STATUS, RP1
BSF STATUS, RP0 ;Select Bank1
MOVLW 0x00 ;Value used to initialize
;data direction
MOVWF TRISA ;Set port A  as inputs
;TRISA<5> always
;TRISA<7:6>
;depend on oscillator​;mode
loop:
MOVLW LED; SET W REGISTER TO 2
MOVWF PORTA; MOVE W TO PORTA SETTING PINS HIGH
goto loop

#### Markd77

Joined Sep 7, 2009
2,806
Put this line after the include line in T06AFRE's code:
Rich (BB code):
    __CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _INTRC_OSC_NOCLKOUT & _MCLRE_ON & _LVP_OFF
With these settings the MCLR pin should be connected to +ve of the supply with a 10K resistor.
Also I think it should be #include, but include may work.

#### Markd77

Joined Sep 7, 2009
2,806
Is it possible that your program runs for less than micro seconds and so the led turns on and off at a frequency your eye can not detect?

I have never tried this but will the port pins stay in the same state they were in during the program, even after the program is done executing.
Without a loop, the PIC continues executing through the whole program memory, which I think on a blank PIC is full of NOPs and will then start again at the first instruction. It's a bad idea, but for this simple program there would be no observable difference.

#### ruuhkis

Joined Jan 19, 2012
8
Try this. Also do you power the 16f628 from the PICKIT or a power supply. You can power the PIC from the PICKIT. But by default this option is turned off
Rich (BB code):
;not tested in mplab so it may be errors
include <p16f628a.inc>

LED equ 02h;
;TRISA equ 85h;
;PORTA equ 05h;
;The latter is defined in the p16f628a.inc file not needed

org    0

CLRF PORTA ;Initialize PORTA by
;setting
;output data latches
MOVLW 0x07 ;Turn comparators off and
MOVWF CMCON ;enable pins for I/O
;functions
BCF STATUS, RP1
BSF STATUS, RP0 ;Select Bank1
MOVLW 0x00 ;Value used to initialize
;data direction
MOVWF TRISA ;Set port A  as inputs
;TRISA<5> always
;TRISA<7:6>
;depend on oscillator​;mode
loop:
MOVLW LED; SET W REGISTER TO 2
MOVWF PORTA; MOVE W TO PORTA SETTING PINS HIGH
goto loop
Hey and thanks for quick response!
You only forget to come back to first bank, other that that the code was perfect. Only this is that it still didn't give even a signal of working on my PIC after programming it.
Is it normal that the programming takes under second with this size of code or is something going wrong? And is it possible that there's something that could improve the circuit or just anything? Or can the chip be damaged as I might have been input something on wrong ports testing how can i get it to work... Or would it give me error report not being able to program or something? I think the code is perfect, it must be the circuit or the chip?

Put this line after the include line in T06AFRE's code:
Rich (BB code):
    __CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _INTRC_OSC_NOCLKOUT & _MCLRE_ON & _LVP_OFF
With these settings the MCLR pin should be connected to +ve of the supply with a 10K resistor.
Also I think it should be #include, but include may work.
Thanks dude, giving it a shot ASAP and reporting back!

#### Markd77

Joined Sep 7, 2009
2,806
Programming time of under a second is normal, have you tried adding the __config line?

#### ruuhkis

Joined Jan 19, 2012
8
Programming time of under a second is normal, have you tried adding the __config line?
Thanks for the info.
I did add it but I am trying to make sure that VE+ means the positive energy source(it is, right?).
Also, I still keep pickits MCLR connected to chips MCLR, right?

#### t06afre

Joined May 11, 2009
5,934
I think the main culprit may be the missing __config setting. DoH! why did I not see that. I have not used the 16f628. But it is a common mistake to forget turning off analog functions then using the port pins as common digital IO. By default after power up. Pins with analog functions will have this function not digital I/O functions. And this may cause all kinds of strange behavior. This is true for 16F and 18F devices. And probably the rest of Microchip controllers also

#### ruuhkis

Joined Jan 19, 2012
8
I think the main culprit may be the missing __config setting. DoH! why did I not see that. I have not used the 16f628. But it is a common mistake to forget turning off analog functions then using the port pins as common digital IO. By default after power up. Pins with analog functions will have this function not digital I/O functions. And this may cause all kinds of strange behavior. This is true for 16F and 18F devices. And probably the rest of Microchip controllers also
Amazing got it working, didn't have to connect anything additional to original, or should i do that anyway?
Now I've just to get this blink..

PS. super big thanks for you t06afre and Markd77!!

#### t06afre

Joined May 11, 2009
5,934
Rich (BB code):
;not tested in mplab so it may be errors
include <p16f628a.inc>
__CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _INTRC_OSC_NOCLKOUT & _MCLRE_ON & _LVP_OFF
cblock 0x20
Delay1                   ; Define two file registers for the
Delay2                   ; delay loop
endc

org 0
Start:
banksel PORTA
CLRF PORTA ;Initialize PORTA by
;setting
;output data latches
banksel CMCON
MOVLW 0x07 ;Turn comparators off and
MOVWF CMCON ;enable pins for I/O
;functions
banksel TRISA ;Select Bank1
MOVLW 0x00 ;Value used to initialize
;data direction
MOVWF TRISA ;Set port A  as inputs
;TRISA<5> always
;TRISA<7:6>
;depend on oscillator
;mode
banksel PORTA
MainLoop:
bsf       PORTA,0             ; turn on LED on A0
OndelayLoop:
decfsz    Delay1,f            ; Waste time.
goto      OndelayLoop         ; The Inner loop takes 3 instructions per loop * 256 loopss = 768 instructions
decfsz    Delay2,f            ; The outer loop takes and additional 3 instructions per lap * 256 loops
goto      OndelayLoop         ; (768+3) * 256 = 197376 instructions / 1M instructions per second = 0.197 sec.
; call it a two-tenths of a second.

bcf       PORTA,0             ; Turn off LED A0
OffDelayLoop:
decfsz    Delay1,f            ; same delay as above
goto      OffDelayLoop
decfsz    Delay2,f
goto      OffDelayLoop
goto      MainLoop            ; Do it again...
end

#### ruuhkis

Joined Jan 19, 2012
8
Rich (BB code):
;not tested in mplab so it may be errors
include <p16f628a.inc>
__CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _INTRC_OSC_NOCLKOUT & _MCLRE_ON & _LVP_OFF
cblock 0x20
Delay1                   ; Define two file registers for the
Delay2                   ; delay loop
endc

org 0
Start:
banksel PORTA
CLRF PORTA ;Initialize PORTA by
;setting
;output data latches
banksel CMCON
MOVLW 0x07 ;Turn comparators off and
MOVWF CMCON ;enable pins for I/O
;functions
banksel TRISA ;Select Bank1
MOVLW 0x00 ;Value used to initialize
;data direction
MOVWF TRISA ;Set port A  as inputs
;TRISA<5> always
;TRISA<7:6>
;depend on oscillator
;mode
banksel PORTA
MainLoop:
bsf       PORTA,0             ; turn on LED on A0
OndelayLoop:
decfsz    Delay1,f            ; Waste time.
goto      OndelayLoop         ; The Inner loop takes 3 instructions per loop * 256 loopss = 768 instructions
decfsz    Delay2,f            ; The outer loop takes and additional 3 instructions per lap * 256 loops
goto      OndelayLoop         ; (768+3) * 256 = 197376 instructions / 1M instructions per second = 0.197 sec.
; call it a two-tenths of a second.

bcf       PORTA,0             ; Turn off LED A0
OffDelayLoop:
decfsz    Delay1,f            ; same delay as above
goto      OffDelayLoop
decfsz    Delay2,f
goto      OffDelayLoop
goto      MainLoop            ; Do it again...
end
You guys are way too nice for me! Thanks again, you've been such a great help! Its glad that I joined in such community. Gonna give this a try very soon! And I have now whole weekend to learn! Can you answer me one more question? Is the connection from MCLR pin to V+ of the supply with a 10K resistor required? And what is it for? It wasn't on the docs so just wondering

#### CraigHB

Joined Aug 12, 2011
127
Without a loop, the PIC continues executing through the whole program memory, which I think on a blank PIC is full of NOPs and will then start again at the first instruction. It's a bad idea, but for this simple program there would be no observable difference.
I've never actually tried to run a PIC without a loop either intentionally or unintentionally. Wouldn't the program counter just keep going until it rolls over at which time it starts counting again from zero?