Probably a stupid question, reading pin input levels with Hi-Tech C?

Thread Starter

GuitarMan216

Joined Oct 6, 2011
18
I'm working on a program, and in a nutshell, I just need to know how to tell if the PORTD pins are high or low, based on push buttons.

Wasn't sure if I could do a if(RD0<1) blah blah blah.

Sorry, tried searching, couldn't find an answer. I'll keep searching.

Thanks for your help!
 

nerdegutta

Joined Dec 15, 2009
2,684
You could try something like this:

Rich (BB code):
while (1)
{
  if (RD0)
  {
     do some code
   }
  if (RD1)
  {
     do some other code
   }
else
   {
     do something complete different
   }
} // end while
I'm sure there are other way to do it. :)
 

Thread Starter

GuitarMan216

Joined Oct 6, 2011
18
You could try something like this:

Rich (BB code):
while (1)
{
  if (RD0)
  {
     do some code
   }
  if (RD1)
  {
     do some other code
   }
else
   {
     do something complete different
   }
} // end while
I'm sure there are other way to do it. :)
What exactly is the while(1) doing? And is the if(RD0) checking if RD0 is high?

Thanks again.
 

nerdegutta

Joined Dec 15, 2009
2,684
The
Rich (BB code):
while (1)
{
  do something forever
}
Is an endless loop, since 1 is not changing.

Rich (BB code):
if (RD0)
{
   do some code
}
Checks if RD0 is 1 or high. You could write:
Rich (BB code):
if (RD0==1)
{
  do some code
}
 

Thread Starter

GuitarMan216

Joined Oct 6, 2011
18
The
Rich (BB code):
while (1)
{
  do something forever
}
Is an endless loop, since 1 is not changing.

Rich (BB code):
if (RD0)
{
   do some code
}
Checks if RD0 is 1 or high. You could write:
Rich (BB code):
if (RD0==1)
{
  do some code
}
Ok, so my original idea of if(RD0<1) would suffice? If that'll work, I think I'm good to go. Just wasn't sure how Hi Tech C dealt with the inputs. I'm more interested in when it's low, than high.

Thanks again, I appreciate it.
 

Thread Starter

GuitarMan216

Joined Oct 6, 2011
18
Just in case someone searches this for similar advice, I went with this code, and it works like a charm.

Thanks guys.

Rich (BB code):
if(RD0==0)
{
	String=E_S;
	Tolerance=.224;
	TRISA=0b00100010;
}

if(RD1==0)
{
	String=A_S;
	Tolerance=.300;
	TRISA=0b00000001;
}

if(RD2==0)
{
	String=D_S;
	Tolerance=.4008;
	TRISA=0b00011000;
}

if(RD3==0)
{
	String=G_S;
	Tolerance=.535;
	TRISA=0b00100100;
}

if(RD4==0)
{
	String=B_S;
	Tolerance=.674;
	TRISA=0b00110000;
}

if(RD5==0)
{
	String=EH_S;
	Tolerance=.899;
	TRISA=0b00100010;
}
 
Top