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

passing pin define

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



Joined: 10 Feb 2011
Posts: 241
Location: Vancouver, BC

View user's profile Send private message

passing pin define
PostPosted: Mon Mar 07, 2011 4:49 pm     Reply with quote

Hi There,

I wanna build a function that i can call and it will return me a low pass filtered analog value.
I wanted to do it like this:
Code:
void GetFilteredAnalog(int16 adconv, int16 *value, int16 filter){
    //Read ADC value
  int16 adcval=0;
  setup_adc_ports(adconv);

but the compiler for some reason tells me A numeric expression must appear here and points to setup_adc_ports(adconv) but adconv is defined as int16. I'm not quite sure what the compiler wants from me. I'm using 4.119 and an 18f87k22.

Thank you
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Mar 07, 2011 5:07 pm     Reply with quote

It's simple enough to test. Just make a test program with a constant
and a variable as the parameter. In the program below, the compiler
gives an error for the variable. Therefore, it can't accept a variable
as the parameter for this particular function.
Code:

#include <16F877.H>
#fuses XT, NOWDT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

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

setup_adc_ports(NO_ANALOGS);

setup_adc_ports(temp);  // This line gives an error

while(1);
}


The CCS manual says this:
Quote:

setup_adc_ports( )

Syntax:
setup_adc_ports (value)
setup_adc_ports (ports, [reference])

Parameters: value - a constant defined in the devices .h file
cerr



Joined: 10 Feb 2011
Posts: 241
Location: Vancouver, BC

View user's profile Send private message

PostPosted: Tue Mar 08, 2011 10:57 am     Reply with quote

uhm, I found a do_pin_io(PIN) function example for digital IOs but nothing for analog. Tried around a bit but couldn't figure it out and const-casts are only possible in C++ - any clues?
Thank you!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Mar 08, 2011 12:19 pm     Reply with quote

You can look at the .LST file (in Symbolic mode) and see how CCS does
the setup_adc_ports() function. Then use #byte statements to define
the PIC registers used by that function. Use getenv() to easily get the
register addresses. Then you can either write directly to the ADC
registers in your posted function, or you can create your own
setup_adc_ports() function and call it from your posted function.
In other words, make a substitute function that can accept a variable
as the parameter.

Another way to do it would be to pass a numeric index to your posted
function (in adconv) and use a switch-case statement to select the
configuration for setup_adc_ports(). In other words, each 'case' would
have its own line for setup_adc_ports(), with different parameters in
each one. This method would be the least amount of work, but would use
more ROM space.
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