I have this code. What I want to know is what’s the purpose of this anldw line?
From my view I can say it will never allow to compare D’125’.Bcuz it allows only D’127’.
Help me to solve this problem.
Code:
movf COUNT,W ;get the COUNT value
andlw b'01111111' ;AND with 7Fh (D’127’)
xorlw .125 ;b'01111101'
btfss STATUS,Z ;compare with zero bit
goto Exit
goto Main
As for the ANDLW, it looks like it's used for BIT stripping. All values from bits 0-6 will be passed through but bit 7 not. (Maybe the original code was used for 7-segment display where bit <7> was not used ??)
You have to look at the rest of the code in order to work out why you need the andlw 0x7f. Bit 7 is used to keep track of the state of the LED. From your other thread,
Code:
movlw .6
addwf TMR0,F
incf TIME,F
movf TIME,W
andlw 7fh
xorlw .125
btfss STATUS,Z
goto Away
btfss TIME,7
goto $+4
clrf TIME ;[COLOR="Blue"]Bit 7 = 0[/COLOR]
bcf LED ;turn OFF led
goto Away
clrf TIME
bsf TIME,7 ;[COLOR="blue"]Bit 7 = 1[/COLOR]
bsf LED ;turn ON led
Now I got it. It has used a family bit of the same Time variable.
To avoid confusion I can remove andlw & use another variable before writing to the LED.
BTW I have another doubt question.
I want to check whether the 7th bit of COUNT variable set.
This will set for sure bcuz it has set only the 7th bit.
Code:
COUNT = b’10000000’
Btfss COUNT, 7
What about this It has some other values in first 5 bits but 7th bit is set.
Yes, BTFSS is only checking one specific bit, the rest make no difference.
As for ANDLW, it's the normal logical AND instruction, as used in computers since their first days. With micro-processors (and lesser micro-controllers) your only option form checking (or setting) individual bits is to use combinations of logical AND, OR, XOR instructions.
I have this code. What I want to know is what’s the purpose of this anldw line?
Code:
movf COUNT,W ;get the COUNT value
andlw b'01111111' ;AND with 7Fh (D’127’)
xorlw .125 ;b'01111101'
btfss STATUS,Z ;compare with zero bit
goto Exit
goto Main
"Just as 256 is not a true max, 256 is also not a true minimum" (donniedj circa see post time stamp):
As already stated, it and its accomplice is used to compare an unknown count to a known comparator value. But whats important for you to take from this is how you can compare PARTS of a value, in this case bits 6-0, while not caring about the other parts for the moment. A single variable can have multiple segments. Bit 7 of COUNT could be used for some other purpose such as a flag. Imagine a processor where the smallest data was 4 bytes. A resource limited yet smart coder could make use of each PART as their own 4 separate 1 byte variables coexisting inside 1 entity by a parts compare technique as above.
Code:
;--COMPARE SEGMENT OF COUNT TO COMPARATOR--
MOVF COUNT, W ;STORING COUNT[6-0] INTO W
ANDLW B'01111111' ;
XORLW .125 ;ASSIGN COMPARATOR = 125
BTFSS STATUS, Z ;DOES COUNT[6-0] = COMPARATOR?,
GOTO EXIT ;NO, EXIT
GOTO MAIN ;YES, GOTO MAIN.
;-------------------------------
Do yourself a favor, comment on the significance and not on the literate. Stating lines like
Code:
movf COUNT,W ;get the COUNT value
andlw b'01111111' ;AND with 7Fh (D’127’)
xorlw .125 ;b'01111101'
btfss STATUS,Z ;compare with zero bit