Searching \ for '0 in file detection ?' 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/index.htm?key=file+detection
Search entire site for: '0 in file detection ?'.

Truncated match.
PICList Thread
'0 in file detection ?'
1997\04\08@210111 by Philip Martin

flavicon
picon face
Ahhh,

If anyone reads my last post, thanks but I solved the problem of Simu
input to pins inn MPLAB-SIM.

Next problem though has got me.

       decfsz  count_ts        ; decrease counter if not zero
;
       addlw   .0              ; put 0 in w reg
       xorlw   count_ts        ; is counter at 0
       btfsc   status,Z
       bcf     flag,0          ; yes so set flag,0 to 0
;

As you van see, I'm decreasing a counter on a program loop. When the
counter reaches 0, I want to set the flag,0 bit to 0. Thing is the xorlw
or the btfsc is not picking up the 0 in count_ts.

Earlier in the program a similar slice of code works to detect a value
greater than 0 in the file count_ts. So the problem has got to be xoring
the two 0's and then checking the Z status, hasn't it ?

If so, how do I check for the 0 state in the file.


TIA.
--
Philip Martin   ----------------------------------------------------------------
Royal Quays             If at first you don't succeed, try again. Then quit:
North Shields.          no use being a damn fool about it !
                                                       W.C. Fields
email spam_OUTphilipTakeThisOuTspamphilmart.demon.co.uk

1997\04\08@224119 by Michael S. Hagberg

flavicon
face
>Next problem though has got me.
>
>        decfsz  count_ts        ; decrease counter if not zero
>;
>        addlw   .0              ; put 0 in w reg

This does NOT put 0 in w reg, use movlw .0 to do that

>        xorlw   count_ts        ; is counter at 0
>        btfsc   status,Z
>        bcf     flag,0          ; yes so set flag,0 to 0
>;
>
>As you van see, I'm decreasing a counter on a program loop. When the
>counter reaches 0, I want to set the flag,0 bit to 0. Thing is the xorlw
>or the btfsc is not picking up the 0 in count_ts.
>

if the flag is not used in an interrupt routine you could do the following

       bcf     flag,0
       decfsz  count_ts,f
       bsf     flag,1          ; set bit if counter not zero

michael

1997\04\09@025809 by Andrew Warren

face
flavicon
face
Philip Martin <.....PICLISTKILLspamspam@spam@MITVMA.MIT.EDU> wrote:

>         decfsz  count_ts        ; decrease counter if not zero
> ;
>         addlw   .0              ; put 0 in w reg
>         xorlw   count_ts        ; is counter at 0
>         btfsc   status,Z
>         bcf     flag,0          ; yes so set flag,0 to 0
>
> As you van see, I'm decreasing a counter on a program loop. When the
> counter reaches 0, I want to set the flag,0 bit to 0. Thing is the
> xorlw or the btfsc is not picking up the 0 in count_ts.
>
> Earlier in the program a similar slice of code works to detect a
> value greater than 0 in the file count_ts. So the problem has got to
> be xoring the two 0's and then checking the Z status, hasn't it ?

No, Philip.

Your code has a couple of problems.

First, if your "decrease counter if not zero" comment is accurately
describing what you want to do, you're going about it all wrong...
"DECFSZ" will ALWAYS decrement the counter; if the result is zero,
the NEXT instruction will be skipped.

Second, "ADDLW 0" does NOT load W with 0; it simply ADDS 0 to
whatever value's in W already.  This will, of course, leave W
unchanged.

If I were you, I'd do it like this:

       TSTF    COUNT_TS        ;COUNT_TS ALREADY AT 0?
       SKPZ                    ;IF SO, SKIP AHEAD.

       DECFSZ  COUNT_TS        ;OTHERWISE, DECREMENT COUNT_TS.
                               ;IF COUNT_TS = 0 AFTER BEING
                               ;DECREMENTED, SKIP AHEAD.

       GOTO    NOCLEAR         ;OTHERWISE (OR IF COUNT_TS WAS
                               ;ALREADY AT 0 WHEN WE TESTED IT
                               ;WITH THE "TSTF", ABOVE), JUMP
                               ;AHEAD.

       BCF     FLAG,0          ;WE JUST DECREMENTED COUNT_TS TO 0,
                               ;SO CLEAR FLAG'S BIT 0.

   NOCLEAR:

       ; .... THE REST OF YOUR CODE GOES HERE ....

Hope this helps...

-Andy

=== Andrew Warren - fastfwdspamKILLspamix.netcom.com
=== Fast Forward Engineering, Vista, California
=== http://www.geocities.com/SiliconValley/2499

1997\04\09@033657 by mike

flavicon
picon face
In message  <.....9NQS2DAjmtSzEwzmKILLspamspam.....philmart.demon.co.uk> EraseMEPICLISTspam_OUTspamTakeThisOuTMITVMA.MIT.EDU
writes:
> Ahhh,
>
> If anyone reads my last post, thanks but I solved the problem of Simu
> input to pins inn MPLAB-SIM.
>
> Next problem though has got me.
>
>         decfsz  count_ts        ; decrease counter if not zero
> ;
>         addlw   .0              ; put 0 in w reg
>         xorlw   count_ts        ; is counter at 0
>         btfsc   status,Z
>         bcf     flag,0          ; yes so set flag,0 to 0
> ;
>
> As you van see, I'm decreasing a counter on a program loop. When the
> counter reaches 0, I want to set the flag,0 bit to 0. Thing is the xorlw
> or the btfsc is not picking up the 0 in count_ts.
>
Philip,

To check if a file reg is zero, you can move it to itself:

       movf    count_ts, f     ; This will alter the zero flag.

In MPASM there is also a built in macro which does the same job:

       tstf    count_ts        ; Equivalent to movf    x, f

You can also use the skpz and skpnz built in macros to test the
zero flag. I think they make code easier to write, debug and
(after some time has passed) modify.


Regards,


Mike Watson

1997\04\09@042507 by Kieran Sullivan

flavicon
face
Next problem though has got me.

       decfsz  count_ts        ; decrease counter if not zero
Your comments are slightly wrong, decfsz means decrement then skip if result is
zero.
;
       addlw   .0              ; put 0 in w reg
This will add 0 to w, not set w to 0. movlw 0 is one way to set w to 0.

       xorlw   count_ts        ; is counter at 0
       btfsc   status,Z
       bcf     flag,0          ; yes so set flag,0 to 0
;

You could try to following instead of the code you have above:
       decfsz  count_ts
       goto    NextStage
       bcf     flag,0
NextStage       .....


I think that should work instead of your code.

Kieran

1997\04\09@154312 by Philip Martin

flavicon
picon face
In article <199704090656.BAA01630spamspam_OUTdfw-ix7.ix.netcom.com>, Andrew Warren
<@spam@fastfwdKILLspamspamIX.NETCOM.COM> writes
{Quote hidden}

Hi all,

To Andy and all the other replies to my problem, thank you very much. It
all is working fine now and of course my understanding of the language
has been improved :-)

Again Taa.

--
Philip Martin   ----------------------------------------------------------------
Royal Quays             If at first you don't succeed, try again. Then quit:
North Shields.          no use being a damn fool about it !
                                                       W.C. Fields
email RemoveMEphilipTakeThisOuTspamphilmart.demon.co.uk

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