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

📄 second.c

📁 ASC 信号机控制程序,国内最先进的信号机控制程序
💻 C
📖 第 1 页 / 共 3 页
字号:
#include <second.h>

unsigned char xdata cmd;

/*遥控处理函数*/
remote_deal()
{
   unsigned char i;
   for(i=0;i<8;i++){    /*确认当前被遥控的相位数*/
   if(re_message[i]==20){
                         reph_number=(i+1);
                         //remote_state=1;
                         }
                 }
   for(i=8;i<12;i++){    /*确认当前被遥控的相位数*/
   if(re_message[i]==20){
                         reph_number=(i+1);
                         }
                     }
  if((reph_number>0)&&(reph_number<9)){
      re_coloc++;
      if(re_coloc>100)re_coloc=100;
      if(re_coloc==1)re_exe_flag=1;   //一旦有合法遥控输入即建立遥控动作执行标志
      re_control=1;                   //遥控状态标志
      forceacting=0;                  //清除强制启动开始标志
      if(lastreph!=reph_number){      //遥控的相位和上一次遥控的相位不相等
             re_coloc=0;
             clear_state=1;
             lastreph=reph_number;
             act_flag=1;
             re_keep_flag=0;          //遥控阶段维持标志清,遥控进入指定阶段后该标志1,有新的遥控输入0
                                }else {
                                      act_flag=0;
                                      }
                                       }else{
                                              re_control=0;
                                              act_flag=0;

                                              }
   if((reph_number>step_num)||(reph_number==12)){//退出遥控进入自动
                                                 re_control=0;
                                                 re_coloc=0;
                                               //  XBYTE[0X6D28]=0;//手动标志一并归零
                                                 }
   lastreph=reph_number;
}
/***************************************************/
//手动处理函数
man_deal()
{
   if(force_flag==1){              //6d28单元中字节内容不为0
             re_control=0;      //清除遥控标志
             re_coloc=0;
             force_coloc++;
             if(force_coloc>100)force_coloc=100;
             if(force_coloc==1)force_exe_flag=1;
             if(force_number!=last_forcenumber){
                 forceacting=1;   //强制过程开始标志 到运行到指定阶段或遥控操作中断
                 act_force=1;     //进入强制第一秒标志
                 re_keep_force=0;
                 force_coloc=0;

                                                }
                 }
   if((force_number>step_num)||(force_flag==4)){//退出遥控进入自动
                                                 force_flag=0;
                                                 force_coloc=0;
                                                 XBYTE[0X6D28]=0;//手动标志一并归零
                                                 }
   last_forcenumber=force_number;
}

