|
|
View previous topic :: View next topic |
Author |
Message |
KenMacfarlane
Joined: 20 Sep 2005 Posts: 23 Location: Glasgow, Scotland, UK
|
How to pass non-constant args to to input(PIN_B0)) |
Posted: Tue Mar 07, 2006 8:27 am |
|
|
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
|
|
Posted: Tue Mar 07, 2006 9:48 am |
|
|
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
|
|
|
|
|
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
|