仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
完整代码,请下载附件!谢谢支持!!
51单片机NTC热敏电阻配合MAX6675热电偶测量温度的源程序如下:
- //2021-04-18
- #include "1602.h"
- #include "reg51.h"
- #include "MAX6675.h"
- #include "ADC1031.H"
- #include <math.h>
- //proteus仿真软件 ADC0831是8位的,测出来的温度有些偏差实属正常。
- //仿真毕竟不是真实的,如有兴趣,可自己搭电路验证。
- //NTC 10K B3950
- //检测温度0-100
- //数组下标就是对应温度
- code u8 Temp_adc[101]={
- 196, 194, 191, 189, 186, 184, 181, 179, 176, 173, 170, 168,
- 165, 162, 159, 157, 154, 151, 148, 145, 142, 139, 136, 134,
- 131, 128, 125, 122, 120, 117, 114, 112, 109, 106, 104, 101,
- 99, 96, 94, 91, 89, 87, 84, 82, 80, 78, 76, 74, 71, 70, 68, 66, 64, 62,
- 60, 59, 57, 55, 54, 52, 51, 49, 48, 47, 45, 44, 43, 41, 40, 39, 38, 37,
- 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 27, 26, 25, 24, 24, 23, 22, 22,
- 21, 21, 20, 20, 19, 18, 18, 17, 17, 16, 16};
- //查找相近值,并返回下标
- u8 Find_data(u8 *a,u8 x,u8 len)
- {
- u8 i,min,r=0;
-
- min=abs(*a-x);
- for(i=0;i<len;i++)
- {
- if(abs(a[i]-x)<min)
- {
- min=abs(a[i]-x);
- r=i;
- }
- }
-
- return r;
- }
- void Timer0_init() //50MS
- {
- TMOD=0X01;
- TH0=0X4B;
- TL0=0XFD;
- TR0=1;
- }
- void ISR_init()
- {
- EA=1;
- ET0=1;
- }
- void isr_timer0() interrupt 1
- {
- static u8 i;
- TH0=0X4B;
- TL0=0XFD;
- i++;
- if(i==6) //300ms
- {
- i=0;
- MAX6675_ReadTemper();
- }
- }
- void main()
- {
- u8 ad;
-
- LCD_init(); //LCD初始化
- Timer0_init(); //50MS
- ISR_init();
- Max6675_Init();
- while(1)
- {
- ad=read_0831();
-
- Show_string(0,0,"MAX6675=");
- show_nuber(8,0,(u16)MAX6675_Temper);
- Show_string(12,0,"C");
-
- Show_string(0,1,"10K NTC=");
- Show_string(12,1,"C");
-
- show_nuber(8,1,Find_data(Temp_adc,ad,101));
- }
- }
复制代码
Proteus仿真与代码下载:
NTC MAX6675 Proteus仿真.zip
(577.88 KB, 下载次数: 251)
|