CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Checking to see if a pin is High or Low

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
The Rookie
Guest







Checking to see if a pin is High or Low
PostPosted: Wed May 12, 2004 3:42 pm     Reply with quote

I would like to develop a routine that checks to see if a pin is High or Low.

If the Pin is high it will do one thing of it is low it will do another.

Thanks

The Rookie
Joyce
Guest







PostPosted: Wed May 12, 2004 4:12 pm     Reply with quote

if(input(PIN_Ax)) // pin high
{
do high
}
else
{
do low
}
Suus



Joined: 11 May 2004
Posts: 8

View user's profile Send private message

PostPosted: Thu May 13, 2004 1:06 am     Reply with quote

Hello,

Can I make it shorter like:

if(PIN_Ax)
{
}

else
{
}

????

Susan
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Thu May 13, 2004 2:24 am     Reply with quote

Not in that format, but you can define a 'bit' like this:

#bit RA1=0x05.1 //On PIC16F877, 0x05 is the address of PORTA.

Now you can say:

RA1=1;

or

if(RA1)
{
...
}
else
{
...
}
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu May 13, 2004 2:53 am     Reply with quote

Please note that the for the shorter version to work you will also have to define the I/O pin as input first! While in the 'longer' version the compiler will do this for you.

So, what is 'shorter'.... ??? Confused

Both examples lead to similar assembly code, so I guess it's a matter of taste.
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Thu May 13, 2004 3:00 am     Reply with quote

Actually the pin doesn't need to be configured as input. You can use this method to read/verify the state of an output pin as well.
Suus



Joined: 11 May 2004
Posts: 8

View user's profile Send private message

PostPosted: Thu May 13, 2004 4:20 am     Reply with quote

And how to check if a pin is low?

(input(!PIN_B0))

or

(!input(PIN_B0))

Susan
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Thu May 13, 2004 4:27 am     Reply with quote

input() is a C function, so:

if(!input(PIN_B0))
{
...
}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group