In the keyboard circuit, there is this line and this thing,
Line AND and Line OR: A line and a switch, one end is high level and the other end is low level. When the switch is closed, the entire line will become low level. In general, there is a line AND relationship. As long as one end is low level and the switch is closed, the entire line will be pulled low. This is line AND; one end is Z (high configuration). After the switch is closed, the other end is high level and the entire line is high and low level, and vice versa. This is line OR;
How to program: First, P3=11110000 (11110000 from bottom to top in the figure), assuming that S1 is pressed, the upper four bits become 1110 (line AND) (ignore the lower four bits). At this time, you have determined that a key in the first column of the keyboard is pressed; then set P3=11101111, change the lower four bits to 1 (the upper four bits remain unchanged), and you have not released the key yet, because of line AND, P3=11101110; (To determine whether the key is pressed: use &0xf0)
#include #define uchar unsigned char #define uint unsigned int unsigned char code smg_du[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00}; unsigned char code smg_we[]={0x08,0x18,0x28,0x38,0x48,0x58,0x68,0x78}; //************************************************ //Delay function, at 12MHz crystal frequency //About 50us delay //************************************************ void delay_50us(uint t) { uchar j; for(;t>0;t--) for(j=19;j>0;j--); } //************************************************ //Delay function, at 12MHz crystal frequency //About 50ms delay //************************************************ void delay_50ms(uint t) { uint j; for(;t>0;t--) for(j=6245;j>0;j--); } void main() { uchar key_l,key_h; uchar key; while(1) { P3=0xf0;//11110000 key_l=P3; key_l=key_l&0xf0; //Determine whether the key is pressed if(key_l!=0xf0) { delay_50us(100);//debounce if(key_l!=0xf0)//Judge again { key_l=P3&0xf0; key_l=key_l|0x0f;//11101111 (prepare to check the row) P3=key_l; key_h=P3; key_h=key_h&0x0f;//00001110 (ignore the column) key_l=key_l&0xf0;//11100000 (ignore the line) key=key_h+key_l; //11101110 } } switch (key) { case 0xee:P1=smg_du[0];break; case 0xde:P1=smg_du[1];break; case 0xbe:P1=smg_du[2];break; case 0x7e:P1=smg_du[3];break; case 0xed:P1=smg_du[4];break; case 0xdd:P1=smg_du[5];break; case 0xbd:P1=smg_du[6];break; case 0x7d:P1=smg_du[7];break; case 0xeb:P1=smg_du[8];break; case 0xdb:P1=smg_du[9];break; case 0xbb:P1=smg_du[10];break; case 0x7b:P1=smg_du[11];break; case 0xe7:P1=smg_du[12];break; case 0xd7:P1=smg_du[13];break; case 0xb7:P1=smg_du[14];break; case 0x77:P1=smg_du[15];break; } } }
Previous article:"Beginner's C51 Self-study Notes" PS/2
Next article:"Beginner's C51 Self-study Notes" - Preliminary understanding of 89C51
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Detailed explanation of intelligent car body perception system
- How to solve the problem that the servo drive is not enabled
- Why does the servo drive not power on?
- What point should I connect to when the servo is turned on?
- How to turn on the internal enable of Panasonic servo drive?
- What is the rigidity setting of Panasonic servo drive?
- How to change the inertia ratio of Panasonic servo drive
- What is the inertia ratio of the servo motor?
- Is it better for the motor to have a large or small moment of inertia?
- What is the difference between low inertia and high inertia of servo motors?
- BlueNRG-2 OTA upgrade causes bricking issue
- Chapter 4: Use of GD32L23x Timer
- Common RF coaxial connectors
- Tonghui TH2817A 100K precision LCR digital bridge disassembly and light maintenance
- 04 External interrupt and timer PWM
- Use an old Kindle to create a dashboard for your life
- If the MPU9250 is placed vertically in the entire system, how should the direction matrix be modified?
- What are the practical application scenarios of 5G industrial applications?
- Why do voice chips have malfunctions?
- consult