这个功能有什么问题?不可转让?

float tempC(unsigned int adc_value) {
    multiplier = adc_value / 1023.0f;
    tempC = -40 * multiplier * 90;
    return tempC;
}

我正在尝试使用微控制器上的 ADC 将电位计转换为 -40 到 50 摄氏度之间的温度,这adc_value是 ADC 给出的范围,但是我得到了错误:

Main.c:110:11: 错误:非对象类型 'float (unsigned int)' 不可分配

如果需要,我可以提供更多代码,但我不知道哪里出错了,因为我对 C 和编程还很陌生。

回答

tempC 不是变量而是函数,所以你不能在那里赋值。

您应该声明另一个变量,而不是像这样:

float tempC(unsigned int adc_value) {
    float tempC_ret;
    multiplier = adc_value / 1023.0f;
    tempC_ret = -40 * multiplier * 90;
    return tempC_ret;
}

或者您可以像这样直接返回计算值:

float tempC(unsigned int adc_value) {
    multiplier = adc_value / 1023.0f;
    return -40 * multiplier * 90;
}

  • The core of the main question here is addressed by your answer, but I think the conversion algorithm is bogus.

以上是这个功能有什么问题?不可转让?的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>