Schematic diagram:
Principle:
Similar to the standalone keyboard
/******************************************************************************** Experiment Name: Matrix Keyboard Experiment * Use of IO: Digital tube using P0 matrix keyboard Using the P3* experiment effect: Displays the key values of the standalone keyboard * Note: *******************************************************************************/#in Clude <reg52.h> #include <intrins.h> #define gpio_led p2#define gpio_dig p0#define gpio_key p1#define UINT unsigned int#define uchar unsigned charsbit k1=p3^1;sbit lsa=p2^2;sbit lsb=p2^3;sbit Lsc=p2^4;uchar key_value;unsigned Char Code dig_code[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};void Delay10ms (); void KeyDown (); void Main () {lsa=0; lsb=0; Lsc=0;while (1) {KeyDown (); Gpio_dig=dig_code[key_value];}} void Delay10ms () {Uchar i=38,j=130; while (i--) while (j--); } void KeyDown () {char n=0; Gpio_key=0x0f;if (gpio_key!=0x0f) {delay10ms (); if (gpio_key!=0x0f) {Gpio_key=0x0f;switch (Gpio_key) {case (0x07): KEY_ Value=0;break;case (0x0b): Key_value=1;break;case (0x0d): Key_value=2;break;case (0x0e): KEY_value=3;break;} Gpio_key=0xf0;switch (Gpio_key) {case (0x70): Key_value+=0;break;case (0xb0): Key_value+=4;break;case (0xd0): KEY_ Value+=8;break;case (0XE0): Key_value+=12;break;} while ((n<50) && (gpio_key!=0xf0)) {delay10ms (); ++n;}}}}
51 single-chip computer fourth---matrix keyboard