hey guys...
i wanted to know how to make multiple conditions such that each condition has arange of values...i have written the following code but doesnt work
help me quick plz.
It is aPIC program for monitoring the ADC value and sending to LCD

if(ADRESL==0x00)
						{lcddata('O');
						DELAY(2);
						lcddata('F');
						DELAY(2);
						lcddata('F');
						DELAY(2);
						}					
						else if(0x00<ADRESL<0x70)
						{
						lcddata('S');
						DELAY(2);
						}											
							else
							{
							lcddata('M');
							DELAY(2);
							}

Recommended Answers

All 16 Replies

Try to change code as:

if(ADRESL==0x00)
{lcddata('O');
DELAY(2);
lcddata('F');
DELAY(2);
lcddata('F');
DELAY(2);
}	
else if(0x00<ADRESL && ADRESL<0x70)
{
lcddata('S');
DELAY(2);
}	
else
{
lcddata('M');
DELAY(2);
}

And more over, concentrate on datatype of "ADRESL".

thanx Yellaiah.....also want to know how to specify three or four else if statements just like :

else if(0x00<ADRESL && ADRESL<0x70)
{
lcddata('S');
DELAY(2);
}

so that i can make code for three different ranges of values coming from ADC...

Just create more else if's.

Just create more else if's.

does that work....i'm having problems in the simulation...the first else if doesnt work in the correct range that Yellaiah told me....

ADRESL is of which type?

it is 8-bit binary output of a PIC's internal ADC...i am converting the particular binary codes to HEX and then using them in the code

ADRESL is of which type?

it is 8-bit binary output of a PIC's internal ADC...i am converting the particular binary codes to HEX and then using them in the code

does that work....i'm having problems in the simulation...the first else if doesnt work in the correct range that Yellaiah told me....

Then you did it wrong. Without seeing the code, we can't offer suggestions.

Then you did it wrong. Without seeing the code, we can't offer suggestions.

#include<p18f458.h>
#include<delays.h>
#define ldata PORTD
#define rs PORTEbits.RE0
#define rw PORTEbits.RE1
#define en PORTEbits.RE2
void DELAY(unsigned int);
void lcdcmd(unsigned char);
void lcddata(unsigned char);
void main(void)
{

		TRISB=0;
		TRISD=0;
		TRISE=0;
		TRISAbits.TRISA0=1;
		ADCON0=0x81;
		ADCON1=0xCE;
		TXSTA=0x20;
		SPBRG=15;
		TXSTAbits.TXEN=1;
		RCSTAbits.SPEN=1;
		en=0;
		DELAY(250);
		lcdcmd(0x38);
		DELAY(250);
		lcdcmd(0x0e);
		DELAY(250);
		lcdcmd(0x01);
		DELAY(250);
		lcdcmd(0x06);
		DELAY(250);
		lcdcmd(0x80);
		DELAY(250);
{
DELAY(2);
ADCON0bits.GO=1;
while(ADCON0bits.DONE==1);

	{
		PORTB=ADRESL;
		DELAY(2);
		{
			if(ADRESL==0x00)
			{lcddata('O');
			DELAY(2);
			lcddata('F');
			DELAY(2);
			lcddata('F');
			DELAY(2);
			}	
			else if(0xF5<ADRESL && ADRESL<0x70)
			{
			lcddata('S');
			DELAY(2);
			}	
			else
			{
			lcddata('M');
			DELAY(2);
			}			
	}					
	}		
}

	
}


void DELAY(unsigned int itime)
{
unsigned int i;unsigned char j;
for(i=0;i<itime;i++)
for(j=0;j<165;j++);
}
void lcdcmd(unsigned char value)
{
		ldata=value;
		rs=0;
		rw=0;
		en=1;
		DELAY(1);
		en=0;

}

void lcddata(unsigned char value)
	{
	ldata=value;
	rs=1;
	rw=0;
	en=1;
	DELAY(1);
	en=0;
	
	}
commented: Still not getting the code tags message! -4

Then you did it wrong. Without seeing the code, we can't offer suggestions.

I have uploaded the full code...i's not too good in c++ becz i originally used to program in Assembly but now our tutor has made it compulsory to write code in c++....plz help me out guyz...

I don't see any attempt at more than one else-if . That's probably why more of them didn't work.

Learn to format your code properly. It's hard to read as it is.

I don't see any attempt at more than one else-if . That's probably why more of them didn't work.

Learn to format your code properly. It's hard to read as it is.

i uploaded the simple one bcz the single if-else statement in this code also isnt working within it's original range....

What's the value of ADRESL before the IF statement? Is it a byte or an int? signed or unsigned? 0xF5 is a negative value if a byte.

What's the value of ADRESL before the IF statement? Is it a byte or an int? signed or unsigned? 0xF5 is a negative value if a byte.

I'll tell u a bit of detail about ADRESL...
The ADC in the PIC gets an analog value and converts it into a 10 bit digital output. 8 bits are loaded in the ADRESL(analog to digital result low) while the upper two bits are loaded in the ADRESH(analog to digital result high). Both of these are 8 bit Registers inside the PIC's RAM.
I only want to use the ADRESL reg's output to interpret what amount of analogue input came in and then display it on the LCD. Now because i'm only using the ADRESL the value might come negative. I have also made a program using the CASE Switch statement and it worked nicely but the problem was that i could only specify a single input value. I want to specify a range of values to check if they came in and then display a single ASCII character on the LCD. You mentioned int. Can the ADRESL be specified as an int and then used in the if statement. Does it make any sense now. Please tell me my method isn't wrong. Thanks

I'll tell u a bit of detail about ADRESL...

Doesn't answer one of my questions. I suspect you will find you think you are using positive values but they are signed and negative.

Doesn't answer one of my questions. I suspect you will find you think you are using positive values but they are signed and negative.

yes i think it is signed because the analogue values also go in the negative range for example like minus temperature and the value i'm using might also be in the negative range but how does that affect my code...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.