# How does one go about programming a PIC microcontroller?

I am working on my first project using a PIC microncontroller, a PIC12F675.

How do I load a program onto the microcontroller?

I bought this programmer to start, but don't really know how to use it.

I'm working with Windows 7.
I installed WinPic800 but it doesnt seem to be detecting the programmer when I plug it in via USB. When I click "Read All" (or any other function for that matter), I get the error "Failed to open Ind.#0".

Can anyone tell me what I could be doing wrong?

Thanks

• Multiple questions; pick one or expect this to be closed. – Brian Carlton Aug 15 '11 at 1:34
• Ok. I want to know why WinPic isn't detecting the programmer and microcontroller, but we'll let a moderator decide if this is too many questions. Oh and be nicer or expect no one to ever love you. – Shubham Aug 15 '11 at 1:51
• @Shubham I don't thin Brain was rude at all. I do agree that this question is overly broad with several unrelated questions. As for your comment on letting a moderator decide, this is a community moderated site with mods only around to help out the community. Brian and any other users have full right to say that a question should be closed, if 5 users agree, it will be closed. – Kellenjb Aug 15 '11 at 2:13
• Ok I edited the question to be less broad. – Shubham Aug 15 '11 at 3:36

Get a better programmer, such as the Microchip PICkit 2 or PICkit 3. They work "out of the box" with the MPLAB IDE, and you get in-circuit debugging as well as programming (you need a special header if you want to debug the 12F675 as it doesn't have on-chip debug hardware). You will also get plenty of help from other users on the Microchip support forums, and you can use it with Microchip's low-cost development boards.

Here is a little test program for the 12F675:

 
;flasher.asm
;simple program for PIC12F675 to flash LED on pin 5
;uses Timer0 for delay

list      p=12f675  ;list directive to define processor
#include "p12f675.inc"  ;processor specific variable definitions

errorlevel -302     ;suppress "not in bank 0" message

__CONFIG  _INTRC_OSC_CLKOUT

;-----------------------------------------------------------------
;defines
;-----------------------------------------------------------------

#define LED 2   ;GP2 (pin 5)
#define INIT_COUNT 10   ;

;-----------------------------------------------------------------
;variables
;-----------------------------------------------------------------
cblock  0x20
tick_counter
endc

;------------------------------------------------------------------
;initialisation
;------------------------------------------------------------------

;reset vector
org 0
nop
goto    Main

;interrupt vector
org 4
banksel INTCON
bcf     INTCON,T0IF     ;clear Timer0 interrupt flag
movlw   INIT_COUNT      ;re-initialise count
movwf   TMR0
decf    tick_counter,f
retfie

Main:
banksel OSCCAL          ;calibrate oscillator
call 0x3FF              ;Get the cal value
movwf OSCCAL            ;Calibrate
banksel ANSEL
movwf   ANSEL
bankseL CMCON
movlw   07h         ;comparators off
movwf   CMCON
banksel TRISIO
bcf     TRISIO,LED  ;LED output GPIO5 (pin 2)
banksel OPTION_REG
movlw   b'00000011'     ;prescaler 1/128
movwf   OPTION_REG      ;
banksel TMR0
movlw   INIT_COUNT      ;initialise timer count value
clrf    tick_counter
movwf   TMR0
bsf     INTCON,GIE      ;enable global interrupt
bsf     INTCON,T0IE     ;enable Timer0 interrupt
banksel GPIO

;-----------------------------------------------------------------------
;main program loop
;-----------------------------------------------------------------------

loop:
bsf     GPIO,LED
call    dly
bcf     GPIO,LED
call    dly
goto    loop

dly:
movlw   0x10
movwf   tick_counter
dly1:
movf    tick_counter,f
skpz
goto    dly1
return

end




• Why is this a bad programmer? The reason I got this one was because it was cheap...the PICKit programmers can be quite expensive compared to cheap ones like this. – Shubham Aug 15 '11 at 22:31
• If you don't know how to use it it is very expensive for what it can do for you! Either get the manual and read it fron to back, and get the programmer to work, or ditch it. Your ebay link suggests that it might be second hand, so it could be defective. – Wouter van Ooijen Aug 25 '11 at 19:59