[SOLVED] False if Condition is Getting True in XC8 with PIC18F

Status
Not open for further replies.

anupteke

Junior Member level 2
Joined
Nov 9, 2008
Messages
21
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
India
Visit site
Activity points
1,424
Hi all,

Guy's Im working on PIC18F45K22 using XC8 1.33V. My problem is
Code:
if((u16)Voltage > (u16)280)
{
	DispRYBCnt = 6;
	DispBuffer[3] = CHAR_r;
}
even Voltage Variable is less than 280 this condition is getting true. I tried this also
Code:
Voltage = 210;
if((u16)Voltage > (u16)280)
{
	DispRYBCnt = 6;
	DispBuffer[3] = CHAR_r;
}
but still 'if' condition is getting true. what is the problem. its compiler issue or what?

Kindly guide me guy's.

Thanks
 
Last edited by a moderator:

How do you know the following conditional test is evaluated as true?

Code:
Voltage = 210;
if((u16)Voltage > (u16)280)
{
	DispRYBCnt = 6;
	DispBuffer[3] = CHAR_r;
}

Are you using a debugger? If so, what specific debugger are you using?


Obviously, there is a conflict in your code which we are not yet privy.

Please post or upload your entire source code, so that it maybe thoroughly examined.

Use CODE or SYNTAX tags if posting and the forum servers, Managed Attachment feature, if uploading.


BigDog
 

I'm not using XC8 but I do not think that the casting of a numeric constant is correct.
Try this out:
Code:
Voltage = 210;
if (Voltage > 280) // or 280u ???
{
....
}
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…