how to dynamically assign port pins

I have several identical devices which I want to connect to differing port pins. I want to pass to my function, which device, and then have the function perform a switch statement dynamically assigning clock, oe, strobe, data lines to the port pins for that device. For example,
function(int ic)
sbit CLOCK;
sbit DATA_OUT;
sbit OE;
sbit STROBE;

switch(chip){
case 0:
CLOCK = P1^0;
DATA_OUT = P1^2;
OE = P1^7;
STROBE = P3^4;
break;

case 1:
sbit CLOCK = P1^0;
sbit DATA_OUT = P1^2;
sbit OE = P1^7;
sbit STROBE = P3^4; break;
}

but the compiler pukes on this--giving syntax error near each 'sbit' declaration and use. However, if I declare the sbit's fixed at the top of the file, the compiler is happy-- but then I would have to duplicate the function with multiple copies referencing the port pins in question for that device.

Any ideas on how to make this work?

THanks!

Parents
  • "I have several identical devices which I want to connect to differing port pins."

    Normally, you'd have something like the CLOCK, DATA_OUT, and STROBE pins all wired together, and individual 'Select' (OE?) lines for each device.
    Or your serial protocol would handle the addressing.

    Could you explain in more detail what you're actually trying to achieve?

Reply
  • "I have several identical devices which I want to connect to differing port pins."

    Normally, you'd have something like the CLOCK, DATA_OUT, and STROBE pins all wired together, and individual 'Select' (OE?) lines for each device.
    Or your serial protocol would handle the addressing.

    Could you explain in more detail what you're actually trying to achieve?

Children
More questions in this forum