51 single-chip computer fourth---matrix keyboard

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.