Frequently Asked Questions

How can I pass a variable to functions like OUTPUT_HIGH()?

Using the Version 5 and up compilers, the I/O functions accept a variable. For older compiler versions, use the following techniques:

switch(pin_to_use) { 
   case PIN_B3 : output_high(PIN_B3); break; 
   case PIN_B4 : output_high(PIN_B4); break; 
   case PIN_B5 : output_high(PIN_B5); break; 
   case PIN_A1 : output_high(PIN_A1); break; 

If you need to use any pin on a port use:

#byte portb = 6 
#byte portb_tris = 0x86 // **
portb_tris &= ~(1<<bit_to_use); // **
portb |= (1<<bit_to_use); // bit_to_use is 0-7

If you need to use any pin on any port use:

*(pin_to_use/8|0x80) &= ~(1<<(pin_to_use&7)); // **

*(pin_to_use/8) |= (1<<(pin_to_use&7));

In all cases pin_to_use is the normal PIN_A0... defines.

** These lines are only required if you need to change the direction register (TRIS).