"Inc-东莞"给大家贡献的NTC查表算法源代码。
Inc-东莞:给大家贡献我的NTC查表算法:
uint8_t Libraryserch(const uint16_t *pNTCBuf, uint8_t len, uint16_t key)
{
uint8_t high = len;
uint8_t low = 0;
uint8_t middle;
if( key < *(pNTCBuf+high)) //如果小于最小值,报错
{
return NTC_ERROR_MINER_CODE;
}
else if ( key > *(pNTCBuf+low) )//大于最大值,报错
{
return NTC_ERROR_BINGER_CODE;
}
else
{
for( middle = len/2; ( high - low)!=1; )
{
if( key > *(pNTCBuf+middle) )//前半段
{
high = middle;
middle /= 2;
}
else if( key < *(pNTCBuf+middle) )//后半段
{
low = middle;
middle = (low + high)/2;
}
else
{
return middle;
}
}
//4舍5入
if( (*(pNTCBuf+low)-key)>=(key-*(pNTCBuf+high)) )
{
return low;
}
else
{
return high;
}
}
}
大神手笔{:soso_e179:}
页:
[1]