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

📄 second.c.bak

📁 最先进的信号机程序,经过很多重要场合测试通过
💻 BAK
📖 第 1 页 / 共 4 页
字号:
                }
                for(j=0; j<16; j++)                   //此循环用于查找当前相位用到的灯组
                {
                   toto1 = 0x0001;
                   toto1 = toto1<<j;
                   inuse_lamp_temp =  toto1&now_lamp;
                   if(inuse_lamp_temp!=0)
                   {
                      if(now_phase_tempn==0)
                      {
                         ensensor_flag = 0;
                         sensor_car_flag = 0;
                         step_time = now_step_key+now_uncount;
                         lamp_state[j]=2;         /*当前阶段用的灯组置成绿闪*/

                      }
                      else
                      {
                         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;         //当前阶段的倒计时
                }
                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;          /*下一阶段用的灯组仍置成绿色*/
                   }
                }
              }

           }
        }
    }
    count_step++;
    if(force_flag!=1)now_step_key++;            //如果没有强制标志
    if((force_flag!=last_forceflag)&&(last_forceflag!=0))esc_flag=1;

    if(esc_flag==1)esc_counter++;
    if(esc_counter==5){
               esc_counter=0;
               esc_flag=0;
               now_uncount=1;
               period_update=1;
               baseaddr_now_schemesch = 0x5E84+41*(now_schemeid-1);
               temp=XBYTE[baseaddr_now_schemesch];
               if(co==temp)co=0;
               step_counter=co;
               for(i=0;i<16;i++)lamp_state[i]=4;
                      }


    if(now_uncount==1)                          //一个阶段时间走完
    {
        step_counter++;
        now_step_key = 0;
        sensor_virgin_flag = 1;
        /////////////////////////////////////////////////////////
        period_sch[7+step_counter]=count_step;
        count_step=0;
        ///////////////////////////////////////////////////////
        if(step_counter>=step_num){ //周期结束
                                   period_update = 1;
                                   }
    }
  if(esc_counter==6){   //强制或遥控的解除
                  step_counter=0;
                                 }



}
/*****************************************************************************************************/
//  灯输出函数
/*****************************************************************************************************/
void lamp_out() using 1
{
    uchar xdata i;
    uchar xdata left;

    greenl=0;
    greenh=0;
    yell=0;
    yelh=0;
    redl=0;
    redh=0;

    for(i=0;i<8;i++)
    {
        left=0x01;
        left=left<<i;
        switch(lamp_state[i])
        {
           case  0x01:                      //绿灯
                      greenl=(greenl|left);
                      break;
           case  0x02:                      //绿闪
                      if(ssecond)  greenl=(greenl|left);
                      else         greenl=(greenl&(~left));
                      break;
           case  0x03:                      //黄灯
                      yell=(yell|left);
                      break;
           case  0x04:                      //红灯
                      redl=(redl|left);
                      break;
           case  0x05:                      //黄闪
                      if(ssecond)  yell=(yell|left);
                      else         yell=(yell&(~left));
                      break;
           default:break;
        }
        switch(lamp_state[i+8])
        {
           case  0x01:
                      greenh=(greenh|left);
                      break;
           case  0x02:
                      if(ssecond)  greenh=(greenh|left);
                      else         greenh=(greenh&(~left));
                      break;
           case  0x03:
                      yelh=(yelh|left);
                      break;
           case  0x04:
                      redh=(redh|left);
                      break;
           case  0x05:
                      if(ssecond)  yelh=(yelh|left);
                      else         yelh=(yelh&(~left));
                      break;
           default:break;
        }

    }

  //     XBYTE[0Xc103]=0x80;
  //     XBYTE[0Xc183]=0x80;
       XBYTE[0Xc100]=greenl;
       XBYTE[0Xc101]=yell;
       XBYTE[0Xc102]=redl;
       XBYTE[0Xc180]=greenh;
       XBYTE[0Xc181]=yelh;
       XBYTE[0Xc182]=redh;
}
/*****************************************************************************************************/
//  装载状态函数
/*****************************************************************************************************/
void  make0x83()
{

    led82[0] = now_day_planid;     //当前计划
    led82[1] = timeid;             //时段
    led82[2] = now_schemeid;       //当前方案

    led83[0] = now_step_schid/*+1*/;          //当前的阶段表号
    led83[1] = step_counter+1;                //当前阶段

    led83[4] = now_phase_status/256;
    led83[5] = now_phase_status%256;      //当前的相位状态


    led83[9] = inuse_phasen[step_counter]/256;
    led83[10] = inuse_phasen[step_counter]%256;    //下一阶段的放行相位


    led83[11] = now_step_uncount-1;               //当前阶段的倒计时
    led83[12] = machine_run_error;                //运行故障信息
    led83[13] = r_error1/256;
    led83[14] = r_error1%256;       /*驱而不亮的红灯组*/
    led83[15] = y_error1/256;
    led83[16] = y_error1%256;       /*驱而不亮的黄灯组*/
    led83[17] = g_error1/256;
    led83[18] = g_error1%256;       /*驱而不亮的绿灯组*/

    led83[19] = r_error2/256;
    led83[20] = r_error2%256;       /*不驱而亮的红灯组*/
    led83[21] = y_error2/256;
    led83[22] = y_error2%256;       /*不驱而亮的黄灯组*/
    led83[23] = g_error2/256;
    led83[24] = g_error2%256;       /*不驱而亮的绿灯组*/

    led83[25] =  hpp/256;
    led83[26] =  hpp%256;
    led83[27] =  lpp/256;
    led83[28] =  lpp%256;           //线圈故障信息

}
/*黄闪和四面红*/
void hand_control()
{
  unsigned char data kkk=0;
  unsigned data toto;
//  unsigned int xdata fa_address;
//  unsigned int xdata detail_addr;

  temp=XBYTE[0X6d28];
  co=XBYTE[0x6d29];
  kkk=0;
  switch (temp){
         case 0x02:for(kkk=0;kkk<16;kkk++){
                        toto = 0x0001;
                        toto = toto<<kkk;
                        if((use_lamp&toto)==toto)  lamp_state[kkk]=4;      /*使用的灯组置成红色先*/
                                             else  lamp_state[kkk]=7;
                                   }
                    break;
         case 0x03:for(kkk=0;kkk<16;kkk++){
                        toto = 0x0001;
                        toto = toto<<kkk;
                        if((use_lamp&toto)==toto)  lamp_state[kkk]=5;      /*使用的灯组置成黄闪先*/
                                             else  lamp_state[kkk]=7;
                                   }
                    break;
         case 0x04:break;
         default:break;
        }


}
/*强制和遥控*/
handremote()
{
  unsigned int  xdata toto,toto1;
  unsigned char xdata i;
//  unsigned char xdata j=0;
 //   nowforce=XBYTE[0X6D29];
    if(sss!=co){
                hand_counter=0;              //阶段号发生变化计时重新开始
           //     j++;
                }
 //  if(nowforce!=lastforce){
 //          hand_counter=0;
       //    step_counter=co;
 //                         }
        //强制的阶段号              
    hand_counter++;

    if(hand_counter>100)hand_counter=100;
        if(hand_counter>=7){ //7秒后
          if(co==(step_counter+1)){//如果当前强制的阶段是当前正放行的相位,不管当前是什么灯色一律置成绿色
            lai_nouse=(now_step_schid-1)*98; //当前阶段表号
            lai_nouse=0x5242+lai_nouse;      //计算阶段表中地址偏移量
            toto=lai_nouse;
            toto=toto+(step_counter)*3+2;    //当前阶段放行的相位
            lai_nouse=toto;
            toto1=XBYTE[toto];
            temp=toto1;
            toto1=toto1<<8;
            toto1=toto1+XBYTE[toto+1];     //当前阶段对应放行的相位
            lai=toto1;
            toto=0x5246+(now_step_schid-1)*98;
            tmd=toto;
            temp=XBYTE[toto];
            if(temp==0)toto=0x5001;       //通过阶段表中空白属
                  else toto=0x5122;       //性确认阶段表所依赖的相位表
            guli=toto;
            control_chunel=0;
            for(i=0;i<16;i++){
              if(i==0)shift=0x0001;
              if(i==1)shift=0x0002;
              if(i==2)shift=0x0004;
              if(i==3)shift=0x0008;
              if(i==4)shift=0x0010;
              if(i==5)shift=0x0020;
              if(i==6)shift=0x0040;
              if(i==7)shift=0x0080;
              if(i==8)shift=0x0100;
              if(i==9)shift=0x0200;
              if(i==10)shift=0x0400;
              if(i==11)shift=0x0800;
              if(i==12)shift=0x1000;
              if(i==13)shift=0x2000;
              if(i==14)shift=0x4000;
              if(i==15)shift=0x8000;
              if((lai&shift)==shift){
                   hand_lamp=guli+i*18;    //相位对应的通道地址
                   hand_phase=XBYTE[hand_lamp]; //相位对应的通道高位字节
                   hand_phase=hand_phase<<8;
                   hand_phase=hand_phase+XBYTE[hand_lamp+1]; //相位对应通道的全部内容
                   control_chunel=control_chunel|hand_phase;
                                              }
                                }
           for(i=0;i<16;i++){
              if(i==0)shift=0x0001;
              if(i==1)shift=0x0002;
              if(i==2)shift=0x0004;
              if(i==3)shift=0x0008;
              if(i==4)shift=0x0010;
              if(i==5)shift=0x0020;
              if(i==6)shift=0x0040;
              if(i==7)shift=0x0080;
              if(i==8)shift=0x0100;
              if(i==9)shift=0x0200;
              if(i==10)shift=0x0400;

⌨️ 快捷键说明

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