PIC Microcontrollers - Getting Started (again)

Thread Starter

SubnetMask

Joined May 3, 2009
8
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

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

retched

Joined Dec 5, 2009
5,207
thatoneguy..... I dont think t06afre was referring to you.

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

t06afre

Joined May 11, 2009
5,934
thatoneguy..... I dont think t06afre was referring to you.

I think he was asking the OP what programming equipment HE had. ;)
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.
 

spinnaker

Joined Oct 29, 2009
7,830
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.
 

Thread Starter

SubnetMask

Joined May 3, 2009
8
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.
 

retched

Joined Dec 5, 2009
5,207
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.
 

maxpower097

Joined Feb 20, 2009
816
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.
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.
 

Thread Starter

SubnetMask

Joined May 3, 2009
8
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?
 

thatoneguy

Joined Feb 19, 2009
6,359
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.
 
Top