PIC Microcontrollers - Getting Started (again)

Discussion in 'Embedded Systems and Microcontrollers' started by SubnetMask, Nov 12, 2010.

  1. SubnetMask

    Thread Starter New Member

    May 3, 2009
    8
    0
    I'm getting back into trying to learn how to program PICs, and I have been reading "The PIC Microcontroller: Your Personal Introductory Course, Third edition" by John Morton. The problem is, it's not helping. I haven't gotten very far into the book, but I tried making the first program, and even when I copy his example program line for line, when I compile it in Microcode Studio/PICBasic Pro, it errors out with a bunch of syntax errors (see below). Does anyone have any ideas why it's erroring, or maybe a suggestion for a better book for a beginner?

    Thanks

    Code ( (Unknown Language)):
    1. '****************************************************************
    2. '*  Name    : UNTITLED.BAS                                      *
    3. '*  Notice  : Copyright (c) 2010 [select VIEW...EDITOR OPTIONS] *
    4. '*          : All Rights Reserved                               *
    5. '*  Date    : 11/12/2010                                        *
    6. '*  Version : 1.0                                               *
    7. '*  Notes   :                                                   *
    8. '*          :                                                   *
    9. '****************************************************************
    10. 'PROGRAM FUNCTION: To turn on an LED
    11. '    list    P=16F819
    12.     include "C:\Program Files\Microchip\MPASM Suite\P16F819.INC"
    13.  
    14. '    __config    _RC_OSC &_WDT_OFF &_CP_OFF
    15.  
    16. '===============================================================
    17. 'Declarations
    18. porta   equ     05
    19.         org     1FF
    20.         goto    Start
    21.         org     0
    22.  
    23. '===============================================================
    24. 'Subroutines
    25. Init    clrf    porta   'reset PortA
    26.         movlw   b'0000' 'RA0: LED, RA1-3: not connected
    27.         tris    porta
    28.         retlw   0
    29.  
    30. '===============================================================
    31. 'Program Start
    32. Start   call    Init    'Sets up inputs and outputs
    33. Main    bsf     porta,0 'Turns on LED
    34. goto    Main            'Loops back to main
    35. END  
    36.  
    Code ( (Unknown Language)):
    1. FATAL ERROR: Too many errors. (21)
    2. C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\P16F819.INC ERROR Line 35: Syntax error.
    3. C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\P16F819.INC ERROR Line 36: Syntax error.
    4. C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\P16F819.INC ERROR Line 45: Syntax error.
    5. C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\P16F819.INC ERROR Line 46: Syntax error.
    6. C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\P16F819.INC ERROR Line 50: Syntax error.
    7. C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\P16F819.INC ERROR Line 51: Syntax error.
    8. C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\P16F819.INC ERROR Line 52: Syntax error.
    9. C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\P16F819.INC ERROR Line 53: Syntax error.
    10. C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\P16F819.INC ERROR Line 54: Syntax error.
    11. C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\P16F819.INC ERROR Line 55: Syntax error.
    12. C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\P16F819.INC ERROR Line 56: Syntax error.
    13. C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\P16F819.INC ERROR Line 57: Syntax error.
    14. C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\P16F819.INC ERROR Line 58: Syntax error.
    15. C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\P16F819.INC ERROR Line 59: Syntax error.
    16. C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\P16F819.INC ERROR Line 60: Syntax error.
    17. C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\P16F819.INC ERROR Line 61: Syntax error.
    18. C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\P16F819.INC ERROR Line 276: Redefiniton of LABEL __BADRAM.
    19. C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\P16F819.INC ERROR Line 277: Redefiniton of LABEL __BADRAM.
    20. C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\P16F819.INC ERROR Line 278: Redefiniton of LABEL __BADRAM.
    21. C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\P16F819.INC ERROR Line 317: Redefiniton of LABEL LIST.
    22. ERROR Line 24: Redefiniton of LABEL org. (Prog1b.pbp)
    23.  
     
  2. retched

    AAC Fanatic!

    Dec 5, 2009
    5,201
    312
    I think your problem is that you are compliling an Assembly program in a BASIC compiler.

    Two different languages. ;)
     
  3. blueroomelectronics

    AAC Fanatic!

    Jul 22, 2007
    1,758
    98
    Problem with that book is it dates back to 1998. The 16F54 is a real fossil.
     
  4. retched

    AAC Fanatic!

    Dec 5, 2009
    5,201
    312
    The code says 16F819.. Are they code compatible?
     
  5. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    The line numbers in the error listing are beyond the number of lines in the code you posted. :confused:
     
  6. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    The errors are referring to the inc file.
    But anyway what kind of equipment do you have for programming the PIC micro?
     
  7. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    ICD 2, PicKit 2, PicKit 3, ICD 3, quite a few of their boards.
     
  8. retched

    AAC Fanatic!

    Dec 5, 2009
    5,201
    312
    thatoneguy..... I dont think t06afre was referring to you.

    I think he was asking the OP what programming equipment HE had. ;)
     
  9. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    I gotta stop tryin to post after going out for "one or two". Next build will be a BAC Keyboard Interlock.
     
  10. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Yes I meant SubnetMask. So which way do plan to program your PIC SubnetMask? If you plan to use assembler then the free MPLAB will be the best tool. The Microcode Studio/PICBasic Pro is not a tool for doing Assembler I think.
    It is also hard to learn any programming by only reading. You have to do some actual coding. Do some dumb errors, and then learn how to debug to find them. The datasheet is also a source for learning as it is full of example code in Assembler.
     
  11. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,887
    1,014
    Try checking out the lessons here. I think they also have assembler lessons but I would go with C or BASIC.

    But even though assembler is harder to learn, there is just something about it I like. I guess maybe because that is where I started many, many years ago.
     
  12. SubnetMask

    Thread Starter New Member

    May 3, 2009
    8
    0
    Thanks for the info; yes, the code says 16F819 as that's what I was going to use (I have some 16F819's, 12F683's, 16F876A's and a 16F627.

    Right now, I have a Velleman K8048 (yes, I know not the greatest, but with WinPIC, It'll program all the PIC's I have), but I'm considering a EasyPIC6.
     
  13. retched

    AAC Fanatic!

    Dec 5, 2009
    5,201
    312
    AH HA!

    I have the K8048 and the EasyPIC6!

    And I am awesome, so I would say you are on the right track (ahem!) ;)

    The EasyPIC6 has built in programmer, buttons for each pin, powersupply, pull-up/down resistors for each pin, LED's for each pin USB, RS232, and much more.

    You can still learn from scratch without all the wiring..BUT you still learn the connections.

    Very nice.
     
  14. maxpower097

    Well-Known Member

    Feb 20, 2009
    795
    388
    You will be a much better embedded programmer if you learn ASM then C or Basic. With C and basic the code is pretty much written for you. But in ASM you have to track everything and code everything from scratch. So while it is harder and has a much larger learning curve. If you put some good time into learning ASM and learn the way it works. Your C programming will be 10 times cleaner and much better. Plus you will be able to debug way better. I had to learn ASM in a working environment with a pic16LF877A and it litterally had about 40 words of memory left and that was it. So first I had to look at the 5000 lines of ASM. Luckily the original programmer was a college teacher so he labeled everything really good. Actaully I think it was a class project where groups of students coded different sections of the code. Well they wanted a bunch of changes and the original programmer was MIA. So it got throw onto my plate. I basically sat there for 2-3 weeks just looking at all this ASM code and no idea what I was doing. But I slowly started to understand it and was able to condense the previous code to make room for the security system I had to put in. All in all it worked out and I figured it out. Then I left that job when the economy crashed and decided to start learning uC's on my own feeling they will be the future and there will be money in it.
     
  15. SubnetMask

    Thread Starter New Member

    May 3, 2009
    8
    0
    I started reading Amer Iqbal's "PIC Microcontrollers for absolute beginners", and it hasn't been too bad, but I've gotten to the programming section (chapter 4), and he's teaching BASIC. I'd like to learn ASM because as a few of you have said, it would (should) make me a better programmer, and I think I'd have a better understanding of how the controllers work. Do any of you know any good books (preferably pdf or epub ebooks) I could get to help me learn ASM?
     
  16. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    I think starting in assembly gets many hobbyists discouraged quickly.

    Something like BoostC allows you to have inline assembly code, with all the memory management and bank switching done by the compiler for the rest of the code.

    Assembly is preferred for highly optimized code, but in general, somebody new to assembly programming will write less optimized code than a C compiler will create from C language. Sourceboost has both C and Basic at free to low cost for design, and I've never had an issue with them or support. There are other compilers around as well. Try a few out and decide is the best way to do it.

    It is a rather steep learning curve, and getting something like the EasyPIC Dev board helps a lot with that curve, a high level language does more. Once you are more versed and practiced, writing assembly code for a breadboard project will be relatively easy compared to what you are trying now.
     
  17. rajbex

    New Member

    Nov 2, 2009
    22
    0
Loading...