This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] CCS/MSP430FR4133:计算问题

Guru**** 2587365 points


请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/803523/ccs-msp430fr4133-calculation-problem

器件型号:MSP430FR4133

工具/软件:Code Composer Studio

大家好、

我想使用 MSP430来计算温度。

但我无法获得正确的结果。

请给我一些建议。

以下是我的代码。

Percent=ADC_getResults (ADC_base)/0x3FF;
VOLT=1500.0*百分比;
温度= CalcTemp (伏、2);
showTemp (temperature);
//将 CPUOFF 位从0 (SR)清零
//这里的断点并观察 ADC_Result
_BIC_SR_REGISTER_ON_EXIT (CPUOFF);

中断;
默认值:break;
}
}

#ifdef __MSP430_has_TBX__
#if defined (__TI_Compiler_version__)|| defined (__IAR_systems_ICC__)
#pragma vector=TIMER0_B0_Vector
__interrupt
#elif defined (__GNU__)
__attribute__(((interrup)
t (TIMER0_B0_Vector))
)#endif
void TB0_ISR (void)
{
TB0CTL = 0;
LPM0_EXIT; //返回
时退出 LPM0}
#else
#if defined (__TI_Compiler_version__)|| Defined (__IAR_systems_ICC__)
#pragma vector=TIMER0_A0_Vector
__interrupt
#elif defined (__GGNU__)
__attribute__((interrupt (TIMER0_A0_Vector)#tufid

)(tufu_translifit

TA0CTL = 0;
LPM0_EXIT; //返回
时退出 LPM0}
#endif //__MSP430_HAS_TBX_double

CalcTemp (双电压、int 模式){
switch (mode){
情况1:return -0.193*VOLT+12.009;
情况2:return -0.000007857923*VOLV*VOLT-0.1777501*VOLT+204.6398;
情况3:return -8.451576E-6*VOLV*VOLT-1.769281*VOLT+204.3937;
情况4:return -1.809628E-9*VOLV*VOLVE-3.325395E-6*VOLVE-0.1814103*VOLT+205.5894;
//案例5:return -1.064200E-9*VOLT*VOLTV-5.759725E-6*VOLT*VOLT-0.1789883E*VOLT+204.8570;
}
//break;
}



void showTemp (double temperature){
如果(温度>=1)
{
if (temperature >= 100) showChar ((((uint32_t) temperature /100)%10 +"0"、pos3);
if (temperature >= 10) showChar ((((uint32_t) temperature /10)%10 +'0'、pos4);
如果(temperature >= 1) showChar ((((uint32_t) temperature /1)%10 +'0'、pos5);
}
其他
{
LCDMEM[pos1]|= 0x01;
if (temperature <=-100) showChar (((uint32_t)(400-(400+温度)))/100)%10 +"0"、pos3);
if (temperature <=-10) showChar (((uint32_t)(400-(400+温度))/10)%10 +"0"、pos4);
if (temperature <1) showChar (((uint32_t)(400-(400+temperature))/1)%10 +"0"、pos5);
}
LCDMEM[pos4+1]|= 0x01;//小数点
LCDMEM[pos5+1]|= 0x04;//度符号
showChar ('C'、pos6);
}

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    > percentage=ADC_getResults (ADC_base)/0x3FF;

    此结果将为0 (或可能为1)、因为 getResults 将返回小于1024的"int"。 尝试:

    > percentage=adc_getResults (adc_base)/1024.0;

    [编辑:我假设"percent"被声明为"double"。 如果没有、您也应该修复它。]