51 single chip microcomputer digital tube and matrix keyboard

Source: Internet
Author: User

Use 4*4 's matrix keyboard and a digital tube

Encode 0-f characters on the 4*4 matrix keyboard, and a digital tube to display the characters entered on each keyboard.

4*4 keyboard Detection program, press the key after the corresponding code displayed in the digital tube #include<reg51.h>typedef unsigned char UINT8; UINT8 i=100; UINT8 j,k,temp,key;void Delay (unsigned char i) {for (j=i;j>0;j--) for (k=125;k>0;k--);} UINT8 Code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};void Display (unsigned char num) {P0=table[num];}                                                                                                     void init_led () {P0 = 0x00;} void Main () {while (1) {P1 = 0xef;temp = P1;temp = Temp&0xf0;if (temp! = 0xf0) {temp = P1;switch (temp) {case 0xe   e:key=0;  Break   Case 0xed:key=1;  Break   Case 0xeb:key=2;  Break   Case 0xe7:key=3;  Break Default:break;} Display (key); P1=0xfe;}   P1 = 0xdf;temp = P1;temp = Temp&0x0f;if (temp! = 0x0f) {temp = P1;switch (temp) {Case 0xde:key = 4;  Break   Case 0xdd:key = 5;  Break   Case 0xdb:key = 6;  Break   Case 0xd7:key = 7;  Break Default:break; } display (key);} p1=0xbf;temp=p1;temp=Temp&0x0f;if (temp! = 0x0f) {Temp=p1;switch (temp) {case 0xbe:key=8;  Break   Case 0xbd:key=9;  Break   Case 0xbb:key=10;  Break   Case 0xb7:key=11;  Break Default:break;} Display (key);}   P1=0x7f;temp=p1;temp=temp&0x0f;if (temp!=0x0f) {Temp=p1;switch (temp) {case 0x7e:key=12;  Break   Case 0x7d:key=13;  Break   Case 0x7b:key=14;  Break   Case 0x77:key=15;    Break Default:break;} Display (key);}}}
This has a bug that every time you enter the digital tube is not empty but the reality of "0" this is not resolved.



51 single chip microcomputer digital tube and matrix keyboard

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.