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

📄 second_bark.c

📁 最先进的信号机程序,经过很多重要场合测试通过
💻 C
📖 第 1 页 / 共 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;    //查表的阶段时间与当前历时的倒计时
            }




#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 max_clear_time()    using 1
{
   uchar now_phase_temp,i ;
   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;
         //  if(step_counter==3)
         //   g_error1=55;
           now_phase_temp = toto&inuse_phase[step_counter];   //当前阶段是否包含该相位
           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  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||force_flag==1||hand_step_flag==1)     //遥控 强制
    	             {
                            if(hand_step_flag==1)
                            reph_number=hand_step+1;
                            //遥控****************************************
                             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) //尚未执行遥控相位,继续走完本阶段
                              {
    	                      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;

⌨️ 快捷键说明

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