谢谢楼上几位的回复,已经搞定这个程序了,会了就很简单了,没弄好的时候头绪都没有,下面是150度部分代码:
uint NTC_R;//定义热敏电阻阻值变量
uint temperature;//定义温度存储变量
/*-----------------------------------------*/
unsigned int code temp_oil[151][2]=
{
0,32485,
1,30871,
2,29346,
3,27937,
4,26584,
5,25303,
6,24092,
7,22945,
8,21859,
9,20830,
10,19856, //0-10
11,18932,
12,18057,
13,17227,
14,16439,
15,15692,
16,14983,
17,14310,
18,13670,
19,13063,
20,12486,
21,11938, //11-21
22,11416,
23,10920,
24,10449,
25,10000,
26,9572,
27,9166,
28,8779,
29,8410,
30,8059,
31,7724,
32,7405,
33,7101,
34,6811,
35,6534,
36,6270,
37,6018,
38,5777,
39,5547,
40,5328,
41,5118,
42,4918,
43,4727,
44,4544,
45,4369,
46,4192,
47,4030,
48,3876,
49,3729,
50,3588,
51,3453,
52,3324,
53,3200,
54,3082,
55,2969,
56,2861,
57,2757,
58,2658,
59,2562,
60,2471,
61,2383,
62,2299,
63,2219,
64,2142,
65,2067,
66,1996,
67,1928,
68,1862,
69,1799,
70,1738,
71,1680,
72,1624,
73,1570,
74,1519,
75,1469,
76,1421,
77,1375,
78,1331,
79,1288,
80,1247,
81,1208,
82,1170,
83,1134,
84,1098,
85,1064,
86,1031,
87,999,
88,969,
89,882,
90,855,
91,829,
92,805,
93,781,
94,758,
95,736,
96,714,
97,694,
98,674,
99,694,
100,674,
101,654,
102,636,
103,618,
104,600,
105,583,
106,567,
107,552,
108,536,
109,522,
110,508,
111,494,
112,481,
113,468,
114,455,
115,443,
116,432,
117,420,
118,409,
119,399,
120,388,
121,378,
122,369,
123,359,
124,350,
125,342,
126,333,
127,325,
128,317,
129,309,
130,302,
131,294,
132,288,
133,281,
134,274,
135,268,
136,262,
137,255,
138,249,
139,244,
140,238,
141,244,
142,227,
143,233,
144,217,
145,212,
146,207,
147,202,
148,198,
149,193,
150,189
};
#include "BandGap.c"//包含读单片机内部BandGap基准电压值
/*********************************************************************************************/
void T_dis(){//温度处理函数采集到的阻值与二维数组的阻值进行比较,从而获得相对应的温度值。
unsigned char i;
for(i=150;i<151;i--) {
if(NTC_R >= temp_oil[i][1]&& NTC_R < temp_oil[i-1][1]){
temperature=(temp_oil[i][0]);
if(temperature>=set_temp)IE2=0x04;
b=temperature/100;
c=temperature%100/10;
d=temperature%10;
break;
}
}
}
/*********************************************************************************************/
void main()
{
beep_error=0;
P1M0=0x41;
P1M1=0x41;
P2M0=0xff;
P2M1=0x00;
beep_error=0;
Ht1621_Init(); //上电初始化LCD
BL=0;
InitADC();
IT0=1;//中断类型(上下沿中断 )
EX0=1; //外中断0使能
PCON &= ~LVDF; //上电后需要清LVD中断标志位
ELVD = 1; //使能LVD中断
_Nop();_Nop();_Nop();_Nop();_Nop();_Nop();_Nop();_Nop();
_Nop();_Nop();_Nop();_Nop();_Nop();_Nop();_Nop();_Nop();
T2L = 0x20; //设置定时初值
T2H = 0xD1; //设置定时初值
AUXR |= 0x90; //定时器时钟1T模式 1001 0000
TMOD = 0xB0; //设置定时器模式1011 0000
TMOD &= 0xB0; //设置定时器模式1011 0000
TL0 = 0xC0; //设置定时初值
TH0 = 0x63; //设置定时初值
TF0 = 0; //清除TF0标志
ET0=0;
IT0=1;
TR0 = 1;
EA = 1;
DelayMS(2000);
set_temp=IapReadByte(0x0001);
/*********************************************************************************************/
while(1)
{
brightness_press();
ljjs++;
if(ljjs==500)
{
ljjs=0;
ljjs_flag^=1;
}
T_dis();
ShowResult();
//if(js<254)js++;
if(flash_flag)
{
s=s+500;
colour_press();
}
else s=0;
Ht1621WrAllData(0,Ht1621Tab1,10);
if(k==10){k=0;j++;}if(j==10){j=0;h++;}
if(j==6){j=0;g++;}
if(g==10){g=0;f++;}
if(f==10){f=0;e++;}
}}
void ShowResult()//uchar ch)
{ //uchar stc_ch;
uint adc_res10,//测量设定通道adc值
bandgap, //bandgap预储存校准值,单位毫伏
adc_9gallery_res; //测量第九通道(bandgap)值
float power_voltage, //系统供电电压,单位毫伏
R,ADC_voltage; //设定通道电压值,单位毫伏
uchar code *cptr; //定义ROM(代码)区指针
cptr = ID_ADDR_ROM; //从程序区读取BandGap电压值(单位:毫伏mV)
bandgap=*cptr++;
bandgap<<=8;
bandgap+=*cptr;
ADC_RES = 0; //清除结果寄存器
P1ASF = 0x41; //设置P1口为AD口 0100 0001
if(!ljjs_flag){stc_ch=0;a=1;}
else {stc_ch=6;a=2;}
GetADCResult(stc_ch);
GetADCResult(stc_ch); //读三次获得稳定
adc_res10= GetADCResult(stc_ch);
//测量第九通道(bandgap)值
ADC_RES = 0; //清除结果寄存器
P1ASF = 0x00; //设置读第九通道
GetADCResult(0); //测bandgap时,调用此函数时通道数只能填0
GetADCResult(0); //读三次获得稳定
adc_9gallery_res=GetADCResult(0);
//计算系统供电电压
power_voltage=(float)bandgap*1024/adc_9gallery_res;
//计算ADC通道测得电压值
ADC_voltage=(float)bandgap*adc_res10/adc_9gallery_res;
//R=10000*ADC_voltage/(power_voltage-ADC_voltage);
R=(power_voltage-ADC_voltage)/(ADC_voltage/10500);
NTC_R=R;//把float浮点数转化为int型
//if(ADC_voltage<2000){t_kyjonflag=0;kyjon_delay=0;}
} |