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

📄 jiaotong2.c

📁 交通灯控制源程序
💻 C
📖 第 1 页 / 共 4 页
字号:
	byte i,j,k,l,con_num;
   TXD1=0;
   for (i=15;i;i--) { 
   	con_num=*(CON_BUF+i-1);
      for (j=0;j<4;j++){
        	if((half_flag||(con_num&0x80))&&(con_num&0x40)) RXD1=(1&light_on);
	      else RXD1 = 0;
         TXD1=1;
         TXD1=0;
         con_num<<=2;}}
  LAT1=0;    LAT1=1;  LAT1=0; 
     for (k=0;k<8;k++){
	   con_num=*(DISP_BUF+k);        
		for (l=0;l<8;l++) {
	      RXD1=(con_num&0x80);
         con_num<<=1;
         TXD1=1;
         TXD1=0;
   	}}       
   LAT2=0;  LAT2=1;  LAT2=0;                  
            }
 /* byte change (byte c){
      return (((((c>>4)*10)/16)<<4)+((((c>>4)*10)%16)+(c&0x0f)));
                 }*/             
  byte bin2bcd(byte c) {
    return ((c/10)<<4) | (c%10);
  }
  byte bcd2bin(byte c) {
    return ((c>>4)*10) + (c&0x0f);
  }

  void initrtcc(byte hh, byte mm) {   
    if ((CLK_REGA!=0x20)||(CLK_REGB!=0x02)) {
    	  hh=0x10; mm=0;
    } else if (hh==0xff) return;
    
    EA=0;
    if ((bcd2bin(hh)<24)&&(bcd2bin(mm)<60)) {
        CLK_REGB=0x80;
        CLK_MIN=mm;
        CLK_HR =hh;
        CLK_MON=0x07;
        CLK_DD=0x01;
        CLK_WK=0x06;
        CLK_SEC=0x00;
        CLK_REGA=0x20; 
        CLK_REGB=0x02; 
    }
    EA=1; 
  }
   void  start_cpu(){
      TCON=0x01;
      TMOD=0x21;
      SCON=0xd0;
      PCON=0x00;
      IP=0x10;
      IE=0x93;
      TH0=-(DLY_1MS/256);
      TL0=-(DLY_1MS%256);
      TH1=0xfd;
      TL1=0xfd;
      TR0=1;
      TR1=1;
       }              

 ///////////////////////////////////
  void  main(void){
   P1=0;
   num1=0;
   num2=0;
   num_80=0;
   num_100=0;
   num_1s=0x00; 
   flag_3s=0;
   key_state=0;
   hand_on=0;
   hand=0;
   control_flag=0;
   first_flag=0;
   flag_write=0;
   sp_time=0x00;
   sp_state=0x00;
   scan_num=0;
   cur_step=0x00;
   num_step=0;
   num_control=0; 
   light_on=1;
   rec_flag=0;
   err_flag=0;
   key_state=0;
   cur_year=0;
   cur_week=0;
   cur_step=0;
   cur_date=0;
   cur_mon=0;
   cur_hour=0;
   cur_min=0;
   key_system_set=4;
   return_state=4;
   change_date_flag=0;
   str_flag=0;   
   start_cpu();
   *line_addr=0xff;                                             
   initrtcc(0xff,0x10); 
   while (!flag_3s){
   all_red();
   disp_con();}
   if(flag_3s==1)
   num_1s=0; 
   while(1){
     if(key_state) 
        key_dispose();
     if(rec_flag){
         if((cur_step==0)&&(num_1s==0)){
             if(!err_flag){
             err_judge();
             if(!err_flag)
             write_eeprom();
             err_flag=0;
             rec_flag=0;
                } 
          } 
     } 
 if (!change_date_flag){
     if((((cur_date!=CLK_DD)||(str_flag))||(cur_mon!=CLK_MON))||(cur_week!=CLK_WK)){ 
           if(str_flag){
              while((CLK_REGA&0x80)&&(flag_write));
              cur_year=CLK_YY; 
              cur_week=CLK_WK;
              cur_date=CLK_DD;
              cur_mon=CLK_MON;
              special_day_check();
            }
          else if(!str_flag){
              if ((cur_step==0)&&(num_1s==0)){   
               while((CLK_REGA&0x80)&&(flag_write));
               cur_year=CLK_YY; 
               cur_week=CLK_WK;
               cur_date=CLK_DD;
               cur_mon=CLK_MON;
               special_day_check();}
          }
      } 
     if(((cur_min!=CLK_MIN)||(str_flag))||(cur_hour!=CLK_HR)){                       
         if(str_flag){
                while((CLK_REGA&0x80)&&(flag_write));
                cur_hour=CLK_HR;
                cur_min=CLK_MIN;  
                project_d_check();
                cur_step=0;
                num_1s=0; 
                str_flag=0;
         }
         else if(!str_flag){
            if (num_step==0){
                while((CLK_REGA&0x80)&&(flag_write));
                cur_hour=CLK_HR;
                cur_min=CLK_MIN;
                project_d_check();
            }     
            else if ((cur_step==0)&&(num_1s==0)){               
                     while((CLK_REGA&0x80)&&(flag_write));
                     cur_hour=CLK_HR;
                     cur_min=CLK_MIN;
                     project_d_check();
            }
          }         
     }
     if(hand&&(return_state==4)) {
              con_get_data();
              disp_con();
              if(hand_on){if (cur_step<num_step)cur_step++;
                          else cur_step=0;}
              hand_on=0;
     }                          
     else if(((!hand_on)&&(!control_flag))&&(!first_flag)){
        if(((num_plan<=60)&&(num_control<=56))&&(num_step<=32)){
          if(num_step!=0){
              if(num_step>cur_step)
                {con_get_data();
                 if(step_time!=0){
                   if (num_1s<step_time)
                     {
                      if (step_time<=99)
                      disp_con();
                   }

                   if (num_1s>=step_time)
                     {cur_step++;
                      num_1s=0;
                   } 
                  }
                 else {num_1s=0;cur_step++;}       
                }  
              if (num_step<=cur_step)
                     {cur_step=0;num_1s=0;}    
           }                    
         else  {all_red();disp_con();}
        }                    
       else {all_red();disp_con();}  
     } 
    else if(!first_flag){
          hand_on=0;
          if(control_flag) { num_1s=0; qiang();
                            while(num_1s<step_time) disp_con();
                            if(num_1s>=step_time){str_flag=1;num_1s=0;}
          }
         control_flag=0; 
     } 
   else if(first_flag) {
              num_control=numa;num_step=numb;cur_step=numc;num_1s=0;          
              while(num_step>cur_step)
                {con_get_data();
                 if(step_time!=0){
                    if (num_1s<step_time)                     
                        disp_con();
                    if (num_1s>=step_time)
                      {cur_step++;
                       num_1s=0;}
                 }
                 else {num_1s=0;cur_step++;}
              }      
              if(num_step<=cur_step){                               
              cur_step=0;first_flag=0;str_flag=1;}
    } 
 } 
 else if(change_date_flag){
        if(((num_plan<=60)&&(num_control<=56))&&(num_step<=32)){
          if(num_step!=0){
              if(num_step>cur_step){
                con_get_data();
                if(step_time!=0){                 
                  if (num_1s<step_time)
                     {if (step_time<=99)
                      disp_con();}
                  else if (num_1s>=step_time)
                     {cur_step++;
                      num_1s=0;}  
                }
                else {cur_step++;num_1s=0;
                }        
              }  
              if (num_step<=cur_step)
                     {cur_step=0;
                      num_step=0;
                      change_date_flag=0; 
             }
           }
         else {all_red();disp_con();}   
          }                    
       else  {all_red();disp_con();}
                    }
                }
           }
    



⌨️ 快捷键说明

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