In SX Microcontrollers, SX/B Compiler and SX-Key Tool, fsafstrom wrote: Howdy... Is it possible to use a pin as a variable ? Right now I have eight pins defined as following: [code] CanRX1 PIN RC.7 input 'CAN Receive to MCP2515 PIN 15 SO CanTX1 PIN RC.6 output 'CAN Transmit to MCP2515 PIN 14 SI PINcs1 PIN RC.5 output 'CAN Chip Select to MCP2515 PIN 16 CS PINclk1 PIN RC.4 output 'CAN Clock to MCP2515 PIN 13 SCK CanRX2 PIN RB.7 input 'CAN Receive to MCP2515 PIN 15 SO CanTX2 PIN RB.6 output 'CAN Transmit to MCP2515 PIN 14 SI PINcs2 PIN RB.5 output 'CAN Chip Select to MCP2515 PIN 16 CS PINclk2 PIN RB.4 output 'CAN Clock to MCP2515 PIN 13 SCK These pins represent chip 1 and chip 2 of the same type chip. And then two subroutines using these pins. [code] resetCan1: LOW PINcs1 SHIFTOUT CANTX1, PINclk1, MSBFIRST, $C0 'Send a RESET command HIGH PINcs1 return resetCan2: LOW PINcs2 SHIFTOUT CANTX2, PINclk2, MSBFIRST, $C0 'Send a RESET command HIGH PINcs2 return [/code] Now every time I add a subroutine, I have to add two of them, one for chip 1 and one for chip 2. What I want to do is to to use one routine and pass a variable 1 or 2 depending on which chip I want to access. For two chips it might be easier to just do an if statement and then select either SHIFTOUT command. However I probably want to add more chips and I wonder if it is possible to do something like this. [code] CanRX1 PIN RC.7 input 'CAN Receive to MCP2515 PIN 15 SO CanTX1 PIN RC.6 output 'CAN Transmit to MCP2515 PIN 14 SI PINcs1 PIN RC.5 output 'CAN Chip Select to MCP2515 PIN 16 CS PINclk1 PIN RC.4 output 'CAN Clock to MCP2515 PIN 13 SCK CanRX2 PIN RC.3 input 'CAN Receive to MCP2515 PIN 15 SO CanTX2 PIN RC.2 output 'CAN Transmit to MCP2515 PIN 14 SI PINcs2 PIN RC.1 output 'CAN Chip Select to MCP2515 PIN 16 CS PINclk2 PIN RC.0 output 'CAN Clock to MCP2515 PIN 13 SCK CanRX3 PIN RB.7 input 'CAN Receive to MCP2515 PIN 15 SO CanTX3 PIN RB.6 output 'CAN Transmit to MCP2515 PIN 14 SI PINcs3 PIN RB.5 output 'CAN Chip Select to MCP2515 PIN 16 CS PINclk3 PIN RB.4 output 'CAN Clock to MCP2515 PIN 13 SCK CanRX4 PIN RB.3 input 'CAN Receive to MCP2515 PIN 15 SO CanTX4 PIN RB.2 output 'CAN Transmit to MCP2515 PIN 14 SI PINcs4 PIN RB.1 output 'CAN Chip Select to MCP2515 PIN 16 CS PINclk4 PIN RB.0 output 'CAN Clock to MCP2515 PIN 13 SCK CanRX PIN RB.3 input 'CAN Receive to MCP2515 PIN 15 SO CanTX PIN RB.2 output 'CAN Transmit to MCP2515 PIN 14 SI PINcs PIN RB.1 output 'CAN Chip Select to MCP2515 PIN 16 CS PINclk PIN RB.0 output 'CAN Clock to MCP2515 PIN 13 SCK . . . resetCan: chip = __PARAM1 if chip = 1 then PINcs = PINcs1 CANTX = CANTX1 PINclk = PINclk1 elseif chip = 2 then PINcs = PINcs2 CANTX = CANTX2 PINclk = PINclk2 elseif chip = 3 then PINcs = PINcs3 CANTX = CANTX3 PINclk = PINclk3 elseif chip = 4 then PINcs = PINcs4 CANTX = CANTX4 PINclk = PINclk4 endif LOW PINcs SHIFTOUT CANTX, PINclk, MSBFIRST, $C0 'Send a RESET command HIGH PINcs return [/code] I tried this and the defined pins will not chage. Is this possible ??? Any other suggestions ??? ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=142595 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2006 (http://www.dotNetBB.com)