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

How to pass non-constant args to to input(PIN_B0))

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



Joined: 20 Sep 2005
Posts: 23
Location: Glasgow, Scotland, UK

View user's profile Send private message

How to pass non-constant args to to input(PIN_B0))
PostPosted: Tue Mar 07, 2006 8:27 am     Reply with quote

I wish I could parameterise code like that below, then I wouldn't have to hardcode it for each bit that I want to test. Is there any way around a func that insists on a constant for an arg?
Code:

   b5_went_low = FALSE;
   while ( !b5_went_low ) // N.B. you have to press SW2 to get out of the loop
   {
      while( input(PIN_B0)) // if only I could pass arg - const only means having to hardcode it
         ;
      sprintf(pszTmp, "Open   ");
      LCD_putstr_xy(pszTmp, LCD_COL0+6, LCD_ROW1);
      //delay_ms(TEST_HOLD_TIME);

      while( !input(PIN_B0))
         ;
      sprintf(pszTmp, "Shorted");
      LCD_putstr_xy(pszTmp, LCD_COL0+6, LCD_ROW1);
      //delay_ms(TEST_HOLD_TIME);
   }


I would have thought that it was not significantly more difficult for a compiler to compile a call that pushes a variable address on the stack than a constant...?
Ttelmah
Guest







PostPosted: Tue Mar 07, 2006 9:48 am     Reply with quote

The compiler does not call a routine,and push a constant onto the stack. The PIC, does not have a stack for variables (only for addresses). The constant code, does not generate a routine at all, but just uses the processor 'bit set' function, which only accepts a constant.
The 'variable' version, will be a lot bulkier (typically about 30 to 40* the size of the constant access), but may well be worthwhile.
The common way of doing this, is to address the port through a pointer, and then use a bit mask. If you only need to access different bits in a single port, then the overhead is a lot less. There have been dozens of routines published here in the past to do this, and a search ought to find these.

Best Wishes
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Mar 07, 2006 9:57 am     Reply with quote

Quote:

I wish I could parameterise code like that below, then I wouldn't have to
hardcode it for each bit that I want to test. Is there any way around a
func that insists on a constant for an arg?

http://www.ccsinfo.com/forum/viewtopic.php?t=25280&start=4
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