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

Exact match. Not showing close matches.
PICList Thread
'[PIC]: Question'
2001\06\02@215409 by basam

flavicon
face
Hi All,
I have a question:
1.Why doesn't this work?

       list p=16f876
       include "P16f876.inc"
;...............................
tmp equ  0x21
;...............................
       org 0x00
       goto start
;...............................
start
        movlw 0x1
        movwf tmp
        nop
  if tmp  = = 1
        call sub1
  else
        call sub2
  endif
        nop
;...............................
sub1
        nop
        return
;..............................
sub2
        nop
        return
        end

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2001\06\02@215827 by Douglas Wood

picon face
Because the "if" directive is only available at compile time and you're
trying to use at run-time.

Douglas Wood
Software Engineer
spam_OUTdbwoodTakeThisOuTspamkc.rr.com

Home of the EPICIS Development System for the PIC and SX
http://epicis.piclist.com

{Original Message removed}

2001\06\02@222141 by Mark Newland

flavicon
face
Sounds like your confused between assembler "opcodes" and assembler
"directives".  You write your PROGRAM with opcodes.  You tell the
assember what to do with directives.  What you are telling the compiler
is >IF< tmp was equal to "1" then use the line "call sub1" in your
program.  However, you set tmp to 0x21 so the line "call sub2" will be in
your program instead.  This is about what the program will look like
AFTER if is compiled:

      list p=16f876
       include "P16f876.inc"
;...............................
tmp equ  0x21
;...............................
       org 0x00
       goto start
;...............................
start
        movlw 0x1
        movwf tmp
        nop

***      call sub2     ***

        nop
;...............................
sub1
        nop
        return
;..............................
sub2
        nop
        return
        end


What you want to do is something like this
   movf    tmp,f                ;Copy tmp into itself to set the ZERO
flag if tmp = 0
   btfss    STATUS,Z       ;Look at the ZERO flag to see if it is set
   goto    Jmp1                ;You don't want a call statement here
unless you ALWAYS want
                                       ;the next line executed after you
return. This line executes if not ZERO
   goto    Jmp2                ;This line executes if ZERO

Jmp1
   call    Sub1                    ;Do your subroutine
   goto    Start                    ;Loop back again after you return
Jmp2
   call    Sub2                    ;Do your subroutine
   goto    Start                    ;Loop back again after you return
basam wrote:

{Quote hidden}

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2001\06\02@223219 by Bob Ammerman

picon face
----- Original Message -----
From: "basam" <.....basamKILLspamspam@spam@EMO.SEAS.SK>
To: <PICLISTspamKILLspamMITVMA.MIT.EDU>
Sent: Saturday, June 02, 2001 9:52 PM
Subject: [PIC]: Question


> Hi All,
> I have a question:
> 1.Why doesn't this work?

Because you are confusing assembly time operations with runtime operations.

IF is an instruction to the assembler, very similar to #if in "C" that
controls what code is actually ASSEMBLED.

I have taken the liberty to modify your code to actually work.

{Quote hidden}

       movf    tmp,W    ; Get saved value of tmp
       xorlw   1             ; compare it to 1
       skpz                   ; skip if they are equal
       goto  unequal
       call    sub1
       goto  merge
unequal:
       call     sub2
merge:

{Quote hidden}

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2001\06\02@230657 by basam
flavicon
face
            Thank You

( It's a long way to the Valhalla  :-) )

                   Milan

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2001\06\03@090728 by Olin Lathrop

face picon face
> 1.Why doesn't this work?

I'm sure it does work exactly as you wrote it.  If that isn't what you
intended, then I can't say because you never said what you wanted it to do.

<soapbox>
*****  COMMENT YOUR CODE, *&#$&@ !  *****
</soapbox>

{Quote hidden}

Note that this is always false since TMP = 21h.

>          call sub1
>    else
>          call sub2
>    endif
>          nop

Note that this will fall thru to SUB1, which will do a RETURN and cause a
stack underflow.

{Quote hidden}

********************************************************************
Olin Lathrop, embedded systems consultant in Littleton Massachusetts
(978) 742-9014, .....olinKILLspamspam.....embedinc.com, http://www.embedinc.com

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2001\06\03@185147 by basam

flavicon
face
Olin Lathrop wrote:

{Quote hidden}

I have no real problem, I only wanted to test IF..ELSE..ENDIF condition, but I
think I mixed everything together.(It looks like I have a little big problems
with assembling :-) ).
I need to initialise tmp, You say ,that if I will do this with EQU, then the
value will be 21h, but I thought that 21h is its adress.
I need to give some adress where to put  tmp, not value.
I am going to study MPASM-HELP.
                                                           Thanx to Everybody

