⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 second.c.bak

📁 最先进的信号机程序,经过很多重要场合测试通过
💻 BAK
📖 第 1 页 / 共 4 页
字号:
#include <second.h>
/*****************************************************************************************************/
// 读时间
/*****************************************************************************************************/

void read_time()  {

    now_day = XBYTE[0XC006]; /*星期*/
    now_year= XBYTE[0XC009]; /*年份*/
    now_month=XBYTE[0XC008]; /*月份*/
    now_date= XBYTE[0XC007]; /*日子*/
    now_hour= XBYTE[0XC004]; /*小时*/
    now_min = XBYTE[0XC002]; /*分钟*/
    now_sec = XBYTE[0XC000]; /*秒*/

    now_time=now_hour*60+now_min;
    if(end_time<begin_time)
    {
       if((now_time>=begin_time) || (now_time<end_time))
          work_time=1;
       else
          work_time=0;
    }
    else if(end_time>begin_time)
    {
       if((now_time>=begin_time) && (now_time<end_time))
          work_time=1;
       else
          work_time=0;
    }
    else
       work_time=0;

}
/*------------求最大值-----------------------*/
max(array_time)
uchar   array_time[16];
{

 uchar max_value,k;
 max_value=array_time[0];
 for(k=1;k<16;k++)
    {
     if(array_time[k]>max_value)
     max_value=array_time[k];
     }
     return(max_value);
}

 /*------------------------------------------*/
uchar search_step_time()  using 1         //计算感应控制阶段时间=最小绿灯+红灯+黄灯
{
   uchar i,max_time;
   uint  j;
   uint offset;
   //uchar  time[16];
   //uchar   green_flash[16];
       ensensor_flag = 1;
       sensor_car_flag= 0;
       sensor_counter = 0;                //感应控制阶段开始设为0
       for(i=0; i<16; i++)                             //此循环用于查找当前阶段用到的相位
       {
          j = 18*i;
          offset= 0x0001;
          offset= offset<<i;

          now_phase_temp = offset&inuse_phase[step_counter];   ////inuse_phase:阶段用到的相位step_counter:阶段号
          now_phase_tempn = offset&inuse_phasen[step_counter];
          if(now_phase_temp!=0)
          {
             if(((XBYTE[baseaddr_now_phasesch+j+2]&0x04)!=0x04) && (now_phase_tempn==0))
             {
                 sensor_distance=XBYTE[baseaddr_now_phasesch+j+11];
                 min_greentime = XBYTE[baseaddr_now_phasesch+j+12]-XBYTE[baseaddr_now_phasesch+j+17]-sensor_distance;
                  //  min_greentime =最小绿灯-绿闪-单位步长
                 max_greentime = XBYTE[baseaddr_now_phasesch+j+13]-XBYTE[baseaddr_now_phasesch+j+17];
           //green_flash[i]= XBYTE[baseaddr_now_phasesch+j+17];//绿闪时间
                 //min_greentime = sensor_distance;//XBYTE[baseaddr_now_phasesch+j+12]-XBYTE[baseaddr_now_phasesch+j+17]-sensor_distance;
                // max_greentime = XBYTE[baseaddr_now_phasesch+j+13];//;-XBYTE[baseaddr_now_phasesch+j+17];
               //  add_greentime = min_greentime;
           //time[i] = XBYTE[baseaddr_now_phasesch+j+12]+XBYTE[baseaddr_now_phasesch+j+15]+XBYTE[baseaddr_now_phasesch+j+16];
                 //time:=最小绿灯+黄灯+红灯
                 max_time=XBYTE[baseaddr_now_phasesch+j+12]+XBYTE[baseaddr_now_phasesch+j+15]+XBYTE[baseaddr_now_phasesch+j+16];
                 max_green_flash=XBYTE[baseaddr_now_phasesch+j+17];
             }

          }
        /* else
           {
           time[i]=0;
           green_flash[i]=0;
           }    */
       }
       //max_time=max(time);
       //max_green_flash=max(green_flash);
       return (max_time);
}


