利用AD采集获取外部温度传感器的值

 1 #include "led.h"
 2 #include "delay.h"
 3 #include "key.h"
 4 #include "sys.h"
 5 #include "lcd.h"
 6 #include "usart.h"     
 7 #include "adc.h"
 8 #include "stdio.h"    
 9  
10  
11  int main(void)
12  {     
13     
14   u16 adcx,adcy,adcz;
15     float temperature;
16     delay_init();            
17     NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
18     uart_init(115200);        
19      LED_Init();               
20      Adc_Init();                 
21     while(1)
22     {
23         temperature=Get_Adc_Average(ADC_Channel_15,1);
24 
25         printf("\r\nAD值:%f\r\n\r\n",temperature);
26         //LCD_ShowxNum(156,130,adcx,4,16,0);
27         temperature=(float)temperature*(3.3/4096)+0.05;//这个0.05可能是因为之前单片机上一直显示这个电压值,当除去
      //那两个电阻时,结果电压却少了0.05,因此就加上了0.05了 28 29 printf("\r\n电压值:%f\r\n\r\n",temperature); 30 temperature=(1.43-temperature)/0.0043+25; 31 adcx=temperature; 32 printf("\r\n温度值:%d\r\n\r\n",adcx); 33 //LCD_ShowxNum(156,150,adcx,1,16,0);34 //temp-=adcx; 35 //temp*=1000; 36 //LCD_ShowxNum(172,150,temp,3,16,0X80); 37 LED2=!LED2; 38 delay_ms(1000); 39 } 40 } 41 42

最后的结果为:

在对着NTC温度表示,你会感到诧异,我现在在的环境是室内。对照表结果只有AD值比较符合现在的环境温度。

可能是我上面的计算温度出了问题。然后我百度查了下说非线性的是不能通过计算得到结果的,因此只能查表了。

但对于AD值和电压值是没有错的,不过温度传感器的电阻怎么变化,电压值都能对应得上。对于配置ADC就不用

多说吧。不懂得话可以多看下有关ADC的资料。

posted on 2017-08-09 10:01  zengsf  阅读(2224)  评论(0编辑  收藏  举报

导航