Best way to learn PICs?

Thread Starter

tracecom

Joined Apr 16, 2010
3,944
I have successfully written and implemented some code for the PICAXE family. I have a PICkit2, a Low Pin Count Demo board, a small selection of PICs, and I would like to learn to program them. I have downloaded the Gooligum Base level tutorials, and tried to use Lesson 1, but find it daunting. Is there a better way to start?

Thanks.
 

Markd77

Joined Sep 7, 2009
2,806
I find that if you can find some well documented code, that helps things absorb, maybe something from the later lessons in the tutorial.
Try the simulator in MPlab, you can step through the code and watch the flow and the registers changing, you are going to need to get acquainted with it sooner or later, I'd recommend sooner.
 

Markd77

Joined Sep 7, 2009
2,806
They have assembler tutorials as well:
http://www.gooligum.com.au/tut_baseline.html
I looked at the assembler ones a while ago and they look pretty good.
I think starting with the baseline PICs is a good idea before moving on to the ones with more features (and pitfalls). I learned on the PIC16F84 which is pretty similar to the baseline ones.
 

Thread Starter

tracecom

Joined Apr 16, 2010
3,944
Ultimately, I want to use C, but the Gooligum tutorial and some other sources recommend starting with assembly language before progressing to a higher level language. I don't know what's best.

The PICs that I have are 12F509, 16F505, 16F506, 16F628A, and 16F684. I also have 2 12F629's on back order. I assume that it is better to start with the 12F509; is that correct?

At this point, I am having trouble just remembering/understanding the PIC terminology, e.g., the register names and functions. :eek:

ETA: 2 new posts since I started writing this one, so some of what I wrote may be redundant. Thanks for every reply.

Yes, the PICkit2 came with the CD and I have that on my computer.
 

MrChips

Joined Oct 2, 2009
30,821
ASM or C? Depends.

1) Are you a student wanting to be an expert one of these days?
2) Or do you just want to experiment with controllers?

Answer 1) - Learn ASM first
Answer 2) - Jump into C
 

Thread Starter

tracecom

Joined Apr 16, 2010
3,944
ASM or C? Depends.

1) Are you a student wanting to be an expert one of these days?
2) Or do you just want to experiment with controllers?

Answer 1) - Learn ASM first
Answer 2) - Jump into C
I am a student of life, but doubt that I will ever be an expert on MCU's. :) I have a few projects that use PICAXE's, and I would like to convert them to use PICs. The projects include a thermostat, hydrostat, and a stepper controller.

I am off to church now; be back in a couple of hours.
 
Last edited:

MrChips

Joined Oct 2, 2009
30,821
Ok, start with HI-TECH C and when you get the itch you can go back and try to understand (but not bother to learn) ASM.
 

Markd77

Joined Sep 7, 2009
2,806
The PICs that I have are 12F509, 16F505, 16F506, 16F628A, and 16F684. I also have 2 12F629's on back order. I assume that it is better to start with the 12F509; is that correct?
The 505 is basically a 509 with more pins so you could dedicate the programming pins to the PICKIT and use the others as I/O, so you wouldn't have to worry too much about circuitry causing any programming problems.
 

Thread Starter

tracecom

Joined Apr 16, 2010
3,944
I am so lost that I tried to go back to the Gooligum tutorial. I have spent two hours writing code that is supposed to turn on an LED. And it won't compile. I get all sorts of error messages and warnings, and I have no idea what to do about them. Any help would be appreciated.

Rich (BB code):
;**********************************************************************
;                                                                     *
;    Filename:      BA_L1-Turn_on_LED-12F509.asm                      *
;    Date:          4/22/12                                           *
;    File Version:  0.1                                               *
;                                                                     *
;    Author:        Charles Hampton                                   *
;    Company:       Trace Communications                              *
;                                                                     * 
;**********************************************************************
;                                                                     *
;    Architecture: Baseline PIC                                       *
;    Processor:    12F509                                             *
;                                                                     *
;**********************************************************************
;                                                                     *
;    Files required: P12F509.INC                                      *
;                                                                     *
;**********************************************************************
;                                                                     *
;    Descripton:  Lesson 1, Example 1                                 *
;                                                                     *
;    Turns on LED. LED remains on until power is removed.             *
;                                                                     *
;**********************************************************************
;                                                                     *
;    Pin assignments:                                                 *
;        GP1 = red indicator LED                                      *
;                                                                     *
;**********************************************************************
    list      p=12F509            ; list directive to define processor
    #include <p12F509.inc>        ; processor specific variable definitions
;***** CONFIGURATION
                ; ext reset, no code protect, no watchdog, int RC clock
    __CONFIG   _MCLRE_ON & _CP_OFF & _WDT_OFF & _IntRC_OSC
;***** RC CALIBRATION
RCCAL   CODE    0x3FF             ; processor reset value
        res 1                     ; holds internal RC cal value, as a mov1w k
;***** RESET VECTOR ***************************************************
RESET   CODE   0x3FF      ; effective reset vector
        movwf  OSCCAL     ; apply internal RC factory calibration
 
;***** MAIN PROGRAM ***************************************************
;***** Initialization
start
        mov1w b'111101'       ; configure GP1 (only) as an output
        tris  GPIO
        mov1w b'000010'       ; set GP1 high
        movwf GPIO
;***** Main loop
        goto  $               ; loop forever
       END
Here is the report.

----------------------------------------------------------------------
Release build of project `C:\Documents and Settings\Charles R. Hampton\Desktop\PIC MCU's\CRH Project Files\BA_L1-Turn_on_LED-12F509.mcp' started.
Language tool versions: MPASMWIN.exe v5.43, mplink.exe v4.41, mplib.exe v4.41
Sun Apr 22 15:49:50 2012
----------------------------------------------------------------------
Make: The target "C:\Documents and Settings\Charles R. Hampton\Desktop\PIC MCU's\CRH Project Files\BA_L1-Turn_on_LED-12F509.o" is out of date.
Executing: "C:\Program Files\Microchip\MPASM Suite\MPASMWIN.exe" /q /p12F509 "BA_L1-Turn_on_LED-12F509.ASM" /l"BA_L1-Turn_on_LED-12F509.lst" /e"BA_L1-Turn_on_LED-12F509.err" /o"BA_L1-Turn_on_LED-12F509.o"
Warning[207] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\BA_L1-TURN_ON_LED-12F509.ASM 51 : Found label after column 1. (mov1w)
Error[124] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\BA_L1-TURN_ON_LED-12F509.ASM 51 : Illegal argument (expected single character)
Message[306] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\BA_L1-TURN_ON_LED-12F509.ASM 51 : Crossing page boundary -- ensure page bits are set.
Warning[207] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\BA_L1-TURN_ON_LED-12F509.ASM 53 : Found label after column 1. (mov1w)
Error[116] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\BA_L1-TURN_ON_LED-12F509.ASM 53 : Address label duplicated or different in second pass (mov1w)
Error[124] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\BA_L1-TURN_ON_LED-12F509.ASM 53 : Illegal argument (expected single character)
Message[306] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\BA_L1-TURN_ON_LED-12F509.ASM 53 : Crossing page boundary -- ensure page bits are set.
Halting build on first failure as requested.
----------------------------------------------------------------------
Release build of project `C:\Documents and Settings\Charles R. Hampton\Desktop\PIC MCU's\CRH Project Files\BA_L1-Turn_on_LED-12F509.mcp' failed.
Language tool versions: MPASMWIN.exe v5.43, mplink.exe v4.41, mplib.exe v4.41
Sun Apr 22 15:49:51 2012
----------------------------------------------------------------------
BUILD FAILED
 

Markd77

Joined Sep 7, 2009
2,806
The problem is that lower case "L" and the number one look the same. It's MOVLW.
There will still be a warning and a message but you can ignore them.
You can double click the error or warning and it will take you to the line.
 

Thread Starter

tracecom

Joined Apr 16, 2010
3,944
The problem is that lower case "L" and the number one look the same. It's MOVLW.
There will still be a warning and a message but you can ignore them.
You can double click the error or warning and it will take you to the line.
Thanks. It still fails, but apparently for a different reason.


ETA: Never mind. I found another error.

2nd ETA: OK, the LED lights. I'll see if I can make it flash. (That's lesson 2. :D)
 
Last edited:

Thread Starter

tracecom

Joined Apr 16, 2010
3,944
I have flashing. However, this process seems terribly convoluted compared to PICAXE. :confused: Hopefully, it will get easier.
 

KansaiRobot

Joined Jan 15, 2010
324
Ultimately, I want to use C, but the Gooligum tutorial and some other sources recommend starting with assembly language before progressing to a higher level language. I don't know what's best.
Not at all! I dont think assembly is even necessary for PICs. I wrote a "how to learn to program a PIC" manual all in C.

The PICs that I have are 12F509, 16F505, 16F506, 16F628A, and 16F684. I also have 2 12F629's on back order. I assume that it is better to start with the 12F509; is that correct?

.
Again no. I learned to program PICs with a 18F directly.
 

KansaiRobot

Joined Jan 15, 2010
324
I have flashing. However, this process seems terribly convoluted compared to PICAXE. :confused: Hopefully, it will get easier.
Programming PICs is easy. (I am now trying to program a SH micro and it is daunting!) but for the love of everything dont use assembly. C is enough... if you give me till tomorrow I will try to look and find a very easy tutorial I found months ago (but I dont promise anything since the bookmark was in my prvious job pc)
 
Last edited:

Thread Starter

tracecom

Joined Apr 16, 2010
3,944
Programming PICs is easy. (I am not trying to program a SH micro and it is daunting!) but for the love of everything dont use assembly. C is enough... if you give me till tomorrow I will try to look and find a very easy tutorial I found months ago (but I dont promise anything since the bookmark was in my prvious job pc)
Thanks. I hope you can find it.
 
Learning a new language takes a lot of patience and extra time. If this is a hobby thing, there is no golden rule that one must learn a particular dialect. If the C or assembler syntax just isn't sinking in, there are plenty of Basic compilers (including free and open source) out there that would do the job.
 
Top