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

📄 juzheng.c

📁 8051单片机矩阵键盘扫描程序(包括键盘的消抖和数码管的显示)
💻 C
字号:
#include<reg52.h>
unsigned char code tableduan[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xF8,
								0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
sbit suo=P3^6;
unsigned int temp,num;
void delay();
void init();
void main()
{   
	init();
		while(1)
   	 { 
		P1=0xf7;
	    temp=P1;
		temp=temp&0xf0;
		
	     while(temp!=0xf0)
		   {
			delay();
			temp=P1;
			temp=temp&0xf0;	
				while(temp!=0xf0)
					{
				      temp=P1;
					  switch(temp)
						 {
							case 0xe7:num=0;break;
							case 0xd7:num=1;break;	
							case 0xb7:num=2;break;
							case 0x77:num=3;break;
				      
						 };while(temp!=0xf0)
								{
								  temp=P1;
							      temp=temp&0xf0;
								};
							      suo=1;
								  P0=tableduan[num];	
								  //delay();
								  suo=0;	
							
					};		
							    	
			};				



		P1=0xfb;
	    temp=P1;
		temp=temp&0xf0;
	     while(temp!=0xf0)
		   {
			delay();
			temp=P1;
			temp=temp&0xf0;	
				while(temp!=0xf0)
					{
				      temp=P1;
					  switch(temp)
						 {
							case 0xeb:num=4;break;
							case 0xdb:num=5;break;	
							case 0xbb:num=6;break;
							case 0x7b:num=7;break;
				      
						 };while(temp!=0xf0)
								{
								  temp=P1;
							      temp=temp&0xf0;
								};

							      suo=1;
								  P0=tableduan[num];	
								  //delay();
								  suo=0;	
							
					};	
							    	
			};					



		P1=0xfd;
	    temp=P1;
		temp=temp&0xf0;
		
	     while(temp!=0xf0)
		   {
			delay();
			temp=P1;
			temp=temp&0xf0;	
				while(temp!=0xf0)
					{
				      temp=P1;
					  switch(temp)
						 {
							case 0xed:num=8;break;
							case 0xdd:num=9;break;	
							case 0xbd:num=10;break;
							case 0x7d:num=11;break;
				      
						 };while(temp!=0xf0)
								{
								  temp=P1;
							      temp=temp&0xf0;
								};

							      suo=1;
								  P0=tableduan[num];	
								  //delay();
								  suo=0;	
							
					};		
							    	
			};	

		P1=0xfe;
	    temp=P1;
		temp=temp&0xf0;
		
	     while(temp!=0xf0)
		   {
			delay();
			temp=P1;
			temp=temp&0xf0;	
				while(temp!=0xf0)
					{
				      temp=P1;
					  switch(temp)
						 {
							case 0xee:num=12;break;
							case 0xde:num=13;break;	
							case 0xbe:num=14;break;
							case 0x7e:num=15;break;
				      
						 };while(temp!=0xf0)
								{
								  temp=P1;
							      temp=temp&0xf0;
								};

							      suo=1;
								  P0=tableduan[num];	
								  //delay();
								  suo=0;	
							
					};		
							    	
			};					
								
	
    };

}

void delay()
{
	unsigned int a,b;
      for(a=50;a>0;a--)
		for(b=10;b>0;b--); 
}



void init()
{		suo=1;
		P2=0x00;suo=0;	
}

⌨️ 快捷键说明

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