当前位置:网站首页>(5) Matrix key
(5) Matrix key
2022-06-26 08:19:00 【I love notes】
In this chapter, we mainly write the contents of matrix keyboard , The principle of matrix keyboard is basically similar to that of independent keys , Just a little introduction to the whole principle , In this chapter, we press one of the matrix keys , Then output the corresponding key value on the nixie tube .
1. About keys
You can see the contents of the previous buttons .
2. Hardware
First, my matrix keyboard is shown below , We first put P1 Interfaces are divided into two groups ,P0 To P3 Group together ,P4 To the plate into a group .

We can start by giving P1^0 A low level , And then to P1^1 To P1^7 High level , Then we test P1^4 To P1^7 The level state of , If a key is pressed , Then you can detect P1^4 To P1^7 On a certain GPIO The pin becomes low , We can detect that the button is pressed .
3 Software
This chapter mainly uses the contents of the previous nixie tube and matrix keys in this chapter , The procedure is as follows :
#include "reg52.h"
#include "key.h"
extern int key_val;
void key_scan(){
int temp;
P1 = 0xfe;
temp = P1;
temp &= 0xf0;
if(temp != 0xf0){
delay(10);
P1= 0xfe;
temp = P1;
temp &= 0xf0;
if(temp != 0xf0){
switch(temp){
case 0x70:
key_val = 3;
break;
case 0xb0:
key_val = 7;
break;
case 0xd0:
key_val = 11;
break;
case 0xe0:
key_val = 15;
break;
}
}
while(temp != 0xf0){
temp = P1;
temp &= 0xf0;
}
}
P1 = 0xfd;
temp = P1;
temp &= 0xf0;
if(temp != 0xf0){
delay(10);
P1 = 0xfd;
temp = P1;
temp &= 0xf0;
if(temp != 0xf0){
switch(temp){
case 0x70:
key_val = 2;
break;
case 0xb0:
key_val = 6;
break;
case 0xd0:
key_val = 10;
break;
case 0xe0:
key_val = 14;
break;
}
}
while(temp != 0xf0){
temp = P1;
temp &= 0xf0;
}
}
P1 = 0xfb;
temp = P1;
temp &= 0xf0;
if(temp != 0xf0){
delay(10);
P1 = 0xfb;
temp = P1;
temp &= 0xf0;
if(temp != 0xf0){
switch(temp){
case 0x70:
key_val = 1;
break;
case 0xb0:
key_val = 5;
break;
case 0xd0:
key_val = 9;
break;
case 0xe0:
key_val = 13;
break;
}
}
while(temp != 0xf0){
temp = P1;
temp &= 0xf0;
}
}
P1 = 0xf7;
temp = P1;
temp &= 0xf0;
if(temp != 0xf0){
delay(10);
P1 = 0xf7;
temp = P1;
temp &= 0xf0;
if(temp != 0xf0){
switch(temp){
case 0x70:
key_val = 0;
break;
case 0xb0:
key_val = 4;
break;
case 0xd0:
key_val = 8;
break;
case 0xe0:
key_val = 12;
break;
}
}
while(temp != 0xf0){
temp = P1;
temp &= 0xf0;
}
}
}The main function to be called is as follows :
#include "reg52.h"
#include "key.h"
sbit LSA = P2^2;
sbit LSB = P2^3;
sbit LSC = P2^4;
int key_val = 0;
unsigned char smgduan[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};// Show 0~F Value
void delay(int xms){
int i;
int j;
for(i = 0;i < xms;i++){
for(j = 0; j < 100;j++){
;
}
}
}
void main(){
LSA = 0; LSB = 0;LSC = 0;
while(1){
key_scan();
P0 = smgduan[key_val];
delay(10);
}
}The contents of the header file are as follows :
#ifndef _KEY_H_
#define _KEY_H_
extern int key_val;
void key_scan();
void delay(int xms);
#endif边栏推荐
- PCB miscellaneous mail
- Oracle database self study notes
- Teach you a few tricks: 30 "overbearing" warm words to coax girls, don't look regret!
- Understanding of closures
- I want to open a stock account at a discount. How do I do it? Is it safe to open a mobile account?
- Jz-063- median in data stream
- Oracle 19C local listener configuration error - no listener
- Automatic backup of MySQL database in the early morning with Linux
- 2: String insert
- What if the service in Nacos cannot be deleted?
猜你喜欢

Chapter VIII (classes and objects)

MySQL insert Chinese error

How to debug plug-ins using vs Code

Example of offset voltage of operational amplifier

Detailed explanation and code implementation of soft voting and hard voting mechanism in integrated learning

Read excel table and render with FileReader object

JS precompile - Variable - scope - closure

Chapter VI (pointer)

Opencv mouse event + interface interaction drawing rectangle polygon selection ROI

Reflection example of ads2020 simulation signal
随机推荐
RF filter
Chapter 4 (functions and preprocessing)
What is Qi certification Qi certification process
Uploading pictures with FileReader object
1. error using XPath to locate tag
Use intent to shuttle between activities -- use implicit intent
Design of reverse five times voltage amplifier circuit
Batch modify file name
Discrete device ~ resistance capacitance
STM32 based d18s20 (one wire)
When loading view, everything behind is shielded
Assembly led on
JWT in go
Chapter VIII (classes and objects)
Chapter VI (pointer)
h5 localStorage
swift 代码实现方法调用
Automatic backup of MySQL database in the early morning with Linux
Read excel table and render with FileReader object
Database learning notes II