Searching \ for 'Pic programming problem Need Help!!' 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/devprogs.htm?key=programming
Search entire site for: 'Pic programming problem Need Help!!'.

Truncated match.
PICList Thread
'Pic programming problem Need Help!!'
1998\07\13@211227 by Brian Gracia

picon face
Hello,

I usually lurk, and send info to the list when I know something about the
subject, which is rare.

I am having trouble trying to learn pic code.  It could be the fact that I
have not programmed a pic yet.  I am still getting my programmer built.
What I am doing is reading all I can and trying to follow along with the
examples.

Where I am lacking is in the fact that while I can program in several
computer languages, pic code is just not the same!!!  Can someone help me
by translating some simple program building blocks like IF..Then, Do
While..Loop, For I.., etc into pic code.  I need to see these in order to
get a basic footing, and then I can begin to understand.  Doing this is
like showing someone how to read a tape measure.  Pretty soon, with a set
of plans (psudo code), and the basic building blocks, they can build a
house.  Well almost, but you get my drift.

Brian

1998\07\13@233349 by Gary Bach

flavicon
face
Brian, check out my Web site for a PicBasic programmer. It uses PIC Basic If
then, For Next etc. Why not write your programs in basic?
I also have EPIC Programmers listed if you have any problems with your
Programmer (The one you are building). This is a brand new web site, so
don't expect too much. I have also added many links to other PIC sites. Good
Luck, Gary. Contact me direct if you need more help. I don't want to clog up
the use group. spam_OUTgbachTakeThisOuTspamsiscom.net
http://www.siscom.net/~gbach



> {Original Message removed}

1998\07\14@031328 by g.daniel.invent.design

flavicon
face
Hi Brian,
You're very lucky with PIC, Microchip provide what would normally be an
expensive development tool free of charge over the internet and on their
CDroms.

This is "MPLAB", load it on to a windows OS PC and then open one of the
demonstration projects.  Use the online help to check out instruction
set, debugging features etc and then simulate running on screen with the
single step icon.  By opening up a "watch" window, and [ins]erting
program variables, special function registers, you can get a good feel
for what makes a PIC tic.

Decision making processes ie if...then... must be replaced with btfss,
btfsc, decfsz, incfsz.   The PIC will only skip single instructions as
result of these decisions, it is your responsibility to insert a goto,
call, or other opcode to achieve your "then" action.   Don't think that
because the instructions are very simple that you cannot achieve very
complex tasks.

typically, a for next type loop is done like this:

       movlw   d'100'                  ;  d'100', d '__' for decimal.
       movwf   any_counter_register
arbitary_loop_name              ;<---------
                                       ;  |
       call    repeated_action_sub     ;  | <-unconditional call repeated 100 t
imes
       btsfc   any_counter_register,0  ;  | skip next instr IF bit 0 of counter
clear
       call    adjust_on_odd_counter   ;  | any_counter_register must be odd, d
o
sub.
                                       ;  |
       decfsz  any_counter_register    ;  |
       goto    arbitary_loop_name      ;--

* You can nest the above structures, especially to get more than 256
counts.

* Beware, starting a decfsz loop with 0 in the file register will cause
a loop count of   256 as decfsz tests for zero condition AFTER the
decrement.

* when you are ready, check out "table reads", these can perform the
equivalent of data/string, on condition.. goto.. .. .. .. ..
structures.  Destination calculated jumps can have retlw instructions
with table values, GOTO.. instructions etc.

These are some of the PIC basics, also remember that 0=output,1=input
when setting port directions, this is different to many other MICROs
regards,
Graham Daniel.

Brian Gracia wrote:
{Quote hidden}

1998\07\14@071542 by hatfield

flavicon
face
Brian Gracia wrote:
>
> Hello,
>
> I usually lurk, and send info to the list when I know something about the
> subject, which is rare.
>
> I am having trouble trying to learn pic code.  It could be the fact that I
> have not programmed a pic yet.  I am still getting my programmer built.
> What I am doing is reading all I can and trying to follow along with the
> examples.
>
> Where I am lacking is in the fact that while I can program in several
> computer languages, pic code is just not the same!!!  Can someone help me
> by translating some simple program building blocks like IF..Then, Do
> While..Loop, For I.., etc into pic code.  I need to see these in order to
> get a basic footing, and then I can begin to understand.  Doing this is
> like showing someone how to read a tape measure.  Pretty soon, with a set
> of plans (psudo code), and the basic building blocks, they can build a
> house.  Well almost, but you get my drift.

