| 部分程序: uchar code table[]={数码管段码}
 uint Sample;ADC采样值
 int temp=0;//温度值
 uint code T_Value[400]={400,..............................................................,
 ....................................................................1};
 /************温度转换************/
 void Temp_ack(void)
 {
 uint L,H,M;
 uchar i;
 L=0;//对分查表最小值25度
 H=400;//对分查表最大值400
 for(i=0;i=5;i++)
 {
 M=(L+H)/2;
 if(Sample<=T_Value[M])
 L=M-1;
 else
 H=M+1;
 }
 if(Sample==T_Value[L])
 {
 temp=L-5;//索引差值
 }
 else
 if(Sample=T_Value[H])
 {
 temp=H-5;
 }
 else
 {
 while(L<=H)
 {
 L++;
 if(Sample<=T_Value[L]&&Sample>T_Value[L+1])
 {
 temp=L-5;
 break;
 }
 }
 }
 //小数线性插补放大10倍小数就不用了
 }
 |