Best way to learn PICs?

Discussion in 'Embedded Systems and Microcontrollers' started by tracecom, Apr 22, 2012.

  1. tracecom

    Thread Starter AAC Fanatic!

    Apr 16, 2010
    3,869
    1,393
    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.
     
  2. MrChips

    Moderator

    Oct 2, 2009
    12,431
    3,360
    Rbeckett likes this.
  3. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    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.
     
    Eric007 likes this.
  4. MrChips

    Moderator

    Oct 2, 2009
    12,431
    3,360
    I should have asked first, do you want to learn to program in ASM or C?
     
  5. panic mode

    Senior Member

    Oct 10, 2011
    1,320
    304
  6. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    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.
     
  7. tracecom

    Thread Starter AAC Fanatic!

    Apr 16, 2010
    3,869
    1,393
    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.
     
  8. MrChips

    Moderator

    Oct 2, 2009
    12,431
    3,360
    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
     
    Eric007 likes this.
  9. tracecom

    Thread Starter AAC Fanatic!

    Apr 16, 2010
    3,869
    1,393
    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: Apr 22, 2012
  10. MrChips

    Moderator

    Oct 2, 2009
    12,431
    3,360
    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.
     
  11. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    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.
     
  12. tracecom

    Thread Starter AAC Fanatic!

    Apr 16, 2010
    3,869
    1,393
    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.

    Code ( (Unknown Language)):
    1. ;**********************************************************************
    2. ;                                                                     *
    3. ;    Filename:      BA_L1-Turn_on_LED-12F509.asm                      *
    4. ;    Date:          4/22/12                                           *
    5. ;    File Version:  0.1                                               *
    6. ;                                                                     *
    7. ;    Author:        Charles Hampton                                   *
    8. ;    Company:       Trace Communications                              *
    9. ;                                                                     *
    10. ;**********************************************************************
    11. ;                                                                     *
    12. ;    Architecture: Baseline PIC                                       *
    13. ;    Processor:    12F509                                             *
    14. ;                                                                     *
    15. ;**********************************************************************
    16. ;                                                                     *
    17. ;    Files required: P12F509.INC                                      *
    18. ;                                                                     *
    19. ;**********************************************************************
    20. ;                                                                     *
    21. ;    Descripton:  Lesson 1, Example 1                                 *
    22. ;                                                                     *
    23. ;    Turns on LED. LED remains on until power is removed.             *
    24. ;                                                                     *
    25. ;**********************************************************************
    26. ;                                                                     *
    27. ;    Pin assignments:                                                 *
    28. ;        GP1 = red indicator LED                                      *
    29. ;                                                                     *
    30. ;**********************************************************************
    31.     list      p=12F509            ; list directive to define processor
    32.     #include <p12F509.inc>        ; processor specific variable definitions
    33. ;***** CONFIGURATION
    34.                 ; ext reset, no code protect, no watchdog, int RC clock
    35.     __CONFIG   _MCLRE_ON & _CP_OFF & _WDT_OFF & _IntRC_OSC
    36. ;***** RC CALIBRATION
    37. RCCAL   CODE    0x3FF             ; processor reset value
    38.         res 1                     ; holds internal RC cal value, as a mov1w k
    39. ;***** RESET VECTOR ***************************************************
    40. RESET   CODE   0x3FF      ; effective reset vector
    41.         movwf  OSCCAL     ; apply internal RC factory calibration
    42.  
    43. ;***** MAIN PROGRAM ***************************************************
    44. ;***** Initialization
    45. start
    46.         mov1w b'111101'       ; configure GP1 (only) as an output
    47.         tris  GPIO
    48.         mov1w b'000010'       ; set GP1 high
    49.         movwf GPIO
    50. ;***** Main loop
    51.         goto  $               ; loop forever
    52.        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
     
  13. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    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.
     
  14. tracecom

    Thread Starter AAC Fanatic!

    Apr 16, 2010
    3,869
    1,393
    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: Apr 22, 2012
  15. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    OK, you need "CODE 0x00" after movwf OSCCAL.
     
  16. tracecom

    Thread Starter AAC Fanatic!

    Apr 16, 2010
    3,869
    1,393
    I have flashing. However, this process seems terribly convoluted compared to PICAXE. :confused: Hopefully, it will get easier.
     
  17. KansaiRobot

    Active Member

    Jan 15, 2010
    318
    5
    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.

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

    Active Member

    Jan 15, 2010
    318
    5
    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: Apr 22, 2012
  19. tracecom

    Thread Starter AAC Fanatic!

    Apr 16, 2010
    3,869
    1,393
    Thanks. I hope you can find it.
     
  20. nickelflipper

    Active Member

    Jun 2, 2010
    280
    35
    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.
     
    Eric007 likes this.
Loading...