STC8A8K64S4A12用10K的NTC温度传感电阻测温串口发送的实验。
只为验证这种方法的可行性。可以成功测量正确温度。
用单片机5V作为基准电压,NTC上拉10K的电阻。
有兴趣的朋友可以看看,帮完善一下。最好能测8路温度,
业余新手的试验
单片机源程序如下:
- #include "stc8.h"
- #include "uart.h"
- #include "adc.h"
- #include <stdio.h>
- #include <math.h>
- const float Rp=10000.0; //10K,25度时的阻值
- const float T2 = (273.15+25.0); //T2,25度时的开尔文温度
- const float Bx = 3950.0; //B值
- const float Ka = 273.15; //开尔文温度
- float Get_Temp(float Rt)
- {
- float temp;
- //like this R=10000, T2=273.15+25,B=3470, RT=10000*EXP(3470*(1/temp-1/(273.15+25)),
- // temp = Rt/Rp;
- // temp = log(temp); //ln(Rt/Rp)
-
- // temp/=Bx; //ln(Rt/Rp)/B
- //temp+=(1/T2);
- // temp = 1/(temp);
- // temp-=Ka;
- temp=1/(log(Rt/Rp)/Bx+(1/T2))-Ka;
- return temp;
- }
- void printstar(void)
- {
- printf("*************************\n");
- }
- void print_message(void)
- {
- printf("hello world\n");
- printf("how do you do!\n");
- printf("欢迎学习STC8A8K单片机\n");
- }
- void main(void)
- {
- float t,r,vol;
- P1M0=0X00;P1M1=0XFF;
- Uart1_Init() ;
- adc_init();
-
- while(1)
- {
-
- if(P20==0)
- {
-
- print_message();
- printstar();
- vol=((float)adc_read()/4096)*5;
- r=vol/((5-vol)/10000);
-
- t=Get_Temp(r);
- printf("ADC %.2f", t) ;
- }
- }
- }
复制代码
全部程序51hei下载地址:
NTC传感器测温.rar
(35.1 KB, 下载次数: 134)
|