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

📄 1275.c

📁 51单片机C程序
💻 C
字号:
//在上题的基础上,用另外三个独立键盘实现按下第一个时计时
//停止,按下第二个时计时开始,按下第三个是计数值清零从头开始。

#include<reg52.h>
#define uc unsigned char
#define ui unsigned int
sbit L4=P3^4;
sbit L5=P3^5;
sbit L6=P3^6;
sbit L7=P3^7;
sbit dus=P2^6;
sbit wes=P2^7;
uc code table[]={
0x3f,0x06,0x5b,0x4f,0x66,0x6d,
0x7d,0x07,0x7f,0x6f,0x77};
uc code tableh[]={
0xbf,0x86,0xdb,0xcf,0xe6,0xed,
0xfd,0x87,0xff,0xef,0xf7};
uc a2,a1,a0,count;
ui num;
display(uc,uc,uc);
delay(uc);
void main()
{
	EA=1;
	ET1=1;
	TMOD=0x10;
	TH1=(65536-5000)/256;
	TL1=(65536-5000)%256;
	TR1=1;
	while(1)
	{		
		if(count==20)
		{		
			count=0;
			num++;
			if(num==999)num=0;}	
			if(L4==0)
            {
				delay(30);
				if(L4==0)
				TR1=0;
				while(!L4)
	            display(a2,a1,a0);
				TR1=1;
			}
			if(L5==0)
	        {
	            delay(30);
				if(L5==0)TR1=0;				
				while(!L5)				
				display(a2,a1,a0);					
			}
			if(L6==0)
			{
				delay(30);
				if(L6==0)TR1=1;       			
		        while(!L6)
		        display(a2,a1,a0);
	        }	
        	if(L7==0)
			{
				delay(30);
				if(L7==0)
				num=0;				
	            while(!L7)
				{a2=num/100;
				a1=num%100/10;
				a0=num%100%10;
				display(a2,a1,a0);}				
				TR1=1;
			}
	
			
		a2=num/100;
		a1=num%100/10;
		a0=num%100%10;
		display(a2,a1,a0);		
	}
}
delay(uc x)
{
	uc i,j;
	for(i=20;i>0;i--)
	for(j=x;j>0;j--);
}
void time1() interrupt 3 using 1
{
    TH1=(65536-5000)/256;
	TL1=(65536-5000)%256;
	count++;
}
display(uc bi,uc si,uc ge)
{
P0=0xff;
wes=1;
wes=0;

P0=table[bi];
dus=1;
dus=0;
P0=0xfe;
wes=1;
wes=0;
delay(1);

P0=0xff;
wes=1;
wes=0;

P0=tableh[si];
dus=1;
dus=0;
P0=0xfd;
wes=1;
wes=0;
delay(1);

P0=0xff;
wes=1;
wes=0;

P0=table[ge];
dus=1;
dus=0;
P0=0xfb;
wes=1;
wes=0;
delay(1);
}

⌨️ 快捷键说明

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