Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[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
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:

@ Brian
voltage is declared as unsigned int (u16)
 

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
 

It's probably not the case, but check if the default radix of compiler is decimal.
 

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 ???
{
....
}
 

It was happening because of Timer Interrupt. Solved.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top