/*****************************************************************************************************/
// 读时间
/*****************************************************************************************************/

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;    //当前时间以分钟计算
    begin_time=XBYTE[0X72E2]*60+XBYTE[0X72E3];
    end_time=XBYTE[0X72E4]*60+XBYTE[0X72E5];
    if((now_time==begin_time)&&(now_sec==0)){
                                             start_counter=0;
                                             }
    if(end_time<begin_time)    //时段开始的时间晚于时段结束的时间,即5点开始,第二天4点关机
    {
       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=1;

     if((now_hour==0x17)&&(now_min==0x3b)&&(now_sec==0x3B))start_counter=5;
}
/*------------求最大值-----------------------*/
//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_temp;
   uint  j;
   uint offset;
       mmax_timed=0;
       ensensor_flag = 1;
       sensor_car_flag= 0;
       min_greentime=0;
       max_greentime = 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_green = XBYTE[baseaddr_now_phasesch+j+12]-XBYTE[baseaddr_now_phasesch+j+17];//;-sensor_distance;
                 if(min_green>min_greentime)min_greentime =min_green;
                 //  min_greentime =最小绿灯-绿闪-单位步长
                 //最大绿灯
                 max_green= XBYTE[baseaddr_now_phasesch+j+13]-XBYTE[baseaddr_now_phasesch+j+17];
                 if(max_green>max_greentime)max_greentime =  max_green;
                 //查找出最小绿灯中最长的绿灯时间
                 max_temp=XBYTE[baseaddr_now_phasesch+j+12]+XBYTE[baseaddr_now_phasesch+j+15]+XBYTE[baseaddr_now_phasesch+j+16];
                 if(max_temp>mmax_timed)mmax_timed=max_temp;
                 //max_green_flash=XBYTE[baseaddr_now_phasesch+j+17];
             }

          }

       }

       return (mmax_timed);
}
/*-----------------------------------*/
void max_clear_time()    using 1
{
   uchar i;
   uint now_phase_temp,now_phase_tempn;
   uint toto;
    uint phasek;
     max_yellow=0;
     max_red_clear=0;
     max_green_flash=0;
     if(step_counter==0x01){
              max_yellow=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(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];

         }
      }
      clear_time=max_yellow+max_red_clear;//红灯和黄灯的清空时间
}
/************计算个阶段的各相位的清空时间***在每阶段的开始时执行一次****************/
/************计算个阶段的各相位的清空时间***在每阶段的开始时执行一次****************/
 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,j,difer,diff;
    uint data toto,toto1;
    uchar data asc_flag=0;
 //   uint phasek;
   for(i=0;i<32;i++){
        if(sensor_step[step_counter]!=0){
                                   asc_flag=1;
                                   break;
                                         }
              }

    if((sensor_virgin_flag)&&(/*sensor_step[step_counter]*/asc_flag==1))
        {
           sensor_virgin_flag = 0;
           step_time = search_step_time();             //阶段时间在开始时只加载一次=最小绿灯+红灯+黄灯
        }
    run_state=0x01;

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

    }
      max_clear_time();
      cal_clear_time();//计算个阶段的清空时间
     // max_clear_time();
      ///////////////////////////////////////////////////////////////////////////////
//遥控遥控遥控遥控遥控遥控遥控遥控遥控遥控遥控遥控遥控遥控遥控遥控遥控遥控遥控遥控遥控
////////////////////////////////////////////////////////////////////////////////

        if(re_control==1) {    //遥控
             run_state=0x03;
             if(act_flag==1){ //遥控状态发生时,时间转移到当前执行阶段绿灯最后一秒 遥控发生秒
                         act_flag=0;
                         if(clear_flag==0){ //绿灯阶段当前阶段倒计时置为绿灯最后一秒,
                                 now_uncount =max_green_flash+max_red_clear+max_yellow+1;
                                           } //处于本阶段清空时刻,不处理,顺其自然


                             }else{   //非遥控发生秒执行语句
                             if(re_keep_flag==1){//
                                      now_uncount=max_green_flash+max_red_clear+max_yellow+1;
                                             }else {//遥控的是当前运行阶段或处于过时间不需要减少
                                      if(step_counter!=reph_number-1){
                                                                      now_uncount--;
                                                                      }else{
                                                                      if(re_exe_flag==1){
                                                                            now_uncount =max_green_flash+max_red_clear+max_yellow+1;
                                                                            re_exe_flag=0;
                                                                                          }
                                                                            }
                                           }
                                 }
                        }else{//无强制和遥控的状态下

                            //now_uncount=XBYTE[baseaddr_now_schemesch+8+step_counter]-now_step_key;
                            if((re_control==0)&&last_re_control==1){
                                          now_uncount=max_green_flash+max_red_clear+max_yellow+1;
                                          now_step_key=0;
                                                                    }

                             }

      //  last_re_control=re_control;
//遥控遥控遥控遥控遥控遥控遥控遥控遥控遥控遥控遥控遥控遥控遥控遥控遥控遥控遥控遥控遥控
 ///////////////////////////////////////////////////////////////////////////////////////
//强制强制强制强制强制强制强制强制强制强制强制强制强制强制强制强制强制强制强制强制强制
////////////////////////////////////////////////////////////////////////////////////////
      if(force_flag==1){    //强制阶段号发生变化
                run_state=0x02;
         //     if(force_number!=last_forcenumber){
                     if(act_force==1){ //进入强制控制的第一秒
                              act_force=0;
                              if(clear_force==0){//绿灯阶段
                                       now_uncount =max_green_flash+max_red_clear+max_yellow+1;
                                                 }

⌨️ 快捷键说明

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