Tengo un sensor de temperatura múltiple conectado al microcontrolador PIC16F887. ¿Cómo puedo asignar un solo PIN a una variable? ¿Es posible?
unsigned char Check, T_byte1, T_byte2, RH_byte1, RH_byte2, Ch1;
unsigned Temp, RH, Sum;
unsigned int Temperature, Humidity;
unsigned char TH;
void SelectSensor(int sensor){
if(sensor == 1)
TH = RA0;
else if(sensor == 2)
TH = RA1;
else
TH = RA2;
}
void StartSignal()
{
TH = 0;
__delay_ms(18);
TH = 1;
__delay_us(30);
}
void CheckResponse()
{
Check = 0;
__delay_us(40);
if (TH == 0)
{
__delay_us(80);//80
if (TH == 1){
Check = 1;
}
__delay_us(40);
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
char ReadData(){
char i=0, j;
for(j = 0; j < 8; j++){
while(!TH ); //Wait until TH1 goes HIGH
__delay_us(30);
if(TH == 0)
i&= ~(1<<(7 - j)); //Clear bit (7-b)
else {
i|= (1 << (7 - j)); //Set bit (7-b)
while(TH1); //Wait until TH1 goes LOW
}
}
return i;
}
void calculateSignal(){
StartSignal();
CheckResponse();
if(Check == 1){
RH_byte1 = ReadData();
RH_byte2 = ReadData();
T_byte1 = ReadData();
T_byte2 = ReadData();
Sum = ReadData();
if(Sum == ((RH_byte1+RH_byte2+T_byte1+T_byte2) & 0XFF)){
Temp = T_byte1;
Temp = (Temp << 8) | T_byte2;
RH = RH_byte1;
RH = (RH << 8) | RH_byte2;
if (Temp > 0X8000){
Temp = Temp & 0X7FFF;
}
Temperature = Temp;
Humidity = RH;
}
else{
//lcd_clear();
//printf("ceksum error");
}
}
else {
//printf("no response");;
}
}
int getTemp(){
return Temperature;
}
int getHumid(){
return Humidity;
}