|
初玩单片机写了一个4x4矩阵键盘程序用protues仿真。但不对,不知道错在哪里,请哪位高手看看,是不是程序写错了?急着知道答案!!!!!!!!!!
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
uchar code tab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
uchar kayscan(viod);
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--);
for(y=120;y>0;y--);
}
void main()
{
uchar kay;
P0=0x06;
while(1)
{
kay=kayscan();
P0=tab[kay];
delay(10);
}
}
uchar kayscan(viod)
{
uchar row,cloumn;
P3=0xf0;
delay(5);
if((P3&0xf0)!=0xf0)
{
delay(5);
if((P3&0xf0)!=0xf0)
{
row=0xfe;
delay(5);
while((row&0x10)!=0)
{
P3=row;
delay(5);
if((row&0xf0)!=0xf0)
{
cloumn=(row&0xf0)| 0xf0;
return((~row )+ (~cloumn) );
}
else
row=(row<<1)|0x01;
}
}
}
return(0);
}
(原文件名:QQ截图未命名.png) |
阿莫论坛20周年了!感谢大家的支持与爱护!!
一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。
|