zoukankan      html  css  js  c++  java
  • 利用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("
    AD值:%f
    
    ",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(" 电压值:%f ",temperature); 30 temperature=(1.43-temperature)/0.0043+25; 31 adcx=temperature; 32 printf(" 温度值:%d ",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的资料。

  • 相关阅读:
    Asp.net的核心对象
    webform在页面生成的代码与事件回传
    计算机专业课程
    代替iframe的方法
    js中斜杠转义
    Uncaught Error: Syntax error, unrecognized expression: |117的js错误
    vs调试时报503错误
    Md5加密方法
    ps批量修改图片
    “Parsing filters unsupported” error during extraction of RAR file
  • 原文地址:https://www.cnblogs.com/zengsf/p/7323681.html
Copyright © 2011-2022 走看看