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

Pin I/O using variables with CCS C

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







Pin I/O using variables with CCS C
PostPosted: Fri Feb 09, 2007 10:24 am     Reply with quote

As I know, CCS functions as Input(PIN) requires PIN to be constant. I need a function uses variable. I have tried to write 2 functions for this, but they are not working.

void SetBit(char a)
{
#asm
MOVLW a
MOVWF FSR
BSF INDF,2
#endasm
}


void ClrBit(char a)
{
#asm
MOVLW a
MOVWF FSR
BCF INDF,2
#endasm
}


I expected that the SetBit function to set pin 2 of portA when the variable a is 5. The other one clears the same pin. I also want to use variable for pins as in the code below.

void SetBit(char a, char b)
{
#asm
MOVLW a
MOVWF FSR
BSF INDF,b
#endasm
}


I need these functions because, I am using several sensors at different pins. If I use the same library, I have to use the same library several times with different pin definitions. This would lead unnecesary code size increase and there will be no space for other things. I am using a 16F877.

Any help will be appreciated.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Feb 09, 2007 10:27 am     Reply with quote

Here are functions to do pin i/o with the pin number passed as
a variable:

For 16F:
http://www.ccsinfo.com/forum/viewtopic.php?t=25280&start=4

For 18F:
http://www.ccsinfo.com/forum/viewtopic.php?t=27723&start=3
dundara
Guest







PostPosted: Sat Feb 10, 2007 5:02 am     Reply with quote

I was wondering about timing since the switch method did not worked on my project because of increased proc. times. But your function has solved my problem at 20Mhz.

I thank you, PCM programmer.
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