Searching \ for '[PIC] Setting out PIC18 Assembly code' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/devices.htm?key=pic
Search entire site for: 'Setting out PIC18 Assembly code'.

Exact match. Not showing close matches.
PICList Thread
'[PIC] Setting out PIC18 Assembly code'
2010\07\07@135457 by Andrew Wood

flavicon
face
 Im trying to write my first program in Assembly for a PIC18. I just
want to set port RB6 high to check things are working. Below is the
assembly Ive written in its entirity. But the MPLAB compiler keeps
throwing the following errors:

Warning[205] C:\USERS\ANDREW\DOCUMENTS\PIC PROJECTS\MAIN.ASM 3 : Found
directive in column 1. (include)
Error[150]   C:\USERS\ANDREW\DOCUMENTS\PIC PROJECTS\MAIN.ASM 11 : Labels
must be defined in a code or data section when making an object file
Error[152]   C:\USERS\ANDREW\DOCUMENTS\PIC PROJECTS\MAIN.ASM 12 :
Executable code and data must be defined in an appropriate section
Warning[205] C:\USERS\ANDREW\DOCUMENTS\PIC PROJECTS\MAIN.ASM 14 : Found
directive in column 1. (END)
Halting build on first failure as requested.

From the examples Im following I cant see whats wrong with the layout
of my code yet obviously something is. Can anyone enlighten me please?

Thanks

====================================
Assembly file follows:
====================================
;MAIN FILE FOR PIC18F13K50 USB CHIP

include "c:\Program Files\Microchip\MPASM Suite\P18F13K50.INC";


;PORTB bit 4 = go
;PORTB bit 5= done
;PORTB bit 6= reset lamp


Main
    bsf PORTB,6

END

2010\07\07@142901 by Philip Pemberton

face
flavicon
face
On 07/07/10 18:54, Andrew Wood wrote:
>   From the examples Im following I cant see whats wrong with the layout
> of my code yet obviously something is. Can anyone enlighten me please?

I think the best way to explain this is to tell you what MPASM code
should look like, then give you an example.

Labels go in the first column, and are almost always terminated with a
colon (:) symbol.
Assembler instructions and directives are indented by one tab (8 spaces).
You can't use an assembly instruction or directive name as a label. So
you can have a label called "MAIN" or "HELLO" (or even "FRED", "JIM",
"SHEILA" or "AReallyLongCamelCasedName"), but not "MOVLW", "INCLUDE" or
anything like that.


Now let's go through those errors and your code one-by-one...

> Warning[205] C:\USERS\ANDREW\DOCUMENTS\PIC PROJECTS\MAIN.ASM 3 :
> Found directive in column 1. (include)

This is telling you there's a Warning on line 3 -- you've got an INCLUDE
directive in column 1...

> include "c:\Program Files\Microchip\MPASM Suite\P18F13K50.INC";

Tab that in one line, and get rid of the "C:\..." -- MPASM has an
internal search path which it scans for include files. By default, that
path contains the directory containing the ASM file, and the directory
where MPASM lives.


> Error[150]   C:\USERS\ANDREW\DOCUMENTS\PIC PROJECTS\MAIN.ASM 11 :
> Labels must be defined in a code or data section when making an
> object file

MPASM thinks you're trying to make an object file. You're doing things
which suggest you actually want a HEX file that you can program straight
into the PIC. You also haven't specified a PIC type, so MPASM is
probably getting VERY confused. Above the "include" line, add this line:

        LIST P=18F13K50, R=DEC, F=INHX16

This sets:
  - The PIC type to PIC18F13K50
  - The Default Radix to decimal (base-10)
  - The output format to 16-bit Intel Hex

> Error[152]   C:\USERS\ANDREW\DOCUMENTS\PIC PROJECTS\MAIN.ASM 12 :
> Executable code and data must be defined in an appropriate section

More fallout from not having a LIST statement.

> Warning[205] C:\USERS\ANDREW\DOCUMENTS\PIC PROJECTS\MAIN.ASM 14 :
> Found directive in column 1. (END)

