中级会员
- 积分
- 222
- 金钱
- 222
- 注册时间
- 2017-4-21
- 在线时间
- 52 小时
|
10金钱
代码:
#include "stm8s.h"
#include "stm8s_adc1.h"
#include <stdio.h>
#include <string.h>
#include <math.h>
void ADC_Init(void);
int main(void)
{
float Vad = 0.0;
float Res = 0.0;
float a = 10000.0;
float b = 0.0;
float c = 0.0;
float d = 0.0;
float e = 0.0;
float Tem = 0.0;
float f = 0.0;
float g = 0.0;
float h = 0.0;
u16 Conversion_Value=0;
FlagStatus ADCRdy = RESET;
CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);
ADC_Init();
while (1)
{
do
{
ADCRdy = ADC1_GetFlagStatus(ADC1_FLAG_EOC);
}
while(ADCRdy == RESET); // SET or RESET
Conversion_Value = ADC1_GetConversionValue();
printf("Conversion_Value = %d\n",Conversion_Value);
Vad = ((float)Conversion_Value * 5.0) /1023.0;
printf("Vad = %lf\n",Vad);
Vad = Vad / 5;
f = (Vad*10000.0);
g = (1-Vad);
Res = f/g;
a = log(a);
b = log(Res);
c = (a - b)/4750.0;
d = 1.0/298.15;
e = d - c;
Tem = 1/e;
Tem = Tem - 273.15;
printf("Tem = %lf\n",Tem);
}
}
void ADC_Init(void)
{
ADC1_DeInit();
ADC1_Init(ADC1_CONVERSIONMODE_CONTINUOUS , ADC1_CHANNEL_0, ADC1_PRESSEL_FCPU_D18,\
ADC1_EXTTRIG_TIM, DISABLE, ADC1_ALIGN_RIGHT, ADC1_SCHMITTTRIG_CHANNEL0,DISABLE);
ADC1_ITConfig(ADC1_IT_EOCIE,DISABLE);
ADC1_Cmd(ENABLE);
ADC1_StartConversion();
}
|
-
编译出现问题
|