首页 > 其他分享 >06-矩阵键盘

06-矩阵键盘

时间:2022-12-25 10:46:10浏览次数:40  
标签:06 矩阵 键盘 while num key C3 C2 display

#include "reg52.h"

sfr P4 = 0xc0;

sbit R1 = P3^0;
sbit R2 = P3^1;
sbit R3 = P3^2;
sbit R4 = P3^3;

sbit C4 = P3^4;
sbit C3 = P3^5;
sbit C2 = P4^2;
sbit C1 = P4^4;

unsigned char code table[] = 
{
	0xc0,//0
	0xf9,//1
	0xa4,//2
	0xb0,//3
	0x99,//4
	0x92,//5
	0x82,//6
	0xf8,//7
	0x80,//8
	0x90,//9
	0x88,//A
	0x83,//B
	0xc6,//C
	0xa1,//D
	0x86,//E
	0x8e,//F
	0xbf,//-
	0x7f//.
};

void HC138(unsigned char n)
{
	switch(n)
	{
		case 4:
			P2 = (P2&0x1f) | 0x80;
		break;
		case 5:
			P2 = (P2&0x1f) | 0xa0;
		break;
		case 6:
			P2 = (P2&0x1f) | 0xc0;
		break;
		case 7:
			P2 = (P2&0x1f) | 0xe0;
		break;
		
	}
}

void display(unsigned char val)
{
	HC138(6);
	P0 = 0x01;
	HC138(7);
	P0 = table[val];
	
}

unsigned char key_num = 0;
void scan()
{
	R1 = 0;
	R2 = 1;
	R3 = 1;
	R4 = 1;
	
	C1 = 1;
	C2 = 1;
	C3 = 1;
	C4 = 1;
	if(C1 == 0)
	{
		while(C1 == 0);
		key_num = 0;
		display(key_num);
	}
	else if(C2 == 0)
	{
		while(C2 == 0);
		key_num = 1;
		display(key_num);
	}
	else if(C3 == 0)
	{
		while(C3 == 0);
		key_num = 2;
		display(key_num);
	}
	else if(C4 == 0)
	{
		while(C4 == 0);
		key_num = 3;
		display(key_num);
	}
	
	R1 = 1;
	R2 = 0;
	R3 = 1;
	R4 = 1;
	
	C1 = 1;
	C2 = 1;
	C3 = 1;
	C4 = 1;
	if(C1 == 0)
	{
		while(C1 == 0);
		key_num = 4;
		display(key_num);
	}
	else if(C2 == 0)
	{
		while(C2 == 0);
		key_num = 5;
		display(key_num);
	}
	else if(C3 == 0)
	{
		while(C3 == 0);
		key_num = 6;
		display(key_num);
	}
	else if(C4 == 0)
	{
		while(C4 == 0);
		key_num = 7;
		display(key_num);
	}
	
	R1 = 1;
	R2 = 1;
	R3 = 0;
	R4 = 1;
	
	C1 = 1;
	C2 = 1;
	C3 = 1;
	C4 = 1;
	if(C1 == 0)
	{
		while(C1 == 0);
		key_num = 8;
		display(key_num);
	}
	else if(C2 == 0)
	{
		while(C2 == 0);
		key_num = 9;
		display(key_num);
	}
	else if(C3 == 0)
	{
		while(C3 == 0);
		key_num = 10;
		display(key_num);
	}
	else if(C4 == 0)
	{
		while(C4 == 0);
		key_num = 11;
		display(key_num);
	}
	
	R1 = 1;
	R2 = 1;
	R3 = 1;
	R4 = 0;
	
	C1 = 1;
	C2 = 1;
	C3 = 1;
	C4 = 1;
	if(C1 == 0)
	{
		while(C1 == 0);
		key_num = 12;
		display(key_num);
	}
	else if(C2 == 0)
	{
		while(C2 == 0);
		key_num = 13;
		display(key_num);
	}
	else if(C3 == 0)
	{
		while(C3 == 0);
		key_num = 14;
		display(key_num);
	}
	else if(C4 == 0)
	{
		while(C4 == 0);
		key_num = 15;
		display(key_num);
	}
}

void main()
{
	while(1)
	{
		scan();
	}
}

 

标签:06,矩阵,键盘,while,num,key,C3,C2,display
From: https://www.cnblogs.com/Unclesundada/p/17003739.html

相关文章

  • 矩阵乘法的优化
    1.矩阵乘法计算的优化方法小记之前逛知乎的时候经常看到有人对julia,numpy(python),ndarray(rust),openblas,blas,lapack的矩阵乘法速度或者其它矩阵操作的速度进行比较,因......
  • 每日食词—day060
    layoutn.布局、设计、布置balancen. v.平衡、均衡、天平upgradev. n. adj. adv.升级、升级版、系统升级、增加、提高directoriesn.目录、计算机文件或程......
  • 蓝桥-13届-C++-B组-省赛-F题-统计子矩阵
    直达链接主要解题思路分为两个部分,1是构造二维前缀和计算矩阵和,降低每次求和的时间复杂度;2是对所有子矩阵的遍历求和过程,因为需要两个坐标,遍历4个行/列值,4层for循环时间复......
  • 力扣-304-二维区域和检索-矩阵不可变
    classNumMatrix{private: vector<vector<int>>prefixSum;public: NumMatrix(vector<vector<int>>&matrix){ intn=matrix.size(); intm=matrix[0].size(......
  • 【数据结构】利用Python手把手带你自定义矩阵
    前言什么是矩阵矩阵,Matrix。在数学上,矩阵是指纵横排列的二维数据表格,最早来自于方程组的系数及常数所构成的方阵。这一概念由19世纪英国数学家凯利首先提出。矩阵是高等代数......
  • 省选06. 分治
    CF1442DSum设\(dp(i,j)\)表示前\(i\)个数组选\(j\)个元素的最大值。\[dp(i,j)=\max_{k=0}^jdp(i-1,k)+sum(i,k)\]因为数组内的元素单调不降,因此有一个结论,只有一......
  • T1408 矩阵嵌套(DAG 记忆化搜索)
    T1408矩阵嵌套​ 有n个矩阵,每个矩阵有长x和宽y。我们定义矩阵A可以嵌套在矩阵B中:A.x>B.x且A.y>B.y或者A.x>B.y且A.y>B.x。我们现在要找一个最长......
  • ts06_ts的编译选项1
    tsconfig.json是ts编译器的配置文件,ts编译器可以根据它的信息来对代码进行编译。可以执行tsc--init命令自动生成常用的配置选项:include:定义希望被编译文件所在的目......
  • Day19_06_Vue教程之Vue实例的生命周期
    Vue教程之Vue实例的生命周期一.什么是生命周期Vue实例有一个完整的生命周期,也就是从开始创建、初始化数据、编译模板、挂载DOM、渲染→更新→渲染、卸载等一系列过程,我们......
  • UVA10641 照亮体育馆 Barisal Stadium
    #include<iostream>#include<cstring>#include<cmath>#include<algorithm>usingnamespacestd;#definevecpointconstdoubleeps=1e-6;constintN=1......