# PIC16F84: Z-flag will not set

Status
Not open for further replies.

#### rizzy

##### New Member
Hi. I'm working on some code for the PIC 16F84 that requires two numbers to be compared. Afterwards, I check the z-flag in the STATUS register (0x03, bit2) to see if it is set. I've been having some problems and I traced it back to the Z-flag. It will not set after an arithmetic or logic operation for some reason. I can set it with the BSF command, however (which really doesn't help). Here is a snippet of code I wrote to see if the z-flag is working:

zero MOVLW 0xAA
MOVWF CODE3
MOVLW 0xAA
MOVWF NUM3 ;here, I set both variables
;to the same value
MOVF CODE5,W
SUBLW NUM5 ;subtract CODE5 from NUM5
BTFSS STATUS,2 ;check z-flag (should be set)
GOTO no_luck
CALL pin1
GOTO zero
no_luck CALL pin2
goto zero

The "pin1" and "pin2" subroutines activate RA0 or RA1 so that I can see which path was taken.

No matter what I do, the Z-flag will not set. I've tried using different variables, even with different values to see if the bit was inverted. I've also tried moving a single variable into W and subtracting it from itself, and I tried using XORLW instead of SUBLW with the same result. Is there something i'm missing? Why won't the flag set?

#### Nigel Goodwin

##### Super Moderator
This is the code that I use to check two values:
Code:
movf	value1, w
subwf	value2, w
btfss	STATUS, Z
goto	Wrong

#### rizzy

##### New Member
the SUBWF command seems to work fine. I tried it in place of SUBLW and my program runs perfectly. Thanks for your help.

Status
Not open for further replies.

Replies
14
Views
4K
Replies
2
Views
871
Replies
6
Views
1K
Replies
7
Views
1K
Replies
8
Views
2K