Milan

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2001\06\03@200710 by Heinz Czychun

flavicon
face
Hi Milan,

       The tutorial here might be of some value.

       http://pc-tek.hypermart.net/pic.html

Heinz


At 12:49 AM +0200 6/4/01, basam wrote:
{Quote hidden}

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2001\06\04@030937 by Mark Newland

flavicon
face
You really REALLY  R E A L L Y need to understand the difference between "opcodes"
and "directives".  One is used for the "program", the other is NOT!!  If you want to
learn programming, then forget the MPASM-HELP (at first) and memorize the small list
of what opcodes are available for the processor you are useing.  You don't have to
memorize exactly what they do but learn whats available.  After that then it should
be ALOT easier to learn and use the assembly "directives" such as EQU to support the
programming.

On the same note, tutorials are really good too.

To answer your other question.  EQU is a "directive", not an "opcode".  When you put
the line of
    tmp EQU 0x21
into your code, that was a "directive" to the assembler.  It is NOT a line that will
be put into your compiled program.  If within my "program" I want to put the value
of the W register into memory register 0x21, I can do it in either of the following
two ways:
    movwf    0x21
    movwf    tmp
This is because tmp = 0x21.  What the assembler (MPASM) will do is make a
substitution in your "program".  Everywhere that it see the word 'tmp' it will put
'0x21' instead.

The IF..ELSE..ENDIF "directives" are another set of commands that are sent to the
assembler but are NOT part of the "program".  Learn your opcodes first.

Heinz Czychun wrote:

{Quote hidden}

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservspamspam_OUTmitvma.mit.edu with SET PICList DIGEST in the body


2001\06\04@073532 by Olin Lathrop

face picon face
> I have no real problem, I only wanted to test IF..ELSE..ENDIF condition,
but I
> think I mixed everything together.(It looks like I have a little big
problems
> with assembling :-) ).
> I need to initialise tmp, You say ,that if I will do this with EQU, then
the
> value will be 21h, but I thought that 21h is its adress.
> I need to give some adress where to put  tmp, not value.

You are confusing assembler variables and constants, and the runtime value
located at addresses that are referenced by those assemlber variables and
constants.  First, assembler symbols never stand for the contents of a RAM
location, because that can't be determined at assembly time.  These symbols
can stand for arbitrary number or memory addresses (which are also just
numbers).  When you say:

TMP   EQU   h'21'

you assign the value 21h to the assembler symbol TMP.  Nothing more.  TMP is
NOT a memory location, and TMP absolutely does not refer to the contents of
any memory location.  However TMP, like any other symbol, can be used as the
address of a memory location.  For example:

     MOVWF TMP, W    ;fetch the value at TMP

But the assembler only knows that TMP = 21h.  It doesn't know that you think
of that as representing the address of a memory location.  You could just as
well use it as a normal numeric constant:

     MOVLW TMP       ;init the loop counter
     MOVWF LOOPCNT

> I am going to study MPASM-HELP.

A very good idea.  However, you might start with a book or something that
introduces assembly language programming in general.  The Microchip
documentation pretty much assumes you already know how assemblers work and
teaches you the specifics of MPASM.  You are having problems with general
concepts that may not be well addressed in the MPASM manual.


********************************************************************
Olin Lathrop, embedded systems consultant in Littleton Massachusetts
(978) 742-9014, @spam@olinKILLspamspamembedinc.com, http://www.embedinc.com

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email KILLspamlistservKILLspamspammitvma.mit.edu with SET PICList DIGEST in the body


2001\06\08@025757 by Kashif Ali

flavicon
face
Hi all,

I need more then 100 reg but 16f874 has only 96 reg in its first bank and I
don't know how to utilize next bank reg.

Please give an example of utilizing both bank 0 & 1 in one routine.

Kashif ali

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2001\06\08@083212 by Byron A Jeff