Indent the END statement by 8 spaces and you can get rid of this too.

Also, your program as-is is going to run off into the "undefined" area
of the PIC's program memory once it sets PORTB, and it doesn't set RB6
as an output so you won't ever see RB6 go high. Let's fix the whole program:

        LIST P=18F13K50, R=DEC, F=INHX16
        INCLUDE "P18F13K50.INC"

        ORG 0
        GOTO Main
        ORG 4
InterruptVector:
        RETFIE

Main:
        ; clear port latches
        CLRF LATB

        ; set TRIS
        CLRF TRISB, ACCESS

        ; set RB6
        BSF LATB, 6, ACCESS

        ; spin
        BRA $

        ; end of the code
        END

What I've done is:
  - Add a LIST statement
  - Tidy up the INCLUDE statement
  - Added the reset and interrupt vectors
  - Indented the code correctly
  - Added statements to set up the port control registers (TRIS)
  - Modified the code to write to the port latches instead of the port
itself (this reduces the likelihood of having a read-modify-write issue)
  - Added a "branch to current PC" at the end of the code. This halts
the program at that point and stops the PIC executing code from an area
of FLASH which hasn't been programmed.

The ACCESS statements are there to avoid bank-switches -- some of the
SFRs are located in what's known as the "access bank", an area of memory
which is accessible no matter what the memory page register is set to.

I haven't tested that code, but I can't see any obvious reason why it
wouldn't compile as is.

--
Phil.
spam_OUTpiclistTakeThisOuTspamphilpem.me.uk
http://www.philpem.me.uk/

2010\07\07@144151 by Olin Lathrop

face picon face
Andrew Wood wrote:
> From the examples Im following I cant see whats wrong with the layout
> of my code yet obviously something is.

Examples are no substitute for the real documentation.  At best they show
you one particular way something can be done.  They are no good for
understanding the full range of choices or learning the rules.

As for the warning, there are obvious paths to proceed.  Have you even
looked at the manual?  You got the warning:

 Found directive in column 1. (include)

So clearly there is some issue with directives and column 1.  Gee, maybe it
would be a good idea to re-read the chapter on directives (you did read it
in the first place, right?), paying particular attention to mention of
column 1.  Also, since it appears to complain about a directive in column 1,
maybe it shouldn't be there?  Did you try putting the directive elsewhere,
like column 2?

There are some obscure things in MPASM that are not easy to find and that
make sense to ask about here, but this isn't one of them, at least at the
point you've gotten to so far.  Your question gives the strong impression of
someone being too lazy to read the manual and even too lazy to read the
warning text.  Go do your homework, then maybe you can ask a intelligent
question.


********************************************************************
Embed Inc, Littleton Massachusetts, http://www.embedinc.com/products
(978) 742-9014.  Gold level PIC consultants since 2000.

2010\07\07@145040 by Olin Lathrop

face picon face
Philip Pemberton wrote:
> MPASM thinks you're trying to make an object file. You're doing things
> which suggest you actually want a HEX file that you can program
> straight into the PIC.

Actually I suspect he doesn't even know the difference.  It will take just a
little more up front, but I really wouldn't have him use the evil absolute
mode just for a little instant gratification now.  He'll get stuck in it and
forever after write crappy absolute code.

>          LIST P=18F13K50, R=DEC, F=INHX16
>          INCLUDE "P18F13K50.INC"
>
>          ORG 0
>          GOTO Main
>          ORG 4

On a PIC 18 the default interrupt vector is at 8, not 4.

> The ACCESS statements are there to avoid bank-switches

Which wouldn't happen anyway since the assembler knows that those SFRs live
in the access bank and will automatically generate access bank references to
them.


********************************************************************
Embed Inc, Littleton Massachusetts, http://www.embedinc.com/products
(978) 742-9014.  Gold level PIC consultants since 2000.

2010\07\07@152925 by Dwayne Reid

