'using a port as a variable in pic microcontroller

I using PIC18f45k22 and I am trying to make a thermocouple library. This library requires LATCH to be assigned as a parameter variable. This is the created code.

#define B4_LATCH LATB4
unsigned short Thermo1;

unsigned short thermal (unsigned char* Latch) {
unsigned short thermocouple;
    Latch = 0;
    thermocouple  = spiRead(0)<<8; //Read first byte
    thermocouple |= spiRead(0); //add second byte with first one
    thermocouple  = (thermocouple>>4)*0.5;
    Latch = 1;
return thermocouple;
}

void main (){
 while (1){
thermo1 = thermal (B4_LATCH);
printf ("%u" , thermo1);
}

However, I have used the same code without using it in a function and it worked.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source