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

Exact match. Not showing close matches.
PICList Thread
'[PIC]:code problem'
2000\08\12@145019 by Sandy Phelps

flavicon
face
Hi,
This my second program on a PIC. I'm using a 16F877 and having
some trouble getting the right value into w.

Tthis starts with a value already in w such as 'a'.
If w = 'a', I want to replace it with 'x'
If w != 'a' leave as is.
The trouble is the last instruction, movlw  _w puts 0x21 into w.
I set a watch on w and _w and all looks good until the last instruction.
This is probably something elementary but it's got me stuck.
Appreciatte any help.

    movwf     _w            ;save w
    xorlw     0x61          ;compare w to 'a'
    btfss     status,2          goto      send
    movlw    0x78        ; x      movwf    _w          ;restore w with orig or new char

send
    movlw     _w

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

2000\08\12@151315 by Dan Michaels

flavicon
face
At 01:38 PM 8/12/00 -0700, you wrote:
{Quote hidden}

As written here, "movlw" command means "move literal to w",
where literal = an 8-bit constant. 0x21 is probably the
address of your variable _w.

BTW, just a hint - it usually makes code more readable if
you write

"btfss status,Z"  rather than  "btfss status,2"

Also, some people write

"movf _w,0"  and  "movf _w,1"  whereas

"movf _w,w"  and  "movf _w,f"  are much more readable.

best regards,
- danM

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

2000\08\12@153438 by Ing. Jose Eleno Curiel G.

flavicon
face
The last instruction could be:
movfw _W
in order to get the CONTENTS of _W register into W register.
instead of
movlw _W

-----Mensaje original-----
De: Dan Michaels <spam_OUToricomTakeThisOuTspamLYNX.SNI.NET>
Para: .....PICLISTKILLspamspam@spam@MITVMA.MIT.EDU <PICLISTspamKILLspamMITVMA.MIT.EDU>
Fecha: Sabado 12 de Agosto de 2000 02:16 PM
Asunto: Re: [PIC]:code problem


{Quote hidden}

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

2000\08\12@155755 by Dan Michaels

flavicon
face
At 01:38 PM 8/12/00 -0700, you wrote:
{Quote hidden}

BTW, another hint related to choosing names for variables,
and trying to debug code that is not working properly....

Using _w for a variable name can cause some real problems,
because w is the most used register in a PIC. Therefore, in
a program with 100 lines, you might end up with _w or w in
almost every line. If you accidentally type _w instead of
w, or vice versa, somewhere in the program, it might take
months to figure out what the problem is.

Better to use something like temp_w or sav_w - variable names
that are more distinctive.

best regards,
- danM

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

2000\08\12@161555 by Sandy Phelps

flavicon
face
Thanks to Jose for the fix. Using movfw makes it work, however I don't see
that in the list
of instructions. I'm not picky, I'll use it.
Thanks also to Dan Michaels for his suggestions. It is very helpful to have
someone
willing to help a neophyte.
Sandy
{Original Message removed}

2000\08\12@204310 by Bob Ammerman

picon face
"movfw  _w" is not really an instruction.

it is a synonym for "movf _w,w".

(boy is that confusing!)

Bob Ammerman
RAm Systems
(contract development of high performance, high function, low-level
sofftware)

{Original Message removed}

2000\08\12@233833 by Nikolai Golovchenko

flavicon
face
Sandy,

It can be done also like this:

       xorlw 'a'       ;compare to 'a', w' = w ^ 'a'
       btfss STATUS, Z
        movlw 'x'^'a'  ;if not equal, w = 'x' ^ 'a'
       xorlw 'a'       ;if w was equal to 'a', restore it
                       ;if   w  was  unequal  to 'a',
                       ; w = 'x' ^ 'a' ^ 'a'= 'x'

Cheers,

Nikolai

---- Original Message ----
From: Sandy Phelps
Sent: Saturday, August 12, 2000 23:38:33
 To: .....PICLISTKILLspamspam.....MITVMA.MIT.EDU
Subj: [PIC]:code problem

{Quote hidden}

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

2000\08\13@152638 by Oliver Broad

flavicon
face
movfw is one of the built in 'macro' instructions, that is an instruction
that can also be written in a more general form, in this case movf  <r>,w.
The seemingly useless movf <r>,f (move f to f) can be used to test a
register for zero without affecting w, though I believe it is rarely used.

There is another usefull set, the skip instructions, these expand out to bit
test instructions acting on the status register, for example skpnz skip next
instruction if zero flag not set. There are set-bit and clear-bit
instructions.

A handy trick to remember is that an exclusive-or is reversable so you can
write:

xorlw     0x61          ;compare w to 'a'
btfsc     status,Z
movlw    0x61 ^ 0x78; that's 0x19 but writing the expression is clearer
xorlw    0x61    ;put w back how it was

You may find yourself able to eliminate many gotos that way. This can make
code smaller and  avoids the need for a lot of labels.

It also makes the code isochronous, it always takes the same time to execute
regardless of results.

{Original Message removed}

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