flavicon
face
At 12:50 PM 7/7/2010, Olin Lathrop wrote:

>Actually I suspect he doesn't even know the difference.  It will take just a
>little more up front, but I really wouldn't have him use the evil absolute
>mode just for a little instant gratification now.  He'll get stuck in it and
>forever after write crappy absolute code.

Olin - would you consider taking Philip's code example and changing
it to re-locatable code?

This would be a VERY useful example - something really short and sweet.

Philip has already done a simple example in absolute mode - take his
example and show what has to be done to make it re-locatable.

Many thanks!

dwayne

--
Dwayne Reid   <.....dwaynerKILLspamspam@spam@planet.eon.net>
Trinity Electronics Systems Ltd    Edmonton, AB, CANADA
(780) 489-3199 voice          (780) 487-6397 fax
http://www.trinity-electronics.com
Custom Electronics Design and Manufacturing

2010\07\07@162145 by Vitaliy

face
flavicon
face
Olin Lathrop wrote:
> There are some obscure things in MPASM that are not easy to find and that
> make sense to ask about here, but this isn't one of them, at least at the
> point you've gotten to so far.  Your question gives the strong impression
> of
> someone being too lazy to read the manual and even too lazy to read the
> warning text.  Go do your homework, then maybe you can ask a intelligent
> question.

Andrew, this is an example of how our resident bully likes to "toughen up"
the newcomers. Best thing you can do is take the good advice and ignore the
insults. Worst thing you can do is take them personally and get into a
fight.

Welcome to the PICList. :-)

Vitaliy

2010\07\07@162328 by Olin Lathrop

face picon face
Dwayne Reid wrote:
> Olin - would you consider taking Philip's code example and changing
> it to re-locatable code?
>
> This would be a VERY useful example - something really short and
> sweet.

I don't have Phillip's example anymore, but here is something sortof
similar.  I don't usually write this stuff outside my environment, which
handles processor selection and including the processor file in a automated
way.  That part would be the same as Phillip's anyway, but instead of
looking it up I left it for someone else to fill in.

;  Set up processor and include the processor-specific include
;  file here.  This is left as a exercise to the reader.
;
        code    0           ;reset vector
        goto    start       ;jump to relocatable code

        code    8           ;interrupt vector
        ;
        ;   Insert interrupt routine here.
        ;
        retfie              ;return from the interrupt

.start   code                ;relocatable code
start                        ;GOTO at reset vector jumps here
        clrf    lata        ;make porta outputs low
        clrf    trisa       ;make parta outputs as much as possible
        clrf    latb        ;same for portb
        clrf    trisb
        ...


********************************************************************
Embed Inc, Littleton Massachusetts, http://www.embedinc.com/products
(978) 742-9014.  Gold level PIC consultants since 2000.

2010\07\07@163635 by Olin Lathrop

face picon face
Vitaliy wrote:
> Andrew, this is an example of how our resident bully likes to
> "toughen up" the newcomers. Best thing you can do is take the good
> advice and ignore the insults. Worst thing you can do is take them
> personally and get into a fight.

So you think not reading the manual and asking a dumb question largely
answered by the very warning message you are asking about is OK?  As I think
you also well know, this has nothing to do with being a newcomer, but about
getting people to use their own brain.  You would get the same response if
you asked a similar question that showed you didn't read the manual or the
error message.


********************************************************************
Embed Inc, Littleton Massachusetts, http://www.embedinc.com/products
(978) 742-9014.  Gold level PIC consultants since 2000.

2010\07\07@171028 by jim

flavicon
face
Olin,

I'm sorry, but I can't keep quiet on this one.

Yes, I think it's okay to ask a dumb question.  At least what you perceive
as dumb.
What may be dumb to you isn't dumb to someone else.

Not everyone has your experience or superior intelligence.  Therefore, they
have to ask
questions to know which way to go from where they currently are.   I agree
that they should
read the datasheet, apnotes, and whatever other resource material is
available, but that
will still leave questions.  As a matter of fact, it may generate more
questions than answers.
And the fact that they did or didn't consult resource material in no way
justifies the way
you belittle people that ask questions. After all, who died and made you
GOD.  As far as I'm
concerned, you're way out of line.

