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

📄 secondccc

📁 ASC 信号机控制程序,国内最先进的信号机控制程序
💻
📖 第 1 页 / 共 3 页
字号:
#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,max_temp;
   uint  j;
   uint offset;
       max_time=0;
       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)) //行人
             {
              max_time=XBYTE[baseaddr_now_phasesch+j+12]+XBYTE[baseaddr_now_phasesch+j+16];
               //max_time:=最小绿灯+红灯
              }   */
             if(((XBYTE[baseaddr_now_phasesch+j+2]&0x04)!=0x04) && (now_phase_tempn==0))
             {
                 no_vehicle_step[step_counter]=1;//该阶段有无机动车标志
                 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_temp=XBYTE[baseaddr_now_phasesch+j+12]+XBYTE[baseaddr_now_phasesch+j+15]+XBYTE[baseaddr_now_phasesch+j+16];
                 if(max_temp>max_time)
                 max_time=max_temp;
                 //max_green_flash=XBYTE[baseaddr_now_phasesch+j+17];
             }

          }

       }
       //max_time=max(time);
       //max_green_flash=max(green_flash);

       return (max_time);
}
/*-----------------------------------**/
void max_clear_time()    using 1
{
   uchar now_phase_temp,i,now_phase_tempn;
   uint toto;
    uint phasek;
     max_yellow=0;
     max_red_clear=0;
     max_green_flash=0;
     for(i=0; i<16; i++)
      {

        toto = 0x0001;
        toto = toto<<i;
        phasek = 18*i;

           now_phase_temp = toto&inuse_phase[step_counter];   //当前阶段是否包含该相位
           now_phase_tempn = toto&inuse_phasen[step_counter];
         if((now_phase_temp!=0)&& (now_phase_tempn==0))
          // if(now_phase_temp!=0)
           {
             if(step_counter==1)
             step_counter=1;
             if(max_yellow<XBYTE[baseaddr_now_phasesch+phasek+15])
             max_yellow=XBYTE[baseaddr_now_phasesch+phasek+15];
             if(max_red_clear<XBYTE[baseaddr_now_phasesch+phasek+16])
             max_red_clear=XBYTE[baseaddr_now_phasesch+phasek+16];
             if(max_green_flash<XBYTE[baseaddr_now_phasesch+phasek+17])
             max_green_flash=XBYTE[baseaddr_now_phasesch+phasek+17];

           }
      }
}
/************计算个阶段的各相位的清空时间***在每阶段的开始时执行一次****************/
 void cal_clear_time()
{
   uchar i;
   uint phasek;
  for(i=0; i<16; i++)
      {

          phasek = 18*i;
          red_clear[i] = XBYTE[baseaddr_now_phasesch+phasek+16];   //红灯清空时间
          //red_yellow_clear[i] = red_clear[i]+XBYTE[baseaddr_now_phasesch+phasek+15]; //黄灯清空时间
          red_yellow_clear[i] = red_clear[i]+ max_yellow;
          red_yellow_green_clear[i] = red_yellow_clear[i]+XBYTE[baseaddr_now_phasesch+phasek+17]; //行人清空时间
      }
}
/*****************************************************************************************************/
// 查找灯色
/*****************************************************************************************************/
void  search_color()  using 1
{
    uchar  data i;
    uint data toto,toto1,j;
    
    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;      /*不用的灯组灭掉*/
    }

    cal_clear_time();//计算个阶段的清空时间
    if(sensor_step[step_counter]==0)                   //阶段为固定配时
      {

      for(i=0; i<16; i++)                             //此循环用于查找当前阶段用到的相位
       {
          j = 18*i;
          toto= 0x0001;
          toto1= toto<<i;

          now_phase_temp = toto1&inuse_phase[step_counter];   ////inuse_phase:阶段用到的相位step_counter:阶段号
          now_phase_tempn = toto1&inuse_phasen[step_counter];
          if(now_phase_temp!=0)
          {
             if(((XBYTE[baseaddr_now_phasesch+j+2]&0x04)!=0x04) && (now_phase_tempn==0))
               {
                 no_vehicle_step[step_counter]=1;//该阶段有无机动车标志
                 }
           }

         }


          if(re_control==1||force_flag==1)     //遥控 强制
    	                   {
                         /*    //手动***************************************
                             if(step_counter==hand_step-1&&hand_step_flag==1)//正在执行手动相位
                                 {
                                  hand_state=2;
                                  now_uncount =max_red_clear+max_yellow+max_green_flash+1;
                                  now_step_key=1;
                                  }
                              else if((hand_state==1||hand_state==4)&&hand_step_flag==1) //尚未执行手动相位
                              {
    	                      hand_state=2;
                               now_uncount =max_red_clear+max_yellow+max_green_flash;
                               now_step_key=1;
                               }
                              else if(hand_state==2&&hand_step_flag==1) //尚未执行遥控相位,继续走完本阶段
                              {
    	                      now_uncount =max_red_clear+max_yellow+max_green_flash-now_step_key;

                               }
                                       */
                            //遥控****************************************
                             if(reph_number==3){
                                        reph_number=3;
                                                }
                             if(step_counter==reph_number-1)//正在执行遥控相位
                                 {
                                   remote_state=2;
                                  now_uncount =max_red_clear+max_yellow+max_green_flash+1;
                                  now_step_key=1;
                                  }
                              else if(remote_state==1||remote_state==4) //尚未执行遥控相位
                              {
    	                      remote_state=2;
                               now_uncount =max_red_clear+max_yellow+max_green_flash;
                               now_step_key=1;
                               }
                              else if(remote_state==2) //尚未执行遥控相位,继续走完本阶段
                              {
                               
                               if(no_vehicle_step[step_counter]==0)//该阶段有无机动车标志
                               now_uncount =3-now_step_key;
                               else
                               now_uncount =max_red_clear+max_yellow+max_green_flash-now_step_key;

                               }
                               //remote_state=1:按下遥控按键
                               //remote_state=2:按下遥控按键后,尚未执行遥控相位,继续走本阶段时间
                               //               或正在执行遥控相位
                               //remote_state=3:按下遥控解除按键
                               //remote_state=4:按下遥控解除按键 继续走完遥控阶段时间
                              //else if(remote_state==3) //解除遥控,
                             // now_step_key=XBYTE[baseaddr_now_schemesch+8+step_counter]-now_uncount;

                            //***************强制****************************************//
                           else if(step_counter==force_number-1)//正在执行强制相位
                                 {
                                  force_state=2;
                                  now_uncount =max_red_clear+max_yellow+max_green_flash+1;
                                  now_step_key=1;
                                  }
                              else if(force_state==1||force_state==4) //尚未执行强制相位
                              {
    	                      force_state=2;
                               now_uncount =max_red_clear+max_yellow+max_green_flash;
                               now_step_key=1;
                               }
                              else if(force_state==2) //尚未执行强制相位,继续走完本阶段
                              {
    	                      now_uncount =max_red_clear+max_yellow+max_green_flash-now_step_key;

                               }
                               //remote_state=1:按下遥控按键
                               //remote_state=2:按下遥控按键后,尚未执行遥控相位,继续走本阶段时间
                               //remote_state=3:按下遥控解除按键
                               //remote_state=4:按下遥控解除按键 继续走完遥控阶段时间
                              //else if(remote_state==3) //解除遥控,
                             // now_step_key=XBYTE[baseaddr_now_schemesch+8+step_counter]-now_uncount;
    	            }

           else
           {
           if(remote_state==3) //解除遥控
                  {
                   now_step_key=XBYTE[baseaddr_now_schemesch+8+step_counter]-now_uncount;
                   remote_state=4;
                   if(reph_number>step_num&&reph_number!=12)
                   remote_state=0;
                   }
           else if(force_state==3) //解除强制
                  {
                   now_step_key=XBYTE[baseaddr_now_schemesch+8+step_counter]-now_uncount;
                   force_state=4;
                   if(force_number>step_num&&force_number!=0)
                   force_state=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];     //当前阶段用到的相位
          if(re_control==1&&step_counter!=reph_number-1)       //遥控响应尚未开始执行
                now_phase_tempn = toto&inuse_phasen[reph_number-1]; //下一阶段放行的相位
          else if(force_flag==1&&step_counter!=force_number-1) //强制响应尚未开始执行
                now_phase_tempn = toto&inuse_phasen[force_number-1];
          else
                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;

⌨️ 快捷键说明

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