24小时热门版块排行榜    

查看: 301  |  回复: 0

48676678

银虫 (小有名气)

[求助] 谁帮忙解释下这段话

#include <ADC.h>
#include <MEGA16.h>
#include <Sys_Init.h>
#include <led_display.h>
#include <AD5310.h>
/****************************************************
** 函数名称: ADC采样函数
** 函数描述: 采样第0通道信号,采样分辨率256
** 输入参数: 无
** 输出参数: 无
*****************************************************/

float TEMP_Table[100] =
{
    0.243,0.286,0.329,0.372,0.415,0.458,0.501,0.544,0.587,0.63,
    0.673,0.716,0.759,0.802,0.845,0.888,0.931,0.974,1.017,1.06,
    1.103,1.146,1.189,1.232,1.275,1.318,1.361,1.404,1.447,1.49,
    1.533,1.576,1.619,1.662,1.705,1.748,1.791,1.834,1.877,1.92,
    1.963,2.006,2.049,2.092,2.135,2.178,2.221,2.264,2.307,2.35,
    2.393,2.436,2.479,2.522,2.565,2.608,2.651,2.694,2.737,2.78,
    2.823,2.866,2.909,2.952,2.995,3.038,3.081,3.124,3.167,3.21,
    3.253,3.296,3.339,3.382,3.425,3.468,3.511,3.554,3.597,3.64,
    3.683,3.726,3.769,3.812,3.855,3.898,3.941,3.984,4.027,4.07,
    4.113,4.156,4.199,4.242,4.285,4.328,4.371,4.414,4.457,4.5
};  //  1-100

uint Vol_Table[100] =
{
    575,577,579,581,583,585,587,589,591,593,
    595,597,599,601,603,605,607,609,611,613,
    615,617,619,621,623,625,627,629,631,633,
    635,637,639,641,643,647,649,651,653,655,
    657,660,663,666,669,672,675,677,680,683,
    685,687,690,693,696,699,702,705,708,711,
    713,717,720,723,726,729,732,735,738,741,
    744,747,750,753,756,759,762,765,768,771,
    774,776,778,780,782,784,786,788,790,792,
    794,797,800,803,806,809,812,815,818,821
};

volatile float ADC_temp_Value = 0; //AD转换中间变量;
volatile uchar ADC_Flag = 1;
volatile uint Temp_Tested_Counter = 0;
volatile uchar Sys_Error_Flag = 0;
volatile uchar Sys_Check_Flag = 1;
extern volatile uchar Buz_three_flag;
extern volatile uchar Voltage_Up_Flag;
void ADC_Convert()
{
   uchar i = 0;
   uchar break_flag = 1;
   uint temp = 0;
   ADC_temp_Value = 0;
   while( i < 3 )//连续ADC变换3次,取最后一次的结果;
   {
    i++;
    if( ADC_Flag )
    {
     ADMUX = 0x67;            /*基准AVCC、左对齐、通道7*/
     ADCSRA = 0xC5;            /*使能、开启、4分频*/

     while(!(ADCSRA & (1 << ADIF)));    /*等待*/

     ADC_temp_Value = ADCH;

     ADCSRA &= ~(1 << ADIF);     /*清标志*/
     ADCSRA &= ~(1 << ADEN);                /*关闭转换*/
    }
   }

   //ADC_temp_Value = (ADC_temp_Value / 255) * 5;
     ADC_temp_Value /= 51;
   if( Sys_Check_Flag )
   {
     if( ADC_temp_Value > TEMP_Table[0] )
     {
      Sys_Error_Flag = 1;
      LED_ERR_ON;
      LED_Out_OFF;
     }
     else
     {
      Sys_Error_Flag = 0;
      LED_ERR_OFF;
      LED_Out_ON;
      Sys_Check_Flag = 0;
     }
   }
   else
   {
     if( ADC_temp_Value < TEMP_Table[0] )
     {
        LED_Out_OFF;
     }
     else
     {
        LED_Out_ON;
     }
   }

   if(( ADC_temp_Value > 0.242 ) && ( ADC_temp_Value < 6 ))
   {
    while(( ADC_temp_Value > TEMP_Table[Temp_Tested_Counter] ) &&  break_flag )
    {
      if( Temp_Tested_Counter < 100 )
      {
       Temp_Tested_Counter++;
        if( Temp_Tested_Counter == 99 )
        {
           break_flag = 0;
        }
      }
    }

    temp = Vol_Table[ Temp_Tested_Counter ];
    //temp =  Temp_Tested_Counter * 10;
    Temp_Tested_Counter = 0;
    if( Sys_Error_Flag )
    {
     DA_Output( 0 );
     Voltage_Up_Flag = 0;
    }
    else
    {
     DA_Output( temp );
     Voltage_Up_Flag = 1;
    }

   }
   else
   {
    if(( ADC_temp_Value < 0.242 ) || ( ADC_temp_Value == 0.242 ))
    {
     DA_Output( 0 );
     Voltage_Up_Flag = 0;
    }
   }
}
回复此楼

» 猜你喜欢

哈哈每一天
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

智能机器人

Robot (super robot)

我们都爱小木虫

找到一些相关的精华帖子,希望有用哦~

科研从小木虫开始,人人为我,我为人人
相关版块跳转 我要订阅楼主 48676678 的主题更新
信息提示
请填处理意见