Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

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 + :confused:

what happened to Pic Basic pro! :mad:
 
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.
 
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
 
I use Word!
Code:
B0 var word

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.?
 
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.:confused:

Have you tried DIM B0 as DWORD.?
 

Attachments

  • esp01 Dec. 20.gif
    esp01 Dec. 20.gif
    14.3 KB · Views: 229
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.?
 
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
    esp02 Dec. 20.gif
    16.9 KB · Views: 266
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top