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 CCS Technical Support

Input state with #BIT pre-processor

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



Joined: 21 Nov 2011
Posts: 6

View user's profile Send private message

Input state with #BIT pre-processor
PostPosted: Mon Jan 20, 2014 2:49 pm     Reply with quote

Hi all!

I'm using PIC18F258 and I would like to refer inputs with #bit pre-processor.
Is this would work?
Code:

// setting the pin direction to input
set_tris_a(0xFF);
//
#byte PORTA = getenv("SFR:PORTA")
//
#bit A0 = PORTA.0
//
if (A0 == 1)
{
// do something...
}

When the Input pin is changing, the PORTA register is also changing ? Or I have to use input() statement...

Thanks in advance!

Valentinus
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jan 20, 2014 3:05 pm     Reply with quote

You can test this. Make a small test program that uses both methods.
Compile it and look at the code in the .LST file. See if there are any
important differences. If not, then you have proved it will work.
Code:
#include <18F258.h>
#fuses XT, NOWDT, BROWNOUT, PUT
#use delay(clock=4M)

#byte PORTA = getenv("SFR:PORTA")
#bit A0 = PORTA.0

//========================
void main()
{
int8 i;

set_tris_a(0xFF);

if(A0 == 1)
   i = 0x55;

if(input(PIN_A0) == 1)
   i = 0x55;


while(1);
}
Valentinus



Joined: 21 Nov 2011
Posts: 6

View user's profile Send private message

PostPosted: Mon Jan 20, 2014 3:48 pm     Reply with quote

Thank you very much for this practical idea. That was very helpfull.

And the answer for my question is: Yes, it will work!!! :D

Thank you again!
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