Using special SFR casts

Language reference ›› Variables ››
Parent Previous Next

When declaring a variable ABSOLUTE to an I/O SFR, the equivalent TRISx, LATx, PORTx, WPUx of the given SFR may be retrieved by special pre-processor's pseudo-cast functions that may be used only in the context of a variable declaration level.

In the definitions below <reference> may be any SFR reference of type PORTx, LATx, WPUx, TRISx, GPIO, TRISIO, GPPU, depending on the selected processor.


GET_PORT(<reference>) returns PORTx.

GET_LAT(<reference>) returns LATx. When there's no physical LATx, GET_LAT() returns the equivalent PORTx.

GET_TRIS(<reference>) returns TRISx. If there's no memory-mapped TRISx on the selected processor, a compilation error occurs.

GET_WPU(<reference>) returns WPUx. If there's no memory-mapped WPUx on the selected processor, a compilation error occurs.

For small devices, GPIO, TRISIO, GPPU are returned.



{$DEFINE BITS_PORT PORTA}
{$DEFINE BITS_ONE 5}

VAR
 Bits_In: BYTE @ GET_PORT(Defined_Value(BITS_PORT)); // Input bits on port A
 Bits_Out: BYTE @ GET_LAT(Bits_In);   // Output bits on LATA
 Bits_TRIS: BYTE @ GET_TRIS(Bits_In); // TRIS control bits on TRISA
 Bits_WPU: BYTE @ GET_WPU(Bits_In);   // Weak Pull-Ups bits on WPUA

 Bit_One: boolean @ GET_PORT(Defined_Value(BITS_PORT)).Defined_Value(BITS_ONE); // Bits PORTA.5