View previous topic :: View next topic |
Author |
Message |
dundara Guest
|
Pin I/O using variables with CCS C |
Posted: Fri Feb 09, 2007 10:24 am |
|
|
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
|
|
|
dundara Guest
|
|
Posted: Sat Feb 10, 2007 5:02 am |
|
|
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. |
|
|
|