我现在用表中一个固定的数:ox2710,可是总是显示160度,请大家帮忙看下!
void temptest() //用二分查表法计算温度值 //25度时最大与最小差1000,相邻度数差500
//总计一度之间可以放的误差为1500
{
signed char tempmid,tempmin,tempmax;
unsigned int tempget ;
code unsigned int temptab[]= //使用了25C 100KNTC,所以原RT表*100取整后制作的此表:0---160C DIV 1C //0:32510[0x7efe]---------160:128[0x80]
{0x7efe,0x78ee,0x733b,0x6dd8,0x68bd,0x63e2,0x5f40,0x5ad4,0x5698,0x528c, //0---9C
0x4eac,0x4ad3,0x4753,0x4417,0x410f,0x3e2f,0x3b6f,0x38ca,0x363e,0x33c8, //10-19C
0x3168,0x2f20,0x2cf1,0x2add,0x28e7,0x2710,0x255b,0x23ca,0x225f,0x211b, //20-29c
0x2002,0x1ec0,0x1d85,0x1c51,0x1b23,0x19fc,0x18dd,0x17c8,0x16be,0x15bf, //30-39c
0x14ce,0x1392,0x1319,0x1258,0x11aa,0x110e,0x1061,0x0fbd,0x0f22,0x0e8f, //40-49c
0x0e04,0x0d7f,0x0d01,0x0c88,0x0c13,0x0ba3,0x0b36,0x0acd,0x0a66,0x0a01, //50-59c
0x099e,0x0945,0x08f1,0x089c,0x084c,0x07ff,0x07b5,0x076e,0x072a,0x06e9,
0x06aa,0x066f,0x0636,0x0600,0x05cc,0x059b,0x056e,0x0542,0x0517,0x04ef,
0x04c8,0x04a2,0x047d,0x0459,0x0436,0x0414,0x03f2,0x03d1,0x03b1,0x0391,
0x0371,0x0355,0x033a,0x0320,0x0308,0x02f0,0x02da,0x02c4,0x02af,0x029a,
0x0286,0x0272,0x025f,0x024b,0x0238,0x0225,0x0216,0x0207,0x01f8,0x01e9,
0x01da,0x01cc,0x01be,0x01b0,0x01a3,0x0197,0x018b,0x0180,0x0175,0x016b,
0x0162,0x0157,0x014d,0x0144,0x013c,0x0133,0x012b,0x0124,0x011d,0x0116,
0x010f,0x0108,0x0101,0x00fb,0x00f4,0x00ed,0x00e6,0x00e0,0x00d9,0x00d4,
0x00ce,0x00c9,0x00c3,0x00bf,0x00ba,0x00b6,0x00b1,0x00ae,0x00aa,0x00a6,
0x00a3,0x009e,0x009a,0x0096,0x0092,0x008f,0x008c,0x0089,0x0085,0x0082,0x007f}; //150-160 */
tempget =0x2710;//sumtemp();
tempmin = 0;
tempmax = 160;
while(1)
{
tempmid = (tempmin + tempmax)/2;
if( tempget == temptab[tempmid]) break;
else if (tempget >temptab[tempmid]) tempmax = tempmid;
else tempmin = tempmid;
if((tempmax-tempmin)<=2000)
{
if(temptab[tempmax]+temptab[tempmin]>2*tempget) tempmid = tempmax;
else tempmid = tempmin;
break;
}
}
ctemp = tempmid;
//if(ctemp<=0) display[3]=0xc0;
//else if(ctemp>=160) display[3] = 0xbf;
} |