This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to pass sbit variables to other functions?

Hi All,

I am running into problem, where I could not pass sbit variables to a function.

Here's an example:

My SBIT definitions:

sbit OLD_JTAG_TCK = 0xB0+3;
sbit NEW_JTAG_TCK = 0x80+7;

My Function:
void Pulse_TCK(bit sbJTAG_TCK)
{
sbJTAG_TCK = 1;
}

My Main code:

if (old_hardware)
{
Pulse_TCK(OLD_JTAG_TCK)
}
else
{
Pulse_TCK(NEW_JTAG_TCK)
}
For some reason, the above code does not work as I dont see any activity on the TCK pins. Can anyone please help me how to resolve this issue?. Note that I had used the type bit in my function parameter instead of sbit as the later gives syntax error.

Parents
  • If you are extremely tight for memory you may need to do something a little less "pretty"

    You can make two versions based on a flag

    #define NEW_HW // comment this out if compiling for old hardware
    
    #ifdef NEW_HW
       shift_data_into_FPGA_new_hardware();
    #else
       shift_data_into_FPGA_old_hardware();
    #endif
    the routines "shift_data_into_FPGA_..." will automatically configure if they are placed in a library, otherwise surround then with #ifdef etc.

    Erik

Reply
  • If you are extremely tight for memory you may need to do something a little less "pretty"

    You can make two versions based on a flag

    #define NEW_HW // comment this out if compiling for old hardware
    
    #ifdef NEW_HW
       shift_data_into_FPGA_new_hardware();
    #else
       shift_data_into_FPGA_old_hardware();
    #endif
    the routines "shift_data_into_FPGA_..." will automatically configure if they are placed in a library, otherwise surround then with #ifdef etc.

    Erik

Children
  • #ifdef NEW_HW

    I think it's reasonably clear that a compile-time switch is insufficient for the OP's needs. He did mention enumeration, i.e. a run-time initialization process, which would drive the decision which of these routines would be used.

    If an #ifdef could do it, it would be better to use it to switch between the two different definitions of that sbit object.