/*****************************************************************************************************/
// 查找灯色
/*****************************************************************************************************/
void  search_color()  using 1
{
    uchar  data i,j;
    uint data toto,toto1;


    for(i=0; i<16; i++)
    {
        toto = 0x0001;
        toto = toto<<i;
        if((use_lamp&toto)==toto)  lamp_state[i]=4;      /*使用的灯组置成红色先*/
        else                       lamp_state[i]=7;      /*不用的灯组灭掉*/
    }

    if(sensor_step[step_counter]==0)                   //阶段为固定配时
    {  
    	 if(re_control==1&&remote_star==1)
    	                   {
    	                  now_uncount = max_yellow+max_red_clear; 
    	                  remote_star==0;
    	                    }
    	 else     	
          now_uncount = XBYTE[baseaddr_now_schemesch+8+step_counter]-now_step_key;    //查表的阶段时间与当前历时的倒计时
       for(i=0; i<16; i++)                             //此循环用于查找当前阶段用到的相位
       {
          toto = 0x0001;
          toto = toto<<i;

          now_phase_temp = toto&inuse_phase[step_counter];
          now_phase_tempn = toto&inuse_phasen[step_counter];
          if(now_phase_temp!=0)
          {
             now_lamp_temp = XBYTE[baseaddr_now_phasesch+18*i];
             now_lamp_temp = now_lamp_temp<<8;
             now_lamp = now_lamp_temp|XBYTE[baseaddr_now_phasesch+18*i+1];
             if(now_uncount>red_yellow_green_clear[i])    //当前倒计时处于绿灯时间范围内
            // step_uncount[4][16]:当前阶段的剩余时间累计,全红时间,黄灯时间,绿闪时间,绿灯时间
             {
                now_phase_status = now_phase_status|now_phase_temp;
                if((XBYTE[baseaddr_now_phasesch+18*i+2]&0x04)!=0x04)  //判断相位的基本属性,
                {
                    now_step_uncount = now_uncount-red_yellow_clear[i];   //非行人相位   不是行人相位
                }    //当前绿灯的倒计时
                for(j=0; j<16; j++)                   //此循环用于查找当前相位用到的灯组
                {
                   toto1 = 0x0001;
                   toto1 = toto1<<j;
                   inuse_lamp_temp =  toto1&now_lamp;
                   if(inuse_lamp_temp!=0)
                   {
                       lamp_state[j]=1;   /*当前阶段用的灯组置成绿色*/
                   }
                }

             }
             else if(now_uncount>red_yellow_clear[i])
             {
                if((XBYTE[baseaddr_now_phasesch+18*i+2]&0x04)!=0x04)
                {
                    now_step_uncount = now_uncount-red_yellow_clear[i];
                }
                for(j=0; j<16; j++)
                {
                   toto1 = 0x0001;
                   toto1 = toto1<<j;
                   inuse_lamp_temp =  toto1&now_lamp;
                   if(inuse_lamp_temp!=0)
                   {
                       lamp_state[j]=2;         /*当前阶段用的灯组置成绿闪*/
                       if(now_phase_tempn!=0)
                          lamp_state[j]=1;      /*下一阶段用的灯组仍置成绿色*/
                   }
                }
             }
             else if(now_uncount>red_clear[i])
             {
                if(now_phase_tempn==0)
                   now_phase_status = now_phase_status&(~now_phase_temp);
                if((XBYTE[baseaddr_now_phasesch+18*i+2]&0x04)!=0x04)
                {
                    now_step_uncount = now_uncount;
                    //now_uncount:当前阶段的倒计时 now_step_uncount:当前绿灯的倒计时
                }
                for(j=0; j<16; j++)
                {
                   toto1 = 0x0001;
                   toto1 = toto1<<j;
                   inuse_lamp_temp =  toto1&now_lamp;
                   if(inuse_lamp_temp!=0)
                   {
                       if(now_uncount>red_clear[i])
                       {
                           lamp_state[j]=3;         /*当前阶段用的灯组置成黄色*/
                           if((XBYTE[baseaddr_now_phasesch+18*i+2]&0x04)==0x04)
                             lamp_state[j]=4;       /*灯组是行人灯组,在黄灯期间置红色*/
                       }
                       if(now_phase_tempn!=0)
                          lamp_state[j]=1;          /*下一阶段用的灯组仍置成绿色*/
                   }
                }
             }

          }
       }
    }
    else if(sensor_step[step_counter]==1)              //阶段为感应配时
    {
        if(step_counter==2)
        step_counter=2;
        if(sensor_virgin_flag)
        {
           sensor_virgin_flag = 0;
           step_time = search_step_time();             //阶段时间在开始时只加载一次=最小绿灯+红灯+黄灯
        }
        if(re_control==1&&remote_star==1)
    	                   {
    	                  now_uncount = max_yellow+max_red_clear; 
    	                  remote_star==0;
    	                    }
    	  else  
        now_uncount = step_time-now_step_key;      //阶段倒计时
        for(i=0; i<16; i++)                            //此循环用于查找当前阶段用到的相位
        {
           toto = 0x0001;
           toto = toto<<i;

           now_phase_temp = toto&inuse_phase[step_counter];   //当前阶段是否包含该相位
           now_phase_tempn = toto&inuse_phasen[step_counter];

           if(now_phase_temp!=0)                        //
           {
              now_lamp_temp = XBYTE[baseaddr_now_phasesch+18*i];
              now_lamp_temp = now_lamp_temp<<8;
              now_lamp = now_lamp_temp|XBYTE[baseaddr_now_phasesch+18*i+1];
             if(now_uncount>red_yellow_green_clear[i])  //当前倒计时处于绿灯时间范围内
              {
                now_phase_status = now_phase_status|now_phase_temp;
               // if((XBYTE[baseaddr_now_phasesch+18*i+2]&0x04)!=0x04)
               // {
                    now_step_uncount = now_uncount-red_yellow_clear[i]; //绿灯倒计时=阶段倒计时-全红时间-黄灯时间
              //  }
                if((ensensor_flag) /*&& ((XBYTE[baseaddr_now_phasesch+18*i+2]&0x04)!=0x04)*/ && (now_phase_tempn==0))
                {
                  /* if(now_step_key<=min_greentime)      //剩余时间大于单位步长
                   //if(now_uncount>sensor_distance)
                     {
                        sensor_car_flag = 1;
                        sensor_counter++;
                        if(sensor_counter>=sensor_distance)
                        {
                             ensensor_flag = 0;
                             sensor_car_flag = 0;
                        }
                     }   */
                     //if(now_step_key>min_greentime)   //min_greentime =最小绿灯-绿闪-单位步长
                     //if(now_uncount<=sensor_distance)
                     //max_green_flash=max_green_flash_cacu();
                     if(now_step_key<(step_time-max_green_flash-sensor_distance))
                          {
                             //ensensor_flag = 0;
                             sensor_car_flag = 0;
                           }

                     if(now_step_key<(step_time-max_green_flash)&&now_step_key>=(step_time-max_green_flash-sensor_distance))
                     {
                         sensor_car_flag=1;
                         if(step_counter==2)
                        step_counter=2;
                         if(carnumber!=lastcarnumber)
                         {
                             add_greentime =now_step_key+sensor_distance;
                             //now_uncount=now_uncount+sensor_distance;
                             if(add_greentime>=max_greentime)
                             {
                                ensensor_flag = 0;
                                sensor_car_flag = 0;
                                add_greentime = max_greentime;
                                //now_uncount=now_uncount+(add_greentime-max_greentime);
                             }
                             step_time = add_greentime+XBYTE[baseaddr_now_phasesch+18*i+15]+XBYTE[baseaddr_now_phasesch+18*i+16]+XBYTE[baseaddr_now_phasesch+18*i+17];

                             sensor_counter = 1;
                             lastcarnumber = carnumber;
                         }
                     /*    else
                         {
                            sensor_counter++;
                            if(sensor_counter>=sensor_distance)
                            {
                                ensensor_flag = 0;
                                sensor_car_flag = 0;
                            }
                         }      */

                     }
                }
                for(j=0; j<16; j++)                   //此循环用于查找当前相位用到的灯组
                {
                   toto1 = 0x0001;
                   toto1 = toto1<<j;
                   inuse_lamp_temp =  toto1&now_lamp;
                   if(inuse_lamp_temp!=0)
                   {
                       lamp_state[j]=1;          /*当前阶段用的灯组置成绿色*/
                   }
                }
              }
              else if(now_uncount>red_yellow_clear[i]) //当前倒计时处于绿闪时间范围内
              {
                if((XBYTE[baseaddr_now_phasesch+18*i+2]&0x04)!=0x04)
                {
                    now_step_uncount = now_uncount-red_yellow_clear[i];    //当前阶段的倒计时

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -