Matrix Keyboard Digital Tube

Source: Internet
Author: User
Tags xms

In the beginning of no digital display, the sequence is a matrix keyboard, followed by the digital tube 0~f,6 simultaneously digitally controlled static display.

Digital control and Matrix keyboard

First of all, the selection of the digital tube is closed to let the digital tube display no matter what the number. Then select all the digital tube, the next only need to select all the digital tube, the subsequent operation of the only need to send a segment of the data can be, and then enter while () cycle scanning keyboard is not kept pressed

#include <reg52.h>
#define UCHAR unsigned char
#define UINT unsigned int
Sbit dula=p2^6;
Sbit wela=p2^7;
Uchar Code table[]={
0X3F,0X06,0X5B,0X4F,
0X66,0X6D,0X7D,0X07,
0X7F,0X6F,0X77,0X7C,
0x39,0x5e,0x79,0x71
};
void delayms (UINT XMS)
{
UINT I,j;
for (i=xms;i>0;i--)
for (j=110;j>0;j--);
}
void display (Uchar num)
{
P0=table[num];
Dula=1;
dula=0;
}
void Matrixkeyscan ()
{
Uchar Temp,key;
P3=0xfe;
TEMP=P3;
temp=temp&0xf0;
if (temp!=0xf0)
{
Delayms (10);
TEMP=P3;
temp=temp&0xf0;
if (temp!=0xf0)
{
TEMP=P3;
Switch (temp)
{
Case 0xEE:
key=0;
Break
Case 0XDE:
Key=1;
Break
Case 0XBE:
key=2;
Break
Case 0X7E:
key=3;
Break
}
while (TEMP!=0XF0)
{
TEMP=P3;
temp=temp&0xf0;
}
Display (key);
}
}
P3=0XFD;
TEMP=P3;
temp=temp&0xf0;
if (temp!=0xf0)
{
Delayms (10);
TEMP=P3;
temp=temp&0xf0;
if (temp!=0xf0)
{
TEMP=P3;
Switch (temp)
{
Case 0xed:
key=4;
Break
Case 0XDD:
key=5;
Break
Case 0XBD:
key=6;
Break
Case 0X7D:
key=7;
Break
}
while (TEMP!=0XF0)
{
TEMP=P3;
temp=temp&0xf0;
}
Display (key);
}
}
P3=0XFB;
TEMP=P3;
temp=temp&0xf0;
if (temp!=0xf0)
{
Delayms (10);
TEMP=P3;
temp=temp&0xf0;
if (temp!=0xf0)
{
TEMP=P3;
Switch (temp)
{
Case 0XEB:
key=8;
Break
Case 0XDB:
key=9;
Break
Case 0XBB:
key=10;
Break
Case 0x7b:
key=11;
Break
}
while (TEMP!=0XF0)
{
TEMP=P3;
temp=temp&0xf0;
}
Display (key);
}
}
P3=0xf7;
TEMP=P3;
temp=temp&0xf0;
if (temp!=0xf0)
{
Delayms (10);
TEMP=P3;
temp=temp&0xf0;
if (temp!=0xf0)
{
TEMP=P3;
Switch (temp)
{
Case 0XE7:
key=12;
Break
Case 0XD7:
key=13;
Break
Case 0XB7:
key=14;
Break
Case 0X77:
key=15;
Break
}
while (TEMP!=0XF0)
{
TEMP=P3;
temp=temp&0xf0;
}
Display (key);
}
}
}


void Main ()
{
p0=0;
Dula=1;
dula=0;
p0=0;
Wela=1;
wela=0;
while (1)
{
Matrixkeyscan ();
}
}


Here are a few

P3=0xfe;
temp=p3;
temp=temp&0xf0;
if (temp!=0xf0)
{
delayms (ten);
temp=p3;
temp=temp&0xf0;
if (temp!=0xf0)
{  .........

P3=0xfe the 1th line is low and all the remaining lines are high

TEMP=P3 Read P3 The current state value is assigned to the temporary variable Temp

Temp=temp&0xf0 the temp with 0xf0 and then assigns the result to temp, mainly to infer if the high 4 bits of temp are 0. Assume that the high 4 bits of temp do not have 0. Then the result of his and 0xf0 "and" operation is still equal to 0xf0.temp's high 4-bit data is actually 4 columns of the matrix keyboard, so we can infer whether the first row of keys has been pressed by inferring whether the result of the 0xf0 operation is 0xf0.

if (temp!=0xf0) indicates that temp is the result of the above P3 port data and the 0xf0 "and" operation, assume that the result temp is not equal to 0xf0 to infer that a key was pressed.

Other than that

P3 Port All Pins

The rest of you want to reset the pin RES\VPD

and a EA\VPP.

Ale\prog

This is all, mine is AT89S52 (51 series)


Copyright notice: This article Bo Master original article. Blog, not reproduced without consent.

Matrix Keyboard Digital Tube

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.