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?
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?