Exact match. Not showing close matches.
PICList
Thread
'[PIC]:16 bit 2's complement compare'
2001\03\12@120349
by
Steven Allard
Hello all,
I have a subroutine which reads a DS1820 and returns two bytes. TEMP_MSB
is FF for negative values and 00 for positive. TEMP_LSB is an 8 bit
two's complement value of temperature (bit0 actually represents 0.5c)
I am trying to compare such that:
If TEMP > MAX then MAX=TEMP
and
If TEMP < MIN then MIN=TEMP
Using standard compare routines from the archive I can make the code
work for positive values, but I am stuck comparing negative values
against positive ones etc.
Does anyone have any pointers, suggestions, pseudocode etc. which would
help ?
Thanks
Steve Allard

http://www.piclist.com hint: To leave the PICList
spam_OUTpiclistunsubscriberequestTakeThisOuTmitvma.mit.edu
2001\03\12@134657
by
Drew Vassallo

>Using standard compare routines from the archive I can make the code
>work for positive values, but I am stuck comparing negative values
>against positive ones etc.
I guess I don't fully understand. If you have a "flag byte" TEMP_MSB that
indicates whether you're positive or negative, aren't you making use of it?
Doesn't make sense that you can't compare a positive and a negative number
differential.
; assume temp differential is 4 degrees for the sake of argument
; and that TEMP_MSB=0xFF (negative value)
movlw 0x02 ; which is really 2 if TEMP_MSB==0xFF
movwf byte_1
movlw 0x02 ; initial reading to compare against
movwf byte_2
incf TEMP_MSB, 0 ; overflow it to 0x00 (maybe)
btfss STATUS, Z ; if temp was negative, Z=1
goto $+3
comf byte_1, 1
incf byte_1, 1 ; negate byte if negative
movf byte_1, 0 ; compare bytes
subwf byte_2, 0
; now W holds the differential, perform standard C, Z comparisons
; to determine MAX value, etc.
Is this not what you're doing? Maybe I'm missing your point.
Andrew
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com

http://www.piclist.com hint: To leave the PICList
.....piclistunsubscriberequestKILLspam@spam@mitvma.mit.edu
More... (looser matching)
 Last day of these posts
 In 2001
, 2002 only
 Today
 New search...