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

📄 traffic.c

📁 经过测试好用
💻 C
字号:
#include <AT89X51.H>
	 
unsigned char ID;
unsigned int time0;
unsigned int time1;
unsigned int time2;
unsigned int timeact;
unsigned int x;
void desplay(x);
void main(void)
{
  TMOD=0x01;
  TH0=(65536-10000)/256;
  TL0=(65536-10000)%256;
  TR0=1;
  ET0=1;
  EA=1;
  P1=0x00;
  P0=0x00;
  time0=20;
  time1=6 ;
  time2=40;
 
  
  while(1)
  {
  if(P2_7==1)
  {TR0=0;
   ID=0;
  return;
  }
  else
  TR0=1;
  }
}

void desplay(x)
{
unsigned int a;
unsigned int b;
unsigned int c;
c=x;
if(c%2==0)
{
c=x/2;
a=c%10;
b=c/10;	
P0=b*16+a;
}
}


void mode0(void)
{		
   timeact++;
   if(timeact==50)
   {  if(time0<8)
        {
          if(time0%2==1)
	        P1=0x00;
	      else
	        P1=0x21;
	    }
		else
		{P1=0x21; }
	  
	   		   desplay(time0);
	   time0--;
	   	
	   if(time0==0)
	   {
	    time0=20;
		ID++;
		}
	  timeact=0;

   }
}

void mode1(void)
{		
   timeact++;
   if(timeact==50)
   {  
          if(time1%2==1)
	        P1=0x00;
	      else
	        P1=0x22;
			   	  desplay(time1);
	  time1--;
	  	
	   if(time1==0)
	   {
	    time1=6;
		ID++;
		}
	  timeact=0;

   }
}

void mode2(void)
{		
   timeact++;
   if(timeact==50)
   {  if(time2<8)
        {
          if(time2%2==1)
	        P1=0x00;
	      else
	        P1=0x0c;
	    }
		else
		{P1=0x0c; }
			 desplay(time2);
	   time2--;	
	    
	   if(time2==0)
	   {
	    time2=40;
		ID++;
		}
	  timeact=0;

   }
}

void mode3(void)
{		
   timeact++;
   if(timeact==50)
   {  
          if(time1%2==1)
	       { P1=0x00;
			}
	      else
	        P1=0x14;
		     desplay(time1);
	  time1--; 
	 
	   if(time1==0)
	   {
	    time1=6;
		ID++;
		}
	  timeact=0;

   }
}

void t0(void) interrupt 1 using 0
{
  TH0=(65536-10000)/256;
  TL0=(65536-10000)%256;
  if(ID==4)
  ID=0;
switch (ID)
{
	case 0:mode0();
		break;
	case 1:mode1();
		break;
	case 2:mode2();
		break;
	case 3:	mode3();
		break;
}
}


⌨️ 快捷键说明

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