块帮我看看 矩阵按键没变发
- #include<reg51.h>
- unsigned char gao,di;
- unsigned char key_value;
- unsigned int key[]={
- 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
- 0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
- void delay()
- { unsigned char i;
- TMOD=0x10;
- for(i=0;i<2;i++)
- {
- TH1=0x3c;
- TL1=0xb0;
- TR1=1;
- while(!TF1);
- TF1=0;
- }
- }
- void main()
- {
- while(1)
- { P1=0x0f;
- if(P1!=0x0f)
- {
- delay();
- if(P1!=0x0f)
- {
- P1=0x0f;di=P1;
-
- switch(di)
- {
- case 0x07: key_value=0;break;
- case 0x0b: key_value=1;break;
- case 0x0d: key_value=2;break;
- case 0x0e: key_value=3;break;
- default :break;
- }
- P1=0xf0;gao=P1;
- switch(gao)
- {
- case 0x70: key_value=0;break;
- case 0xb0: key_value=key_value+4;break;
- case 0xd0: key_value=key_value+8;break;
- case 0xe0: key_value=key_value+12;break;
- default :break;
- }
- while(1)
- {
- P2=~key[key_value];
- }
- }
- }
- }
- }
按键没变化 这个矩阵按键哪里出问题了?
P1=0x0f;di=P1;
di=0x0f? 可是下面没有case 0x0f?
不知道对不对,希望小编指正。
恩恩 是这样的的原因 今天重新写了个 还是不对 帮我看看按键还是没反应
#include<reg51.h>
unsigned char key[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
unsigned int keyvalue;
void keyscan();
void delay();
void main()
{
while(1)
{
keyscan();
P3=~key[keyvalue];
}
}
void keyscan()
{
unsigned int a;
P1=0x0f;
if(P1!=0x0f)
{
delay();
if(P1!=0x0f)
{
a=P1;
switch(a)
{
case 0x0e: keyvalue=0;break;
case 0x0d: keyvalue=1;break;
case 0x0b: keyvalue=2;break;
case 0x07: keyvalue=3;break;
}
}
}
P1=0xf0;
if(P1!=0xf0)
{
delay();
if(P1!=0xf0)
{
a=P1;
switch(a)
{
case 0xe0: keyvalue=keyvalue;break;
case 0xd0: keyvalue=keyvalue+4;break;
case 0xb0: keyvalue=keyvalue+8;break;
case 0x70: keyvalue=keyvalue+12;break;
}
}
}
}
void delay()
{
unsigned int c;
for(c=1;c>0;c--)
TMOD=0x10;
TH1=0xb1;
TL1=0xe0;
while(!TF1);
TF1=0;
}
恩恩 是这样的的原因 今天重新写了个 还是不对 帮我看看按键还是没反应
#include<reg51.h>
unsigned char key[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
unsigned int keyvalue;
void keyscan();
void delay();
void main()
{
while(1)
{
keyscan();
P3=~key[keyvalue];
}
}
void keyscan()
{
unsigned int a;
P1=0x0f;
if(P1!=0x0f)
{
delay();
if(P1!=0x0f)
{
a=P1;
switch(a)
{
case 0x0e: keyvalue=0;break;
case 0x0d: keyvalue=1;break;
case 0x0b: keyvalue=2;break;
case 0x07: keyvalue=3;break;
}
}
}
P1=0xf0;
if(P1!=0xf0)
{
delay();
if(P1!=0xf0)
{
a=P1;
switch(a)
{
case 0xe0: keyvalue=keyvalue;break;
case 0xd0: keyvalue=keyvalue+4;break;
case 0xb0: keyvalue=keyvalue+8;break;
case 0x70: keyvalue=keyvalue+12;break;
}
}
}
}
void delay()
{
unsigned int c;
for(c=1;c>0;c--)
TMOD=0x10;
TH1=0xb1;
TL1=0xe0;
while(!TF1);
TF1=0;
}
恩恩 是这样的的原因 今天重新写了个 还是不对 帮我看看按键还是没反应
#include<reg51.h>
unsigned char key[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
unsigned int keyvalue;
void keyscan();
void delay();
void main()
{
while(1)
{
keyscan();
P3=~key[keyvalue];
}
}
void keyscan()
{
unsigned int a;
P1=0x0f;
if(P1!=0x0f)
{
delay();
if(P1!=0x0f)
{
a=P1;
switch(a)
{
case 0x0e: keyvalue=0;break;
case 0x0d: keyvalue=1;break;
case 0x0b: keyvalue=2;break;
case 0x07: keyvalue=3;break;
}
}
}
P1=0xf0;
if(P1!=0xf0)
{
delay();
if(P1!=0xf0)
{
a=P1;
switch(a)
{
case 0xe0: keyvalue=keyvalue;break;
case 0xd0: keyvalue=keyvalue+4;break;
case 0xb0: keyvalue=keyvalue+8;break;
case 0x70: keyvalue=keyvalue+12;break;
}
}
}
}
void delay()
{
unsigned int c;
for(c=1;c>0;c--)
TMOD=0x10;
TH1=0xb1;
TL1=0xe0;
while(!TF1);
TF1=0;
}