当前位置:网站首页>Matrix keyboard scan (keil5)

Matrix keyboard scan (keil5)

2022-07-05 07:18:00 After reading thousands of books, you can pick them up and put

Copy and paste the kind that beginners don't need to use their brains

#include <STC15F2K60S2.H>
#include <intrins.h>
unsigned char code num[16]={
    0xc0,0xcf,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x98,0x88,0x80,0xc6,0xc0,0x86,0x8e};//0123456789abcd
sbit R1 = P3^0;
sbit R2 = P3^1;
sbit R3 = P3^2;
sbit R4 = P3^3;
sbit C1 = P3^4;
sbit C2 = P3^5;
sbit C3 = P3^6;
sbit C4 = P3^7;
/***********************************************/
void initsystem(unsigned char i)
{
    
	switch(i)
	{
    
		case 4:
			P2=0X8f&(P2|0xe0);
		break;
		case 5:
			P2=0xbf&(P2|0xe0);
		break;
		case 6:
			P2=0xdf&(P2|0xe0);
		break;
		case 7:
			P2=0xff&(P2|0xe0);
		break;
		case 0:
			P2=0x1f&(P2|0xe0);
		break;
	}
}
/*****************************************************/
unsigned char s;
void SMG_Display()
{
    
	initsystem(6);
	P0=0x01;
	initsystem(7);
	P0=num[s];
}
void Delay100ms()		//@11.0592MHz
{
    
	unsigned char i, j, k;

	_nop_();
	_nop_();
	i = 5;
	j = 52;
	k = 195;
	do
	{
    
		do
		{
    
			while (--k);
		} while (--j);
	} while (--i);
}
/*****************************************************/
void key_s()
{
    
	R1=0;
	R2=R3=R4=1;
	C1=C2=C3=C4=1;
	if(C1==0)
	{
    
		Delay100ms();
		if(C1==0)
		{
    
			s=0;
			SMG_Display();// The nixie tube first displays 0
		}
	}
	R1=0;
	R2=R3=R4=1;
	C1=C2=C3=C4=1;
	if(C2==0)
	{
    
		Delay100ms();
		if(C2==0)
		{
    
			s=1;
			SMG_Display();// The nixie tube first displays 1
		}
	}
	R1=0;
	R2=R3=R4=1;
	C1=C2=C3=C4=1;
	if(C3==0)
	{
    
		Delay100ms();
		if(C3==0)
		{
    
			s=2;
			SMG_Display();// The nixie tube first displays 2
		}
	}
	R1=0;
	R2=R3=R4=1;
	C1=C2=C3=C4=1;
	if(C4==0)
	{
    
		Delay100ms();
		if(C4==0)
		{
    
			s=3;
			SMG_Display();// The nixie tube first displays 3
		}
	}
	R2=0;
	R1=R3=R4=1;
	C1=C2=C3=C4=1;
	if(C1==0)
	{
    
		Delay100ms();
		if(C1==0)
		{
    
			s=4;
			SMG_Display();// The nixie tube first displays 4
		}
	}
	R2=0;
	R1=R3=R4=1;
	C1=C2=C3=C4=1;
	if(C2==0)
	{
    
		Delay100ms();
		if(C2==0)
		{
    
			s=5;
			SMG_Display();// The nixie tube first displays 5
		}
	}
	R2=0;
	R1=R3=R4=1;
	C1=C2=C3=C4=1;
	if(C3==0)
	{
    
		Delay100ms();
		if(C3==0)
		{
    
			s=6;
			SMG_Display();// The nixie tube first displays 6
		}
	}
	R2=0;
	R1=R3=R4=1;
	C1=C2=C3=C4=1;
	if(C4==0)
	{
    
		Delay100ms();
		if(C4==0)
		{
    
			s=7;
			SMG_Display();// The nixie tube first displays 7
		}
	}
	R3=0;
	R1=R2=R4=1;
	C1=C2=C3=C4=1;
	if(C1==0)
	{
    
		Delay100ms();
		if(C1==0)
		{
    
			s=8;
			SMG_Display();// The nixie tube first displays 8
		}
	}
	R3=0;
	R1=R2=R4=1;
	C1=C2=C3=C4=1;
	if(C2==0)
	{
    
		Delay100ms();
		if(C2==0)
		{
    
			s=9;
			SMG_Display();// The nixie tube first displays 9
		}
	}
	R3=0;
	R1=R2=R4=1;
	C1=C2=C3=C4=1;
	if(C3==0)
	{
    
		Delay100ms();
		if(C3==0)
		{
    
			s=10;
			SMG_Display();// The nixie tube first displays 10
		}
	}
	R3=0;
	R1=R2=R4=1;
	C1=C2=C3=C4=1;
	if(C4==0)
	{
    
		Delay100ms();
		if(C4==0)
		{
    
			s=11;
			SMG_Display();// The nixie tube first displays 11
		}
	}
	R4=0;
	R1=R2=R3=1;
	C1=C2=C3=C4=1;
	if(C1==0)
	{
    
		Delay100ms();
		if(C1==0)
		{
    
			s=12;
			SMG_Display();// The nixie tube first displays 12
		}
	}
		R4=0;
	R1=R2=R3=1;
	C1=C2=C3=C4=1;
	if(C2==0)
	{
    
		Delay100ms();
		if(C2==0)
		{
    
			s=13;
			SMG_Display();// The nixie tube first displays 13
		}
	}
	R4=0;
	R1=R2=R3=1;
	C1=C2=C3=C4=1;
	if(C3==0)
	{
    
		Delay100ms();
		if(C3==0)
		{
    
			s=14;
			SMG_Display();// The nixie tube first displays 14
		}
	}
	R4=0;
	R1=R2=R3=1;
	C1=C2=C3=C4=1;
	if(C4==0)
	{
    
		Delay100ms();
		if(C4==0)
		{
    
			s=15;
			SMG_Display();// The nixie tube first displays 15
		}
	}
}
void main()
{
    
	while(1)
	{
    
		key_s();
	}
}
原网站

版权声明
本文为[After reading thousands of books, you can pick them up and put ]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140558148657.html