51蛋骗鸡显示矩阵按键的16位二进制和定义值的二进制(以及4*4电路接法32按键综合扫描驱动)

//缘由https://bbs.csdn.net/topics/396577304?page=1#post-411560687    示例工程下载

#include "reg52.h"
bit k=0;//标记
unsigned char code smgduan[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}; //共阴0~15
unsigned char code ShaoMiaoZhi[]={238,237,235,231,222,221,219,215,190,189,187,183,126,125,123,119};
unsigned char JianPanShaoMiao(/*使用行列反转扫描法*/)
{	
	unsigned char H=15,L=240,Ys=0;
	P1=15;
	if(P1!=15)
	{		
		while(++Ys);//消抖
		H=P1;
		P1=240;
		L=P1;
		while(P1!=240);
	}
	P1 = 255;
	return (H+L);
}
unsigned char JianPanQuZhi(/*定义按钮*/)
{	
	unsigned char Jian_Zhi=0,LinShi=JianPanShaoMiao();
	if(LinShi==255)return LinShi;else//减小对延时影响提高运行效率
	while(LinShi!=ShaoMiaoZhi[Jian_Zhi])if(++Jian_Zhi > 15)break;//if(LinShi!=255)
	return Jian_Zhi;
}
void main()
{//缘由https://bbs.csdn.net/topics/396577304?page=1#post-411560687
	unsigned char jz=0,zhi=0,wei=1,lx=0;//键值 位 轮询
	unsigned int Ys=47474;
	while(1)
	{
		jz=JianPanQuZhi();
		if(jz!=255)zhi=jz;
		if(--Ys==0)
		{
			P3=wei;if(!(wei*=2)){++wei;k=~k;}//数码管动态显示
			P2=~smgduan[zhi];//数码管静态显示
			if(++zhi>15)zhi=0;
			Ys=47474;
		}
	}
}

51蛋骗鸡显示矩阵按键的16位二进制和定义值的二进制(以及4*4电路接法32按键综合扫描驱动)

#include "reg52.h"
bit k=0;//标记
unsigned char code smgduan[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}; //共阴0~15
unsigned char code ShaoMiaoZhi[]={238,237,235,231,222,221,219,215,190,189,187,183,126,125,123,119};
unsigned char JianPanShaoMiao(/*使用行列反转扫描法*/)
{	
	unsigned char H=15,L=240,Ys=0;
	P1=15;
	if(P1!=15)
	{		
		while(++Ys);//消抖
		H=P1;
		P1=240;
		L=P1;
		while(P1!=240);
	}
	P1 = 255;
	return (H+L);
}
unsigned char JianPanQuZhi(/*定义按钮*/)
{	
	unsigned char Jian_Zhi=0,LinShi=JianPanShaoMiao();
	if(LinShi==255)return LinShi;else//减小对延时影响提高运行效率
	while(LinShi!=ShaoMiaoZhi[Jian_Zhi])if(++Jian_Zhi > 15)break;//if(LinShi!=255)
	return Jian_Zhi;
}
void main()
{//缘由https://bbs.csdn.net/topics/396577304?page=1#post-411560687
	unsigned char jz=0,zhi=0,wei=1,ls=zhi,er=0;//键值 位 二进制
	unsigned int Ys=47;
	while(1)
	{
		jz=JianPanQuZhi();
		if(jz!=255)ls=zhi=jz;
		if(--Ys==0)
		{
			if(ls)
			{
				P3=wei;
				if(!(wei*=2))++wei;//数码管动态显示
				er=ls-(ls/2)*2;
				ls/=2;
			}
			else
			{
				er=0;
				P3=wei;
				wei=1;
				ls=zhi;
			}
			P2=~smgduan[er];//数码管静态显示
			Ys=47;
		}
	}
}

矩阵按键的二进制编码直接取数组中的值即可:        if(jz!=255)ls=zhi=ShaoMiaoZhi[jz];

51蛋骗鸡显示矩阵按键的16位二进制和定义值的二进制(以及4*4电路接法32按键综合扫描驱动)

#include "reg52.h"
bit k=0;//标记
unsigned char code smgduan[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}; //共阴0~15
unsigned char code ShaoMiaoZhi[]={238,237,235,231,222,221,219,215,190,189,187,183,126,125,123,119,1,2,4,8,16,32,64,128,254,253,251,247,239,223,191,127};
unsigned char JianPanShaoMiao(/*使用行列反转扫描法+独立16按键共32按键*/)
{	
	unsigned char H=15,L=240,Ys=0,zhi=H+L;
	P1=zhi;
	if(P1!=zhi){while(++Ys);zhi=P1;while(zhi==P1);return zhi;}
	else P1=zhi+1;//~zhi;
	if(P1!=~zhi){while(++Ys);zhi=P1;while(zhi==P1);return zhi;}
	P1=15;
	if(P1!=15)
	{		
		while(++Ys);//消抖
		H=P1;
		P1=240;
		L=P1;
		while(P1!=240);
	}
	P1 = 255;
	return (H+L);
}
unsigned char JianPanQuZhi(/*定义按钮*/)
{	
	unsigned char Jian_Zhi=0,LinShi=JianPanShaoMiao();
	if(LinShi==255)return LinShi;else//减小对延时影响提高运行效率
	while(LinShi!=ShaoMiaoZhi[Jian_Zhi])if(++Jian_Zhi > 31)break;//if(LinShi!=255)
	return Jian_Zhi;
}
void main()
{//缘由https://bbs.csdn.net/topics/396577304?page=1#post-411560687
	unsigned char jz=0,zhi=0,wei=1,ls=zhi,er=0;//键值 位 二进制
	unsigned int Ys=747;
	while(1)
	{
		if(--Ys==0)
		{
			jz=JianPanQuZhi();
			if(jz!=255)ls=zhi=jz;
			if(ls)
			{
				P3=wei;
				if(!(wei*=2))++wei;//数码管动态显示
				er=ls-(ls/2)*2;
				ls/=2;
			}
			else
			{
				er=ls;
				P3=wei;
				wei=1;
				ls=zhi;
			}
			P2=~smgduan[er];//数码管静态显示
			Ys=747;
		}
	}
}

51蛋骗鸡显示矩阵按键的16位二进制和定义值的二进制(以及4*4电路接法32按键综合扫描驱动)

上一篇:政治献金案例


下一篇:MySQL集群架构之主从模式并行复制实践