And. if they are such dumb questions, why don't you just keep your mouth
shut, ignore them,
and let someone else answer them.  That way the less experienced will gain
the answer
they seek and they will grow, another member of the PICLIST gets to answer a
question that
he or she has experience with, and you won't have been inconvenienced at
trying to answer
a dumb question, or lacking the answer, telling everyone that it was a dumb
question.  
In other words, everybody wins.  It probably takes you as long to tell the
world you have
just intercepted another dumb question as it would have taken to answer the
actual question.

Olin, stop taking yourself so seriously and try to understand that at some
point, everyone is/was
a beginner.  Think back to when you were a beginner.  Didn't you have
questions about something
that maybe an expert could help you answer in just a few seconds?  I know I
have.  And when I got
the answer to the question, I looked up further clarification and education.

My philosophy regarding this list is if I know the answer to a question, or
where to find the answer,
I'll answer it.  Otherwise, I don't.  Unless once in a while I interject
what I think is humor.
But those time are few and far between.

There is a lot of collective experience on this list.  Probably in the
hundreds if not thousands
of man years.  So if you didn't answer a dumb question, there are still
hundreds of man years
experience that is fully capable of answering the question, dumb or not.

So my suggestion is, and this is only a suggestion because I don't have any
moderator authority,
if a question is posted that you believe is beneath your dignity to answer,
leave it alone, let someone else answer it, and use that valuable time to
create your next great invention.

Regards,

Jim





{Original Message removed}

2010\07\07@172537 by Bob Blick

face
flavicon
face
STOP bickering. This is an official admin warning.

Olin, Vitaliy, Jim - you are all out of line, in increasing order of
offensiveness. Do not post your crap to the piclist.

Vitaliy and Jim - address for complaints is piclist-ownerspamKILLspammit.edu and
you should both know this already so I am being generous in giving you
warnings.

Olin, you know not to call someone "lazy" and I should not be so
generous to give you a warning.

But if any of you step out of line this way again I will shut you down,
you have my guarantee.

-Bob



--
http://www.fastmail.fm - mmm... Fastmail...

2010\07\07@174752 by Olin Lathrop

face picon face
jim wrote:
> Yes, I think it's okay to ask a dumb question.  At least what you
> perceive as dumb.
> What may be dumb to you isn't dumb to someone else.

Even when a message mumbles something about a directive being in column 1
and you don't even look to see if you maybe have a directive in column 1 and
whether or not that is bad?  Note that that is a very different question
from "It says something about a directive in column 1, but I'm not clear
what a directive is and I can't find any mention what column they should be
in".  That would have been a rather good question actually.

> Therefore, they have to ask
> questions to know which way to go from where they currently are.

Not when the error message gives them a clear path to follow.  If you don't
undestand that, ask about that.

> And the fact that they did or didn't consult resource material in no
> way justifies the way
> you belittle people that ask questions.

That's your opinion.  There's plenty to be confused about with PICs, and
plenty of good questions to ask, and plenty I've tried to be quite helpful
with, but there are also dumb questions.

> And. if they are such dumb questions, why don't you just keep your
> mouth shut, ignore them, and let someone else answer them.

This has been explained many times before.

> That way the less experienced will
> gain the answer they seek and they will grow,

No, they will be taught that being lazy works.  I don't want to let people
get away with that.

> It probably takes you as long to
> tell the world you have
> just intercepted another dumb question as it would have taken to
> answer the actual question.

Perhaps, but the outcome is of course rather different.

> Think back to when you were a beginner.  Didn't you have
> questions about something that maybe an expert could help
> you answer in just a few seconds?

Of course, but I didn't ask lightly.  I tried to do my homework before
asking.  That's part of the process of learning.

> So if you didn't answer a dumb question, there are
> still hundreds of man years
> experience that is fully capable of answering the question, dumb or
> not.

