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

📄 main.c

📁 this procedure is a game of basketball or subsystems time, the competition will record the entire ti
💻 C
字号:
 #include<reg51.h>
 #include<stdio.h>	 
#include<intrins.h>
 sbit	k5=P2^4;
 sbit	k6=P2^5;
 sbit 	k7=P2^6;
 sbit 	buzzer=P3^6;
 sbit 	tenfen=P2^0;
 sbit 	fen=P2^1;
 sbit 	tens=P2^2;
 sbit	second=P2^3;
 sbit	k1=P0^1;
 sbit	k2=P0^2;
 sbit	k3=P3^5;
 sbit	k4=P3^4;
 sbit 	int0=P3^2;
 sbit STR  =  P3^7;//定义CD4094各端口;
 sbit DATA =  P3^0;
 sbit CLK  =  P3^1;
		
  

#define uint  unsigned int
#define uchar unsigned char
uchar code table[10]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09};
unsigned char code Date[]={0x3f,0x06,0x5b,0x4f,0x66, 
                            0x6d,0x7d,0x07,0x7f,0x6f}; 
uint jifen[]={0,0,0,0,0,0,0};
int disn[8];
uchar disnum[]={1,2,3,4,5,6,7,8,9};
uint tf,f,ts,s,kk7;



void jishi();
void Out_4094(uchar data1);//CD4094写数据子函数;
void Delay10ms(uint a);     //延时子函数;




void Out_4094(int *p) //写CD4094子函数;
{
	int i;
   	for(i=0;i<6;i++)
	{  
		disn[i]=*(Date+disnum[i-1]);
		SBUF=*(p+i);
		while(!TI);
		TI=0;
		STR=1;
		STR=0;
	}  
}

void Delay10ms(uint a)     //延时子函数;
{
	uint j,k;
	for(;a>0;a--)
	for(j=20;j>0;j--)
	for(k=248;k>0;k--)	  {} ;
}

void jishi()		
{
	for(;tf>0;)
		{
		
		if(kk7==0)	 break; 
			for(;f>0;)
			{
				
			    if(kk7==0)	 break; 
				for(;ts>0;)
					{ 	
					if(kk7==0)	 break; 
						for(;s>0;);
			 			{	
							if(k7==0)
							{
								Delay10ms(1);
								if(k7==0)
								kk7=!kk7;
							}
								if(kk7==0)	 break; 							
								Delay10ms(100) ;
								s--;
								second=0;
								P1=table[s];
								Delay10ms(1);
								second=1;
								
						}		
					s=10;
					ts--;
					tens=0;
					P1=table[tens];
					Delay10ms(1);
					tens=1;	
					}
			ts=6;
			f--;
			fen=0;
			P1=table[f];
			Delay10ms(1) ;
			fen=1;	
			}
		f=10;
	   	tf--;
		tenfen=0;
		P1=table[tf];
		Delay10ms(1);
		tenfen=1;
		}
		 for(;f>0;)
			{
			if(kk7==0)	 break;
			
				for(;ts>0;)
					{ 	
						if(kk7==0)	 break;
					    
						for(;s>0;)
			 			{
								if(k7==0)
							{
								Delay10ms(1);
								if(k7==0)
								kk7=!kk7;
							}
					  			if(kk7==0)	 break;							
								Delay10ms(100);
								s--;
								second=0;
								P1=table[s];
								Delay10ms(1);
								second=1;
						}
					s=10;
					ts--;
					tens=0;
					P1=table[tens];
					Delay10ms(1);
					tens=1;	
					}
			ts=6;
			f--;
			fen=0;
			P1=table[f];
			Delay10ms(1);
			fen=1;	
			}
		for(;ts>0;)
				{ 	
					if(kk7==0)	 break;
				    
					for(;s>0;)			 			{
						if(k7==0)
						{
							Delay10ms(1);
							if(k7==0)
							kk7=!kk7;
						}
				  			if(kk7==0)	 break;							
							Delay10ms(100);
							s--;
							second=0;
							P1=table[s];
							Delay10ms(1);
							second=1;
				}
				s=10;
				ts--;
				tens=0;
				P1=table[tens];
				Delay10ms(1);
				tens=1;	
				}
		for(;s>0;)
			{
					if(k7==0)
						{
							Delay10ms(1);
							if(k7==0)
							kk7=!kk7;
						}
			  			if(kk7==0)	 break;							
						Delay10ms(100);
						s--;
						second=0;
						P1=table[s];
						Delay10ms(1);
						second=1;
			}
		kk7=0;	
		buzzer=0;
		Delay10ms(100);
		buzzer=1;

}


	

void main()
{
	
	EX0=1;
	EA=1;
 	PS=0;
	PX0=0;
	buzzer=1;
	tf=0,f=0,ts=0,s=0;
	kk7=0;
	tenfen=0;
	fen=0;
	tens=0;
	second=0;
	P1=0;
	tenfen=1;
	fen=1;
	tens=1;
	second=1;
	Out_4094(disn);
	while(1)			
	{
		if(k5==0)
		{
			Delay10ms(1);
			if(k5==0)
			{
				tf++;
				if(tf==10)
				tf=0;
				tenfen=0;
				P1=table[tf];
				Delay10ms(1);
				tenfen=1;
			}
		}
		if(k6==0)
		{	 
			Delay10ms(1);
			if(k6==0)
			{
				f++;
				if(f==10)
				f=0;
				fen=0;
				P1=table[f];
				Delay10ms(1);
				fen=1;
			}
		}
		if(k7==0)
		{
			Delay10ms(1);
			if(k7==0)
				kk7=!kk7;
		}
		if(kk7)
			jishi();
		}
}

void timer0(void) interrupt 0 
{
	uint  t=0 ;
	if(k1==0)
	{
		Delay10ms(1);
		if(k1==0)
		{
			disn[1]++;
			if(disn[1]==10) 
			{
				disn[2]++;
				disn[1]=0;
				if(disn[2]==10)
				{
					disn[3]++;
					disn[2]=0;
					if(disn[3]==0) disn[3]=0;
				}
			}
		}
			Out_4094(disn);
		
	}
	if(k2==0)
	{
		Delay10ms(1);
		if(k2==0)
		{
			disn[1]--;
			if(disn[1]==-1)
			{
				disn[1]=9;
				disn[2]--;
				if(disn[2]==-1)
				{
					disn[2]=9;
					disn[3]--;
					if(disn[3]==-1) disn[3]=0;
				}
			}
		}
		Out_4094(disn);
	}
	if(k3==0)
	{
		Delay10ms(1);
		if(k3==0)
		{
			disn[4]++;
			if(disn[4]==10) 
			{
				disn[5]++;
				disn[4]=0;
				if(disn[5]==10)
				{
					disn[6]++;
					disn[5]=0;
					if(disn[6]==0) disn[6]=0;
				}
			}
		}
			Out_4094(disn);
		
	}
	if(k4==0)
	{
		Delay10ms(1);
		if(k4==0)
		{
			disn[4]--;
			if(disn[4]==-1)
			{
				disn[4]=9;
				disn[5]--;
				if(disn[5]==-1)
				{
					disn[5]=9;
					disn[6]--;
					if(disn[6]==-1) disn[6]=0;
				}
			}
		}
		Out_4094(disn);
	}	

}


		  			

⌨️ 快捷键说明

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