單片機(jī)鍵盤(pán)程序(4×4矩陣式)
7. C語(yǔ)言源程序
#include AT89X51.H>
unsigned char code table[]={0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
unsigned char temp;
unsigned char key;
unsigned char i,j;
void main(void)
{
while(1)
{
P3=0xff;
P3_4=0;
temp=P3;
temp=temp 0x0f;
if (temp!=0x0f)
{
for(i=50;i>0;i--)
for(j=200;j>0;j--);
temp=P3;
temp=temp 0x0f;
if (temp!=0x0f)
{
temp=P3;
temp=temp 0x0f;
switch(temp)
{
case 0x0e:
key=7;
break;
case 0x0d:
key=8;
break;
case 0x0b:
key=9;
break;
case 0x07:
key=10;
break;
}
temp=P3;
P1_0=~P1_0;
P0=table[key];
temp=temp 0x0f;
while(temp!=0x0f)
{
temp=P3;
temp=temp 0x0f;
}
}
}
P3=0xff;
P3_5=0;
temp=P3;
temp=temp 0x0f;
if (temp!=0x0f)
{
for(i=50;i>0;i--)
for(j=200;j>0;j--);
temp=P3;
temp=temp 0x0f;
if (temp!=0x0f)
{
temp=P3;
temp=temp 0x0f;
switch(temp)
{
case 0x0e:
key=4;
break;
case 0x0d:
key=5;
break;
case 0x0b:
key=6;
break;
case 0x07:
key=11;
break;
}
temp=P3;
P1_0=~P1_0;
P0=table[key];
temp=temp 0x0f;
while(temp!=0x0f)
{
temp=P3;
temp=temp 0x0f;
}
}
}
P3=0xff;
P3_6=0;
temp=P3;
temp=temp 0x0f;
if (temp!=0x0f)
{
for(i=50;i>0;i--)
for(j=200;j>0;j--);
temp=P3;
temp=temp 0x0f;
if (temp!=0x0f)
{
temp=P3;
temp=temp 0x0f;
switch(temp)
{
case 0x0e:
key=1;
break;
case 0x0d:
key=2;
break;
case 0x0b:
key=3;
break;
case 0x07:
key=12;
break;
}
temp=P3;
P1_0=~P1_0;
P0=table[key];
temp=temp 0x0f;
while(temp!=0x0f)
{
temp=P3;
temp=temp 0x0f;
}
}
}
P3=0xff;
P3_7=0;
temp=P3;
temp=temp 0x0f;
if (temp!=0x0f)
{
for(i=50;i>0;i--)
for(j=200;j>0;j--);
temp=P3;
temp=temp 0x0f;
if (temp!=0x0f)
{
temp=P3;
temp=temp 0x0f;
switch(temp)
{
case 0x0e:
key=0;
break;
case 0x0d:
key=13;
break;
case 0x0b:
key=14;
break;
case 0x07:
key=15;
break;
}
temp=P3;
P1_0=~P1_0;
P0=table[key];
temp=temp 0x0f;
while(temp!=0x0f)
{
temp=P3;
temp=temp 0x0f;
}
}
}
}
}
DIY機(jī)械鍵盤(pán)相關(guān)社區(qū):機(jī)械鍵盤(pán)DIY
評(píng)論