You'll have to pass the address of the port and a bitmask instead. For example: void MAX3110_WRITE( unsigned char c, unsigned char *port, unsigned char mask ) { MAX3110_SETSPI(); // setup SPI port for MAX3110 while(!(MAX3110_STATUS() & 0x4000)); *port &= ~mask; // select MAX3110 SPI_SEND(0x80); // write data command SPI_SEND(c); // send the data *port |= mask; // deselect the MAX3110 } Bob Ammerman RAm Systems ----- Original Message ----- From: "Nick Veys" To: Sent: Friday, April 26, 2002 4:36 PM Subject: [PIC]: Passing "bit" variables in Hi-Tech C > I know there's plenty of C users here so here goes. > > I decided to at least try the plunge into the PIC C world, after all ASM > it's starting to get old! :) > > So I am looking to write a few headers, one is for the MAX3110's I use. > I need to have a chipselect line for each of them, so I can't just > define it as there will be > 1. I want to simply pass the "bit" > variable I setup in the main program to the functions for the 3110 that > way I can use lots of them. > > My problem is, PICC bitches when I put a bit in a parameter list for a > function. > > Here's a sample: > > ------------------------------ > > void MAX3110_WRITE(unsigned char c) > { > MAX3110_SETSPI(); // setup SPI port for MAX3110 > while(!(MAX3110_STATUS() & 0x4000)); > // chipselect = 0; // select MAX3110 > SPI_SEND(0x80); // write data command > SPI_SEND(c); // send the data > // chipselect = 1; // de-select MAX3110 > } > > ------------------------------ > > This simply writes a byte to the 3110. The chipselects are commented > out, as when I add the bit to the parameter list, and uncomment them, as > so: > > ------------------------------ > > void MAX3110_WRITE(unsigned char c, bit chipselect) > { > MAX3110_SETSPI(); // setup SPI port for MAX3110 > while(!(MAX3110_STATUS() & 0x4000)); > chipselect = 0; // select MAX3110 > SPI_SEND(0x80); // write data command > SPI_SEND(c); // send the data > chipselect = 1; // de-select MAX3110 > } > > ------------------------------ > > I get "bits must be either global or static" error. So I make them > static. > > ------------------------------ > > void MAX3110_WRITE(unsigned char c, static bit chipselect) > > ------------------------------ > > Now I get "bad storage class" error. > > So I read the manual. ;) I can't make them global since I need multiple > ones, and this seems the simplest way, but sadly I find in the manual, > "bit variables cannot be function parameters". Argh. > > So any ideas on how to work around this limitation? I could pass a > PORT,BIT pair as a struct, but that seems messy. There's gotta be a > slick way to do this. > > nick@veys.com | www.veys.com/nick > > -- > http://www.piclist.com hint: To leave the PICList > mailto:piclist-unsubscribe-request@mitvma.mit.edu > > -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu