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

📄 cs13-1.c

📁 《手把手教你学单片机的C程序设计》及实验程序
💻 C
字号:
#include <REG51.H>			
#define uchar unsigned char	
#define uint unsigned int		
uchar code SEG7[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar code ACT[4]={0xfe,0xfd,0xfb,0xf7};
uchar data shuzu[4];				
/*****************************************************************************/
uchar status;						
uchar temp,f;					
/********************************************************************/
void delay_1ms(void)						
{							
uint k;						
for(k=0;k<121;k++);				
}							
/*******************************************************************/
void dis_all(void)				
{		P0=SEG7[shuzu[0]];P2=ACT[0];
		delay_1ms();				
  		P0=SEG7[shuzu[1]];P2=ACT[1];
		delay_1ms();			
  		P0=SEG7[shuzu[2]];P2=ACT[2];
		delay_1ms();				
		P0=SEG7[shuzu[3]];P2=ACT[3];
		delay_1ms();			
}							
/*****************************************************************************/
void dis_shuzu0(void)				
{		P0=SEG7[f];P2=ACT[0];	
		delay_1ms();				
}								
/**********************************************************************/
void dis_shuzu1(void)				
{		P0=SEG7[f];P2=ACT[1];	
		delay_1ms();			
}								
/************************************************************************/
void dis_shuzu2(void)			
{		P0=SEG7[f];P2=ACT[2];	
		delay_1ms();				
}							
/***************************************************************************/
void dis_shuzu3(void)				
{		P0=SEG7[f];P2=ACT[3];	
		delay_1ms();			
}							
/***************************************************************************/
void key_s1(void)					
{							
P3=0xff;						
  if(P3==0xfb)					
  {if(temp>50)temp=0;			
 	if(temp==0)f++;			
	if(f>9)f=0;				
	temp++;					
	delay_1ms();					
  }							
}								
/******************************************************************************/							
void key_s2(void)					
{							
P3=0xff;						
  if(P3==0xf7)				
  {							
	switch (status)			
	{						
	case 1:shuzu[0]=f;break;	
		case 2:shuzu[1]=f;break;
		case 3:shuzu[2]=f;break;
		case 4:shuzu[3]=f;break;	
		default:break;		
	}						
  }							
}							
/****************************************************************/
void key_s4(void)				
{							
P3=0xff;							
	if(P3==0xdf)				
	 {if(temp>50)temp=0;			
 	if(temp==0)status++;		
	if(status>4)status=0;		
	temp++;					
	delay_1ms();				
  	 }						
}							
/*******************************************************************/
void main(void)				
{							
	while(1)					
	{						
  		key_s1();				
  		key_s2();			
  		key_s4();			
  			switch (status)		
   		{					
  				case 0:dis_all();break;
				case 1:dis_shuzu0();break;
				case 2:dis_shuzu1();break;
				case 3:dis_shuzu2();break;
				case 4:dis_shuzu3();break;
				default:break;	
	 	}					
 	}						
}							

⌨️ 快捷键说明

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