標(biāo)題: STC8A8K64S4A12單片機(jī)用10K的NTC溫度傳感電阻測(cè)溫串口發(fā)送的實(shí)驗(yàn)程序 [打印本頁(yè)]

作者: liuqing    時(shí)間: 2021-2-6 22:18
標(biāo)題: STC8A8K64S4A12單片機(jī)用10K的NTC溫度傳感電阻測(cè)溫串口發(fā)送的實(shí)驗(yàn)程序
STC8A8K64S4A12用10K的NTC溫度傳感電阻測(cè)溫串口發(fā)送的實(shí)驗(yàn)。
只為驗(yàn)證這種方法的可行性?梢猿晒y(cè)量正確溫度。
用單片機(jī)5V作為基準(zhǔn)電壓,NTC上拉10K的電阻。
有興趣的朋友可以看看,幫完善一下。最好能測(cè)8路溫度,
業(yè)余新手的試驗(yàn)

單片機(jī)源程序如下:
  1. #include "stc8.h"
  2. #include "uart.h"
  3. #include "adc.h"
  4. #include <stdio.h>
  5. #include <math.h>


  6. const float Rp=10000.0;                 //10K,25度時(shí)的阻值         
  7. const float T2 = (273.15+25.0);   //T2,25度時(shí)的開(kāi)爾文溫度
  8. const float Bx = 3950.0;                //B值
  9. const float Ka = 273.15;        //開(kāi)爾文溫度

  10. float Get_Temp(float Rt)
  11. {

  12.         float temp;

  13.                                 //like this R=10000, T2=273.15+25,B=3470, RT=10000*EXP(3470*(1/temp-1/(273.15+25)),  
  14. //        temp = Rt/Rp;
  15. //        temp = log(temp);                //ln(Rt/Rp)
  16.         
  17. //        temp/=Bx;                          //ln(Rt/Rp)/B
  18.         //temp+=(1/T2);
  19. //        temp = 1/(temp);
  20. //        temp-=Ka;
  21.         temp=1/(log(Rt/Rp)/Bx+(1/T2))-Ka;
  22.         return temp;
  23. }

  24. void printstar(void)
  25. {
  26.         printf("*************************\n");
  27. }

  28. void print_message(void)
  29. {
  30.         printf("hello world\n");
  31.         printf("how do you do!\n");
  32.         printf("歡迎學(xué)習(xí)STC8A8K單片機(jī)\n");
  33. }


  34. void main(void)
  35. {
  36.         float t,r,vol;
  37.         P1M0=0X00;P1M1=0XFF;
  38.         Uart1_Init() ;
  39.         adc_init();
  40.         
  41.         while(1)
  42.         {
  43.         
  44.            if(P20==0)
  45.            {
  46.                   

  47.                         print_message();
  48.                         printstar();
  49.                         vol=((float)adc_read()/4096)*5;
  50.                         r=vol/((5-vol)/10000);
  51.                
  52.                          t=Get_Temp(r);
  53.                         printf("ADC %.2f", t) ;
  54.                 }
  55.         }

  56. }
復(fù)制代碼

全部程序51hei下載地址:
NTC傳感器測(cè)溫.rar (35.1 KB, 下載次數(shù): 134)






歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1