4*4矩阵键盘控制8*8点阵显示程序:程序中有两个while(1)循环,死掉了,怎么改?
#include<reg52.h>#defineucharunsignedchar#defineuintunsignedintucharconstbiaozhi_2[]=...
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar const biaozhi_2[]={
0x80,0xe0,0x9c,0x13,0x9c,0xe0,0x80,0x00,//A
0x00,0x81,0xff,0x89,0x89,0x89,0x76,0x00,//B
0x00,0x3c,0x42,0x81,0x81,0x81,0x67,0x00,//C
0x00,0x81,0xff,0x81,0x81,0x42,0x3c,0x00,//D
};
uchar keyscan(void);//键盘扫描函数
void delay(uchar i); //延时函数
void display(uchar);//控制点阵显示函数
void main()
{
uchar key;
while(1)
{
key=keyscan();//调用键盘扫描
switch(key) //按下相应的键显示相应的内容
{
case 0x18:display(0);break;
case 0x28:display(1);break;
case 0x48:display(2);break;
case 0x88:display(3);break;
case 0x14:display(4);break;
case 0x24:display(5);break;
case 0x44:display(6);break;
case 0x84:display(7);break;
case 0x12:display(8);break;
case 0x22:display(9);break;
case 0x42:display(10);break;
case 0x82:display(11);break;
case 0x11:display(12);break;
case 0x21:display(13);break;
case 0x41:display(14);break;
case 0x81:display(15);break;
}
}
}
uchar keyscan(void)//键盘扫描函数
{
uchar value_hang,value_lie,value;//行列值
P1=0xf0;
value_hang=P1&0x0f; //读入行线值
if(value_hang>0) //检测有无按键按下
{
delay(100); //去抖
if(value_hang>0)
{
value_hang=P1&0x0f; //读入行线值
P1=0x0f;
value_lie=P1&0xf0; //读入列线值
value=(value_hang+value_lie);//键盘最后组合码值,即key值
}
}return(value); //返回该值
}
void delay(uint i)//延时函数
{
while(i--);
}
void display(uchar m) //点阵显示函数
{ uchar i,temp;
while(1)
{ P0=temp;
P2=0;
temp=0xfe;
for(i=0;i<8;i++)
{
P0=temp;
P2=biaozhi_2[i+8*m];
delay(3);
temp=0x1|(temp<<1);
}
}
} 展开
#define uchar unsigned char
#define uint unsigned int
uchar const biaozhi_2[]={
0x80,0xe0,0x9c,0x13,0x9c,0xe0,0x80,0x00,//A
0x00,0x81,0xff,0x89,0x89,0x89,0x76,0x00,//B
0x00,0x3c,0x42,0x81,0x81,0x81,0x67,0x00,//C
0x00,0x81,0xff,0x81,0x81,0x42,0x3c,0x00,//D
};
uchar keyscan(void);//键盘扫描函数
void delay(uchar i); //延时函数
void display(uchar);//控制点阵显示函数
void main()
{
uchar key;
while(1)
{
key=keyscan();//调用键盘扫描
switch(key) //按下相应的键显示相应的内容
{
case 0x18:display(0);break;
case 0x28:display(1);break;
case 0x48:display(2);break;
case 0x88:display(3);break;
case 0x14:display(4);break;
case 0x24:display(5);break;
case 0x44:display(6);break;
case 0x84:display(7);break;
case 0x12:display(8);break;
case 0x22:display(9);break;
case 0x42:display(10);break;
case 0x82:display(11);break;
case 0x11:display(12);break;
case 0x21:display(13);break;
case 0x41:display(14);break;
case 0x81:display(15);break;
}
}
}
uchar keyscan(void)//键盘扫描函数
{
uchar value_hang,value_lie,value;//行列值
P1=0xf0;
value_hang=P1&0x0f; //读入行线值
if(value_hang>0) //检测有无按键按下
{
delay(100); //去抖
if(value_hang>0)
{
value_hang=P1&0x0f; //读入行线值
P1=0x0f;
value_lie=P1&0xf0; //读入列线值
value=(value_hang+value_lie);//键盘最后组合码值,即key值
}
}return(value); //返回该值
}
void delay(uint i)//延时函数
{
while(i--);
}
void display(uchar m) //点阵显示函数
{ uchar i,temp;
while(1)
{ P0=temp;
P2=0;
temp=0xfe;
for(i=0;i<8;i++)
{
P0=temp;
P2=biaozhi_2[i+8*m];
delay(3);
temp=0x1|(temp<<1);
}
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询