title: PIC pass SFR address to function in C
body: <p>I am attempting to pass a reference to an I/O pin as an function argument on a PIC24F MCU using C.  For PICs, the device header file provides access to the i/o buffer registers via: </p>
  
  <pre><code>LATAbits.LATA2 = 0;    // sets the pin (RA2 in this case) low.
  if (PORTAbits.RA3) {   // reads the state of the pin. (RA3)
  </code></pre>
  
  <p>I want to do something like this: </p>
  
  <pre><code>int main() {
      Configure();                        // Sets up peripherals, etc. 
      WaitForHigh(PORTAbits.RA3);         // waits for pin RA3 to go hi. 
      ...
  
      return 0;
  }
  
  void WaitForHigh( ?datatype? pin_reference ) { 
  
      while( !pin_reference );            // Stays here until the pin goes hi.
  }
  </code></pre>
  
  <p>So what datatype am I trying to pass here?  And what's actually going on when I poll that pin?  Below, I copy a relevant portion from the PIC24F device header that I'm using in case it helps. </p>
  
  <pre><code>#define PORTA PORTA
  extern volatile unsigned int  PORTA __attribute__((__sfr__));
  typedef struct tagPORTABITS {
    unsigned RA0:1;
    unsigned RA1:1;
    unsigned RA2:1;
    unsigned RA3:1;
    unsigned RA4:1;
    unsigned RA5:1;
  } PORTABITS;
  extern volatile PORTABITS PORTAbits __attribute__((__sfr__));
  </code></pre>
  
  <p>Thank you in advance!</p>