face picon face
On Fri, Jun 08, 2001 at 11:57:56AM -0700, Kashif Ali wrote:
> Hi all,
>
> I need more then 100 reg but 16f874 has only 96 reg in its first bank and I
> don't know how to utilize next bank reg.
>
> Please give an example of utilizing both bank 0 & 1 in one routine.
>
> Kashif ali

Kashif,

You need a copy of the datasheet. It describes exactly how to change banks.
It's section 2.2 of the 16F87X datasheet. Page 12. More detail can be found
in the 16F family midrange manual in section 6.3.3 on page 6-8. Also
in both manuals take a read of the indirect addressing feature using FSR
and INDF. They can be utilized for the task also.

I know this may seem unfair, but I'm not going to answer your question, and
I hope that no one else will answer it either. This is information is that
is clearly documented. Frankly you would have saved a ton of time if you had
taken the time to look it up yourself.

You can't program microcontrollers without the documentation. You also must
read it. Get a copy of the documents above from the Microchip website, and
take a read of the sections. Then try it. Then come back if necessary and post
the relevant code and the results. In this way you will get a clearer
understanding of the process instead of simply asking and getting back a
code snippet.

I will give you one hint: bank switching for general purpose registers is
exactly the same process as setting the TRIS registers for the I/O ports for
ports D, and E (which are on an 16F874). Did you use ports D or E? If so then
how did you change the TRIS registers? It's the same process for general
purpose.

Good luck, and let us know how it comes out....

BAJ

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2001\06\08@095943 by Kashif Ali

flavicon
face
Thanks for your reply,

But still I have question :

Actually I need 64 reg for working and 64 reg for backup purpose.
Now the problem is how can I simply backup working reg (bank0) into backup
registers (bank 1).

Please give me a short example for moving working reginster into backup registers.

Kashif ali

Byron A Jeff wrote:

{Quote hidden}

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2001\06\08@121902 by Quentin

flavicon
face
If you use FSR you don't have to set any bits for between bank0 and
bank1 (it is explained in the data sheet).
So, to copy a register from 0x021 in bank0 to 0x0A1 in bank1:
MOVLW   0X021   ;value of register to copy
MOVWF   FSR     ;point to that register
MOVF    INCF,W  ;move and
MOVWF   TEMP1   ;save contents in a temporary register
MOVLW   0X0A1   ;value of register to save in
MOVWF   FSR     ;point to that register
MOVF    TEMP1,W ;move contents and
MOVWF   INDF    ;save it in that register

Loop that for all your other registers.
Read the data sheets on using the FSR, it is a very handy function to
use.
Quentin

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2001\06\08@122727 by Quentin

flavicon
face
Typo in my last email:

> MOVF    INCF,W  ;move and
MOVF    INDF,W

Quentin

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2001\06\08@140649 by Olin Lathrop

face picon face
> Actually I need 64 reg for working and 64 reg for backup purpose.
> Now the problem is how can I simply backup working reg (bank0) into backup
> registers (bank 1).
>
> Please give me a short example for moving working reginster into backup
registers.

I agree with Byron.  Your question leaves the impression that you don't want
to bother reading the manual and want someone just to solve the problem for
you.  I'm not going to do that.  Come back after you've done the basic
homework and have specific questions.  HINT: you can index thru memory
buffers by using indirect addressing.  This is done by use of the INDF and
FSR registers.


********************************************************************
Olin Lathrop, embedded systems consultant in Littleton Massachusetts
(978) 742-9014, RemoveMEolinTakeThisOuTspamembedinc.com, http://www.embedinc.com

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2001\06\12@061350 by Kashif Ali

flavicon
face
Hi all,

I am working on 16f874 newly and facing problem of  (MCLR) reset.
Same hardware I am using for 16f84a it worked perfactly but with 16f874 working
randumly.

Kashif Ali

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2001\06\12@063705 by Vasile Surducan

flavicon
face
Ali,
The reset circuit is shown at page138 from DS30292A  ( datasheet)
R=10k to vcc, 1n4148 cathode to vcc, from common point one 47...100nF
capacitor to ground, common point to mclr through 100 ohm resistor.
Check also if BODEN is enable and power supply is clean.
Vasile

On Tue, 12 Jun 2001, Kashif Ali wrote:

{Quote hidden}

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


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