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

📄 anjianshuzi.c

📁 C51 程序练习
💻 C
字号:
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar num,wela,temp;
sbit key1=P3^0;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c};

void delay(uint z);

void main()
{
	wela=0;//所以数码管都亮
	P1=wela;
	while(1)
		{
			P3=0xfc;
			temp=P3;
			temp=temp&0xf0;
			while(temp!=0xf0) //有键按下
				{
					delay(5);//延时去抖动
					temp=P3;
					temp=temp&0xf0;
					while(temp!=0xf0)
					{
						temp=P3;//检验P3口
					switch(temp)
						{
							case 0xec:num=1;
								break;
							case 0xdc:num=2;
								break;
							case 0xbc:num=3;
								break;
							case 0x7c:num=4;
								break;
						}
					while(temp!=0xf0)//松手检测
						{	
							temp=P0;
							temp=temp&0xf0;
						}
					P0=table[num-1];//显示
					}
				}


			P3=0xfa;
			temp=P3;
			temp=temp&0xf0;
			while(temp!=0xf0) //有键按下
				{
					delay(5);//延时去抖动
					temp=P3;
					temp=temp&0xf0;
					while(temp!=0xf0)
					{
						temp=P3;//检验P3口
					switch(temp)
						{
							case 0xea:num=5;
								break;
							case 0xda:num=6;
								break;
							case 0xba:num=7;
								break;
							case 0x7a:num=8;
								break;
						}
					while(temp!=0xf0)//松手检测
						{	
							temp=P0;
							temp=temp&0xf0;
						}
					P0=table[num-1];//显示
					}
				}

			P3=0xf6;//1111 0110
			temp=P3;
			temp=temp&0xf0;
			while(temp!=0xf0) //有键按下
				{
					delay(5);//延时去抖动
					temp=P3;
					temp=temp&0xf0;
					while(temp!=0xf0)
					{
						temp=P3;//检验P3口
					switch(temp)
						{
							case 0xe6:num=9;
								break;
							case 0xd6:num=10;
								break;
							case 0xb6:num=11;
								break;
							case 0x76:num=12;
								break;
						}
					while(temp!=0xf0)//松手检测
						{	
							temp=P0;
							temp=temp&0xf0;
						}
					P0=table[num-1];//显示
					}
				}
		
		}

}

void delay(uint z)//延时子程序
{
	uint x,y;
	for(x=z;x>0;x--)
		for(y=110;y>0;y--);
}

⌨️ 快捷键说明

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