> > Hi all, > > I have a question about passing the name of a pin as an argument to a > > function. For example, I have a function driveservo(drivevalue, servopin) > > and I might want to pass RA0 as the value for servopin. > > > > The thing is, if I declare the function as void drvieservo(int drivevalue, > > bit servopin) the compiler throws an error. I am a bit lost as to how to > > get > > around this problem. I have tried a few hacks, but feel I am probably > > missing something here. > > > > Can anyone help out a Hi-Tech C newbie? > > > > Thanks for any and all help, > > James Fitzsimons > > > > P.S I don't think it should make any difference, but driveservo is > > declared > > in a different file (servo.c) than the file it is called from (motcont.c) > > > You cannot pass a 'bit' as an argument in HiTech. One possible workaround > is to pass a bitmask which can be OR'd or AND'ed with the port to set or > clear a bit. > > Mike > To expand on the idea a bit (no pun intended): [i use unsigned char below for 8 bit values, as this is more ANSIish, YMMV depending on your compiler] void driveservo(int val, unsigned char *port, unsigned char mask) { // to turn on the pin: *port |= mask; // to turn off the pin *port &= ~mask; // to test the pin if ( *port & mask ) ... } void main() { // Do pin RA5 driveservo( 123, &PORTA, 1 << 5 ); // And pin RB3 driveservo( 456, &PORTB, 1 << 3 ); } Bob Ammerman RAm Systems -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics