Electronic – How does one go about programming a PIC microcontroller

picprogramming

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

Best Answer

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 movlw 11h ;AN0 as analog input,conversion clock Fosc/8 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