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

📄 lampout.c

📁 ASC 信号机控制程序,国内最先进的信号机控制程序
💻 C
字号:
#include <absacc.h>
#include <reg52.h>
unsigned char gf_count[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
unsigned char ye_count[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
unsigned char re_count[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
unsigned char lamp_state[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
      /*灯色状态存储单元01:绿;02:绿闪;03:黄;04:红;*/      /*05:黄闪;06:红闪;07:全灭*/
/*****************************************************************/
/*灯色状态输出函数                                               */
/* 根据灯色状态中,控制程序对灯组的颜色状态的设置,驱动信号灯    */
/*****************************************************************/
 unsigned char xdata flash_period;
 unsigned char xdata flash_light;
unsigned char xdata gtemp1[16],ytemp1[16],rtemp1[16];
unsigned char xdata gtemp2[16],ytemp2[16],rtemp2[16];
unsigned char xdata gl_read;
unsigned char xdata gh_read;
unsigned char xdata yl_read;
unsigned char xdata yh_read;
unsigned char xdata rl_read;
unsigned char xdata rh_read;
unsigned int  data g_load1,y_load1,r_load1;
unsigned int  data g_load2,y_load2,r_load2;
extern unsigned char xdata state_update;   /*用来检测负荷故障*/
unsigned int  xdata g_error1,y_error1,r_error1;/*驱而不亮的故障*/
unsigned int  xdata g_error2,y_error2,r_error2;/*不驱而亮的故障*/

 unsigned char xdata yellowl,yellowh;
 unsigned char xdata gl_error;
 unsigned char xdata yl_error;
 unsigned char xdata rl_error;
 unsigned char xdata gh_error;
 unsigned char xdata yh_error;
 unsigned char xdata rh_error;

 unsigned int xdata g_read,y_read,r_read;
 unsigned int xdata g_out,y_out,r_out;
 unsigned char data con;
 unsigned char xdata greenl,greenh;
 unsigned char xdata yell,yelh;
 unsigned char xdata redl,redh;
 unsigned char xdata l82551_read,h82551_read,l82552_read,h82552_read;

 extern char xdata start_count;
 sbit cs_dram=P3^2;
lamp_out()
{
 unsigned char data i;
 unsigned char data left;
 unsigned char temp;
 unsigned char hi=0,lo=0;

 /*
 unsigned char xdata greenl,greenh;
 unsigned char xdata yell,yelh;
 unsigned char xdata redl,redh;  */
 greenl=0;
 greenh=0;
 yell=0;
 yelh=0;
 redl=0;
 redh=0;
 temp=XBYTE[0X80C8];
 flash_light=5*temp;
 flash_period=5*XBYTE[0X80C9];

 for(i=0;i<8;i++){
       if(i==0)left=0x01;
       if(i==1)left=0x02;
       if(i==2)left=0x04;
       if(i==3)left=0x08;
       if(i==4)left=0x10;
       if(i==5)left=0x20;
       if(i==6)left=0x40;
       if(i==7)left=0x80;


       if(lamp_state[i]==0x01){greenl=(greenl|left);gf_count[i]=0;}
       if(lamp_state[i]==0x02){
                             gf_count[i]++;
                             if((gf_count[i])>50)gf_count[i]=0;
                             if((gf_count[i])<25)greenl=(greenl|left);
                                           else greenl=(greenl&(~left));
                                             }
       if(lamp_state[i]==0x03)yell=(yell|left);
       if(lamp_state[i]==0x04)redl=(redl|left);
       if(lamp_state[i]==0x05){
                             ye_count[i]++;
                             /*if((ye_count[i])>50)ye_count[i]=0;
                             if((ye_count[i])<25)yell=(yell|left);  */
                             if((ye_count[i])>flash_period)
                             ye_count[i]=0;
                             if((ye_count[i])<flash_light)yell=(yell|left);
                                           else yell=(yell&(~left));
                                             }
                          }
 for(i=0;i<8;i++){
       if(i==0)left=0x01;
       if(i==1)left=0x02;
       if(i==2)left=0x04;
       if(i==3)left=0x08;
       if(i==4)left=0x10;
       if(i==5)left=0x20;
       if(i==6)left=0x40;
       if(i==7)left=0x80;

       if(lamp_state[i+8]==0x01){greenh=(greenh|left);gf_count[i+8]=0;}
       if(lamp_state[i+8]==0x02){
                             gf_count[i+8]++;
                             if((gf_count[i+8])>50)gf_count[i+8]=0;
                             if((gf_count[i+8])<25)greenh=(greenh|left);
                                           else greenh=(greenh&(~left));
                                             }
       if(lamp_state[i+8]==0x03)yelh=(yelh|left);
       if(lamp_state[i+8]==0x04)redh=(redh|left);
        if(lamp_state[i+8]==0x05){
                             ye_count[i+8]++;
                             /*if((ye_count[i+8])>50)ye_count[i+8]=0;
                             if((ye_count[i+8])<25)yelh=(yelh|left); */
                             if((ye_count[i+8])>flash_period)ye_count[i+8]=0;
                             if((ye_count[i+8])<flash_light)yelh=(yelh|left);

                                           else yelh=(yelh&(~left));
                                             }
                  }
       XBYTE[0Xc103]=0x80;
       XBYTE[0Xc183]=0x80;
       XBYTE[0Xc100]=greenl;
       XBYTE[0Xc101]=yell;
       XBYTE[0Xc102]=redl;
       XBYTE[0Xc180]=greenh;
       XBYTE[0Xc181]=yelh;
       XBYTE[0Xc182]=redh;



}
extern unsigned char c381,c380,c301,c300,flagh,flagl;
unsigned char  gl_out,yl_out,rl_out,gh_out, yh_out, rh_out,unit_error;
read_state()
{
 unsigned int  data lod;
 unsigned char data i;

  //cs_dram=1;
       gl_out=XBYTE[0Xc100];
       yl_out=XBYTE[0Xc101];
       rl_out=XBYTE[0Xc102];
       gh_out=XBYTE[0Xc180];
       yh_out=XBYTE[0Xc181];
       rh_out=XBYTE[0Xc182];


  XBYTE[0XC203]=0X9b;//b
  XBYTE[0XC283]=0X9b;//b
  gl_read=XBYTE[0XC200];     /*实际信息,来自硬件端口*/
  yl_read=XBYTE[0XC201];
  rl_read=XBYTE[0XC202];
  gh_read=XBYTE[0XC280];
  yh_read=XBYTE[0XC281];
  rh_read=XBYTE[0XC282];
  l82551_read=XBYTE[0Xc300];
  h82551_read=XBYTE[0Xc301];
  l82552_read=XBYTE[0Xc380];
  h82552_read=XBYTE[0Xc381];
  unit_error=0;
  i=1;
  if(XBYTE[0xa01b]==0xff&&XBYTE[0xa01b]==0xff&&XBYTE[0xa01b]==0xff)
  unit_error=unit_error|i;                                  //通信单元
  i=i*2;
  if(gl_read==0xff&&yl_read==0xff&&rl_read==0xff)
  unit_error=unit_error|i;                      //信号灯检测输入8255-1
  i=i*2;
  if(gh_read==0xff&&yh_read==0xff&&rh_read==0xff)
  unit_error=unit_error|i;                               //信号灯检测输入8255-2
  i=i*2;
   if(l82551_read==0xff&&h82551_read==0xff)
  unit_error=unit_error|i;                                //线圈检测输入8255-1
  i=i*2;
  if(l82552_read==0xff&&h82552_read==0xff)
  unit_error=unit_error|i;                                //线圈检测输入8255-2
  i=i*2;
  if(gl_out==0xff&&yl_out==0xff&&rl_out==0xff)
  unit_error=unit_error|i;                             //信号灯输出8255-1
  i=i*2;
  if(gl_out==0xff&&yl_out==0xff&&rl_out==0xff)
  unit_error=unit_error|i;                              //信号灯输出8255-2
  i=i*2;



  g_read=gh_read*256+gl_read;    /*16位分别代表16个灯组的绿灯情况*/
  y_read=yh_read*256+yl_read;    /*16位分别代表16个灯组的黄灯情况*/
  r_read=rh_read*256+rl_read;    /*16位分别代表16个灯组的红灯情况*/
  //g_read=XBYTE[0XC280]*256+XBYTE[0XC200];    /*16位分别代表16个灯组的绿灯情况*/
  //y_read=XBYTE[0XC281]*256+XBYTE[0XC201];    /*16位分别代表16个灯组的黄灯情况*/
  //r_read=XBYTE[0XC282]*256+XBYTE[0XC202];    /*16位分别代表16个灯组的红灯情况*/

 // g_read=gh_read*256+gl_read;    /*16位分别代表16个灯组的绿灯情况*/
  //y_read=yh_read*256+yl_read;    /*16位分别代表16个灯组的黄灯情况*/
 // r_read=rh_read*256+rl_read;    /*16位分别代表16个灯组的红灯情况*/

  /*-------------------------------------------------------*/
//  g_out=greenh*256+greenl;    /*16位分别代表16个灯组的绿灯程序输出情况*/
//  y_out=yelh*256+yell;    /*16位分别代表16个灯组的黄灯程序输出情况*/
//  r_out=redh*256+redl;    /*16位分别代表16个灯组的红灯程序输出情况*/
  g_out=greenh*256+greenl;    /*16位分别代表16个灯组的绿灯程序输出情况*/
 y_out=yelh*256+yell;    /*16位分别代表16个灯组的黄灯程序输出情况*/
 r_out=redh*256+redl;    /*16位分别代表16个灯组的红灯程序输出情况*/
 // g_out=XBYTE[0Xc180]*256+XBYTE[0Xc100];    /*16位分别代表16个灯组的绿灯程序输出情况*/
  //y_out=XBYTE[0Xc181]*256+XBYTE[0Xc101];    /*16位分别代表16个灯组的黄灯程序输出情况*/
  //r_out=XBYTE[0Xc182]*256+XBYTE[0Xc102];    /*16位分别代表16个灯组的红灯程序输出情况*/
  if(state_update==0x01){ /*用来检测负荷故障状态发生改变*/
            state_update=0x00;/*对故障检测结果清零*/

                        }

 for(i=0;i<16;i++){

     lod=0x0001;
     lod=(lod<<i);
     if(((g_out&lod)==lod)&&((g_read&lod)!=lod))
         {if(gtemp1[i]==10)gtemp1[i]=10;
          else
          gtemp1[i]++;
          }
     else gtemp1[i]=0;
     if(((y_out&lod)==lod)&&((y_read&lod)!=lod))
         {if(ytemp1[i]==10)
           ytemp1[i]=10;
          else
          ytemp1[i]++;
          }
     else ytemp1[i]=0;
     if(((r_out&lod)==lod)&&((r_read&lod)!=lod))
         {if(rtemp1[i]==10)
          rtemp1[i]=10;
          else
          rtemp1[i]++;
          }
     else rtemp1[i]=0;
     if(((g_read&lod)==lod)&&((g_out&lod)!=lod))
          {if(gtemp2[i]==70)
           gtemp2[i]=70;
          else
          gtemp2[i]++;
          }
     else gtemp2[i]=0;
     if(((y_read&lod)==lod)&&((y_out&lod)!=lod))
          {if(ytemp2[i]==70)ytemp2[i]=70;
          else
          ytemp2[i]++;
          }
     else ytemp2[i]=0;
     if(((r_read&lod)==lod)&&((r_out&lod)!=lod))
          {if(rtemp2[i]==70)rtemp2[i]=70;
          else
          rtemp2[i]++;
          }
      else rtemp2[i]=0;

    if(gtemp1[i]==10)
     g_load1=(g_load1|lod); /*程序输出但采样没有,驱而不亮*/
     if(ytemp1[i]==10)
     y_load1=(y_load1|lod); /*程序输出但采样没有,驱而不亮*/
     if(rtemp1[i]==10)
     r_load1=(r_load1|lod); /*程序输出但采样没有,驱而不亮*/
     if(gtemp2[i]==70)
     g_load2=(g_load2|lod); /*程序没有输出但采样有,不驱而亮*/
     if(ytemp2[i]==70)
     y_load2=(y_load2|lod); /*程序没有输出但采样有,不驱而亮*/
     if(rtemp2[i]==70)
     r_load2=(r_load2|lod); /*程序没有输出但采样有,不驱而亮*/

  }

    //g_error1=g_load1; /*驱而不亮的绿灯组*/
   // y_error1=y_load1; /*驱而不亮的黄灯组*/
   // r_error1=r_load1; /*驱而不亮的红灯组*/
  //  g_error2=g_load2; /*不驱而亮的绿灯组*/
  //  y_error2=y_load2; /*不驱而亮的黄灯组*/
 //   r_error2=r_load2; /*不驱而亮的红灯组*/
    //make86();

//    g_error1=!(g_out&g_read)&g_out;  /*驱而不亮的绿灯组*/
//    y_error1=!(y_out&y_read)&y_out;  /*驱而不亮的黄灯组*/
//    r_error1=!(r_out&r_read)&r_out;; /*驱而不亮的红灯组*/
//    g_error2=g_error1^(g_out^g_read); /*不驱而亮的绿灯组*/
//    y_error2=y_error1^(y_out^y_read); /*不驱而亮的黄灯组*/
//    r_error2=r_error1^(r_out^r_read); /*不驱而亮的红灯组*/
}



⌨️ 快捷键说明

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