IF B0 < 0 !?!?! in PIC Basic

Status
Not open for further replies.

arvinfx

Member
hi

I need to compare a NEGATIVE variant value with 0 in (Pic Basic pro Studio).

look at the code
Code:
if  B0 < 0 then  
lcdout $fe,1,"-" 
else 
lcdout $fe,1,"+" 
endif

and if i set B0 = -30 or any negative value the output on LCD is +

what happened to Pic Basic pro!
 
I dont know about Pic basic pro, but most simple basic languages dont allow negative values, only positive integers, so somewhere set your "0" to say 127 (half of 255, by adding 127 to the original value) and then use your code the way it is but with "if B0 < 127", so 127 becomes the "default" zero thoughout your program.
 

Thanks but this way is very bulk of code and process!

Is any way in assembly language?
 
Last edited:
Thanks but this way is very bulk of code and process!

Is any way in assembly language?

hi,
How have you defined B0, as byte/word ....?

The Basic only uses unsigned BYTE/WORD Integers, but signed DWORD
 
As a simple test DIM B0 as DWORD.

Perhaps there is an easier way to solve the problem... whats the 'source' of the B0 variable, how is it derived.?


B0 is a output value of DS1820 (1-Wire thermometer )

I use PICBasic Pro v2.45 and your sample code is for Visal Basic!
 
B0 is a output value of DS1820 (1-Wire thermometer )

I use PICBasic Pro v2.45 and your sample code is for Visal Basic!

I know you use PICBasic, I downloaded the instruction manual so that I could answer your question, which if you read the VAR definitions it clearly tells you which are signed and unsigned variables.

As the attached image is from the PICBasic Pro manual how do you come to the conclusion its for Visual Basic.

Have you tried DIM B0 as DWORD.?
 

Attachments

  • esp01 Dec. 20.gif
    14.3 KB · Views: 237
B0 is a output value of DS1820 (1-Wire thermometer )

As I understand the DS1820, its a WORD output format.?

Have you considered using the Th and TL in the users Alarm registers, bit7 the Sign(S) bit defines neg/pos values.

Also if you are trying to measure down to -55Cdeg, why not just add 55 to the read value and do an unsigned test for negative temperatures.?
 

I think its end way to do my compare !

Ok

I test bit of Signe and if it is present my code is:
Code:
if b0 >65000 then ; is negative value!?
If b0 < 65531 then  ; Is b0 < -3 
lcdout $c0,1,"-" 
end if 
endif

its correct!?
 
Last edited:
hi,
Look at this image.

If the upper byte of the tempr value is greater than 0x00 then the tempr is negative.

OK.?
 

Attachments

  • esp02 Dec. 20.gif
    16.9 KB · Views: 274
You've never explained (and still haven't) exactly what compiler you're using - but it seems pretty likely that it doesn't do negative numbers.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…