unsigned long ref_tensao[21]={50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 210, 220, 230, 240, 250};
unsigned long ref_ad_tensao[21]={38, 55, 74, 95, 119, 144, 171, 200, 230, 262, 296, 330, 366, 404, 442, 480, 520, 558, 604, 646, 692};
float calcula_tensao(unsigned long entrada){
float tensao;
unsigned long x1, x2, y1, y2, dx, dy, temp;
unsigned char i;
if ((entrada<ref_ad_tensao[0])||(entrada>ref_ad_tensao[21])){
tensao=0;
}else{
i=0;
while(entrada>ref_ad_tensao[i+1]){
i++;
}
x2=ref_ad_tensao[i+1];
x1=ref_ad_tensao[i];
y2=ref_tensao[i+1];
y1=ref_tensao[i];
dx=x2-x1;
dy=y2-y1;
temp=(dy*(entrada-x1))+(dx*y1);
tensao=(float)temp/dx;
}
return tensao;
}
int main(){
float resultado;
resultado = calcula_tensao(20);
printf("%f",resultado);
return 0;
}