There's no substitute for a good book like "Pic N Start" or
Myke Predko's "Programming and Customizing the Pic....".  They
teach you one or two instructions at a time, give examples
and often include an actual program that you can run on hardware
or a software emulator.

Fred.
.....fred.hatfieldKILLspamspam@spam@sstar.com
New Orleans

1998\07\14@095755 by lilel

flavicon
face
Brian Wrote:

> Hello,
>
> I usually lurk, and send info to the list when I know something
> about the subject, which is rare.
>
> I am having trouble trying to learn pic code.  It could be the fact
> that I have not programmed a pic yet.  I am still getting my
> programmer built. What I am doing is reading all I can and trying to
> follow along with the examples.


Quick, download a free copy of MPlab from Microchip.  You don't have
to program parts to see the code run, it will run fine as a
"simulator".    When you have trouble getting it running, call their
800 number.  They are very helpful.  Don't bother making a programmer
for a while, you are not even close to programming a part if you are
moving at the same speed I was.


I often use comments to write "pseudocode" next to my assembler.
Some people even consider this good technique, thus:

SOME_LOOP     ; WHILE  X > 0

          ; .... SOME CODE .....


           DECFSZ  X, F              ; X=X-1
           GOTO SOME_LOOP  ; SKIP IF X=0
                              ; END WHILE


-- Lawrence Lile

    "An Engineer is simply a machine for
     turning coffee into assembler code."

Download AutoCad blocks for electrical drafting at:
http://home1.gte.net/llile/index.htm

1998\07\14@121805 by Peter L. Peres

picon face
On Mon, 13 Jul 1998, Brian Gracia wrote:
-snip-
>
> Where I am lacking is in the fact that while I can program in several
> computer languages, pic code is just not the same!!!  Can someone help me
> by translating some simple program building blocks like IF..Then, Do
> While..Loop, For I.., etc into pic code.  I need to see these in order to
> get a basic footing, and then I can begin to understand.  Doing this is
> like showing someone how to read a tape measure.  Pretty soon, with a set
> of plans (psudo code), and the basic building blocks, they can build a
> house.  Well almost, but you get my drift.

Since you already know a few other languages, analyze how you picked
the(m) up. Do you learn best by yourself, in class, from an organized
course, or are you the kind that rips things apart to learn what's inside
? Then, pick a learning method that suits you best.

A book is a good start, if you are that kind of guy. If you learn by
yourself, simply learn the instruction set by heart and start doing some
simple applications (peek at the application notes from Microchip in the
process). If you like to program using templates, get a book. The author
usually uses his own programming style throughout, and that is as good
a 'template' as any.

Translating structured programming constructs into PIC assembly is not so
direct as you might think it is.

For example for an IF...THEN...ELSE you would have to work out an
expression for the IF part that sets a bit or a register and write code
like this:

       ; IF
       ; code for if-expression here

       ; final comparison: ZF of the PSW is not set IF true (C convention)
       btfsc   PSW, ZF
       goto    if_false

       ; THEN
       ; code for true case here

       goto    if_end

       ; ELSE
if_false:
       ; code for false case here

if_end:
       ; FI

Notice that there is no boilerplate code, only the structure of the code
is essential. You have to find a solution for every case as you go, there
is no real constraint in a symmetrical-register architecture machine as
the PIC is.

DO..WHILE etc translate much in the same way. You keep the general
structure of the construct, but you implement it with the mnemonics that
get you to your goal. Putting labels with structured construct part names
in them into the source will help you understand the code later.

Notice that remarkably few advanced assembly programmers bother about
structured code construction on PICs ;) Hack mode is much more natural <G>

hope this helps,

       Peter

1998\07\15@133516 by philb

flavicon
face
Brian,

You're right, the hardest part is getting started.  You might try some
of the sample programs off the Parallax site.  In addition, Dantronics
has put Scott Edwards Electronics PIC Source Book online at
http://dontronics.com/see.html.

Some of his implementation is more difficult than it needs to be IMO,
but it's great to see someone else's code to get started.  It was a HUGE
help getting started.



Brian Gracia wrote:
>
<snip>
> Where I am lacking is in the fact that while I can program in several
> computer languages, pic code is just not the same!!!  Can someone help me
> by translating some simple program building blocks like IF..Then, Do
> While..Loop, For I.., etc into pic code.  I need to see these in order to
> get a basic footing, and then I can begin to understand....

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