That's exactly the problem.  There always seems to be someone more eager to
look smart than to look at the bigger picture and not let people get away
with using us as a substitute for doing their homework.


********************************************************************
Embed Inc, Littleton Massachusetts, http://www.embedinc.com/products
(978) 742-9014.  Gold level PIC consultants since 2000.

2010\07\07@183853 by Vitaliy

face
flavicon
face
Bob Blick wrote:
> STOP bickering. This is an official admin warning.
>
> Olin, Vitaliy, Jim - you are all out of line, in increasing order of
> offensiveness. Do not post your crap to the piclist.
>
> Vitaliy and Jim - address for complaints is .....piclist-ownerKILLspamspam.....mit.edu and
> you should both know this already so I am being generous in giving you
> warnings.
>
> Olin, you know not to call someone "lazy" and I should not be so
> generous to give you a warning.
>
> But if any of you step out of line this way again I will shut you down,
> you have my guarantee.

Admins -- I asked repeatedly not to be moderated by Bob Blick, who stated
that he considers me an enemy of the United States and his personal enemy,
and therefore cannot be considered an objective arbiter. Is it really too
much to ask to have Bob to refer me to another admin for moderation?

My comment was meant to diffuse the situation. Olin is a seasoned PICLister
with a thick skin, and I'm sure in the interest of retaining his freedom of
speech he is willing to take it, as well as dish it out.

Vitaliy

2010\07\08@005802 by RussellMc

face picon face
> Bob Blick wrote:
> > STOP bickering. This is an official admin warning.
> >
> > Olin, Vitaliy, Jim - you are all out of line ...

> > Vitaliy and Jim - address for complaints is EraseMEpiclist-ownerspam_OUTspamTakeThisOuTmit.edu and
> > you should both know this already ...

> > Olin, you know ...

Vitaliy asked:

> Admins ... Is it really too
> much to ask to ...  refer me to another admin for moderation?

> My comment was meant to ...

OK.
I'll answer that as "another admin".
Please see also my longer comments in [OT].

Vitaliy:

Please read what Bob asked and do it.
You were not singled out individually but as part of a group action.
Apart, perhaps, from the use of one perhaps-unwise word the requests
seem entirely fair and balanced and none were directed solely to you.
All 3 people have significant merit in what they said. The merits of
the arguments are not relevant to the request.
The admin request was re following list rules which are designed to
"keep the peace" and not to noise up the [PIC] topic (as this is
doing).

Please read list guidelines re what is appropriate for the list.
*If* this sort of material is appropriate at all it belongs in [OT].
And then politely and in a reasoned manner.
(See the example that someone has posted in [OT] (changing the tag of
their own volition ! :-)  - arguably still not quite within list
guidelines but so reasonable and non confrontational as to serve as an
excellent example of how such things MIGHT be discussed).

The same, of course, also applies to what Olin and Jim wrote.

Additionally:
                   Please do not respond to admins onlist in the
manner that you subsequently did. The merits and/or truthfulness or
not of anything you say is irrelevant. Admins are most effective when
they never need to do anything and can be seen as a lurking power -
benevolent or malevolent as you see fit to perceive them. By getting
in the face of an individual admin onlist you pose an unnecessary
personally based  challenge to the admins effectiveness overall.
Failure of admins to respond appropriately to such a challenge or to
show solidarity makes admins look weak and powerless and reduces their
effectiveness*. Responding appropriately would not be appreciated by
you. Please throw down such gauntlets offlist. By all means send
material to piclist-ownerspamspam_OUTmit.edu as desired - repeatedly if deemed
necessary.


               Russell


* (Personal feelings may well be present but are not relevant - admins
as a whole have to retain usefulness. If this cannot be achieved by
being treated politely then it must be achieved by
invariably-perceived-as-draconian use of power. Politeness is much
preferred.)

More... (looser matching)
- Last day of these posts
- In 2010 , 2011 only
- Today
- New search...