只可远观,不可亵玩

交通灯PS:此程序未使用时钟)
#include"reg51.h"
unsigned int a,i,s,t,m,n=1,ii,aa;
//设置
unsigned int cshi=30;//秒数
unsigned int jge=5;//延时
//red
sbit red1 = P1^0;
sbit red2 = P1^5;
//green	
sbit green1 = P1^2;
sbit green2 = P1^3;
//yellow	
sbit yellow1 = P1^1;
sbit yellow2 = P1^4;
//延时函数
void Delay(s){
	while(s--){
		t = 10000;
		while(t--);
	}
} 
//yellow
void rygcx(e,f){
	e %= 2;
	if(f<=3){
		yellow2 = yellow1 = green2 = green1 = 1;
		Delay(jge);
		yellow1 = ~e;
		yellow2 = ~yellow1;
	}else{
		yellow2 = yellow1 = 1;	
		green1 = ~e;
		green2 = ~green1;
		red1 = e;
		red2 = ~red1;
	}
	Delay(jge);	
}
//跑初始值			   
void chushi(e){
	 ii = 0x00;
	 for(a=e-1;;a--){
	 	if(a==e){m=1;}else{m=a%10;}
	 	if(m==0){ii+=7;}else{ii++;}
	 	if(a==0){break;}	
	 }
}
void main(){
	chushi(cshi);
	while(1){
		m = 0;
		i = ii; 
		rygcx(--n,cshi);
		for(a=cshi;;a--){
			m=a%10;
			P2 = i;
			rygcx(n,a);
			if(m==0){i-=7;}else{i--;}
	 		if(a==0){break;}
		}	   
	} 
}

8051-交通灯