
{
EA=0
scan_key()
delay(50)
INT_0 =judge_hitkey()
while( INT_0 !=1) /信顷/等待按键释放
EA=1
}
在EA=0;这句前,有无加上了,重新把 INT_0 =judge_hitkey() 再赋回来了?,,我在郭天祥的板搜贺子上调试不行; EXITE.C(93): warning C206: 'manage_key1': missing function-prototype
这是我花两个多小时写得51单片机,矩阵键盘的显示,希望能对你有帮助;
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}
sbit dula=P2^6
sbit wela=P2^7
void init()
void display(uchar)
uchar keyscan()
uchar temp,num //键盘扫描
void delay(uint xms)//延时子函数
{
int i,j
for(i=xmsi>0i--)//延时xms毫秒
for(j=110j>0j--)
}
void main()
{
init()
while(1)
{
keyscan()//不断扫描键盘;
display(num)
}
}
void init()
{
num=0xff //控制让程序开始时不出现乱码;
wela=1
P0=0xc0 //打开数码管显示,静态显示;
wela=0
}
uchar keyscan()
{
P3=0xfe
temp=P3
temp=temp&0xf0/世坦派/按位与,只能用&;
if(temp!=0xf0)//在用while语句时,一定要加上去抖动,否则程序会停不下来的哦;
{ //还是统一用if语句吧,只有在去抖动才一定要用if语句;
delay(5)//至于中括号加在那都无所谓啦;
temp=P3
temp=temp&0xf0
if(temp!=0xf0)
{
temp=P3
switch(temp)
{
case 0xee:num=1
break
case 0xde:num=2
break
case 0xbe:num=3
break
case 0x7e:num=4
break
}
while (temp!=0xf0) //去抖动只能用while ,只有松开手才会执行下面的,才会有数码显;
{////一松开手,就相当于把P3口的电平改变了;所以去抖不能在switch前
temp=P3
temp=temp&0xf0 //不能不要,只有松开手,才会退出这个循环;
}
}
}
P3=0xfd
temp=P3
temp=temp&0xf0//按位与,只能用&;
if(temp!=0xf0)
{
delay(5)
if(temp!=0xf0)
{
temp=P3
// temp=temp&0xf0//该句子一定不能要,因为下面判断的,只是P3口的电平状态而已;
}
switch(temp)
{ case 0xed: num=5break
case 0xdd: num=6break
case 0xbd: num=7break
case 0x7d: num=8break
}
}
while (temp!=0xf0)
{
temp=P3
temp=temp&0xf0
}
P3=0xfb
temp=P3
temp=temp&0xf0//按位与,只能用&;
if(temp!=0xf0)
{
delay(5)
if(temp!=0xf0)
{
temp=P3
temp=temp&0xf0
}
}
if(temp!=0xf0)
{
temp=P3
// temp=temp&0xf0
}
switch(temp)
{ case 0xeb: num=9break
case 0xdb: num=10break
case 0xbb: num=11break
case 0x7b: num=12break
}
while (temp!=0xf0) //去抖动只能用while ,只有松开手才会执行下面的,才会有数码显;
{////一松开手,就相当于把P3口的电平改变了;所以去抖不能在switch前
temp=P3
temp=temp&0xf0 //不能不要,只有松开手,才会退出这个循环;
}
P3=0xf7
temp=P3
temp=temp&0xf0//按位与,只能用&;
if(temp!=0xf0)
{
delay(5)
if(temp!=0xf0)
{
temp=P3
temp=temp&0xf0
}
}
if(temp!=0xf0) //该句子不能用while语句,因为如果用while语句,如果松手了,P3的电平就改变了,temp的值也会改变的。
//因此建议,非必要,还是用if语句;
{
temp=P3
// temp=temp&0xf0
}
switch(temp)
{ case 0xe7: num=13break
case 0xd7: num=14break
case 0xb7: num=15break
case 0x77: num=16break
}
while (temp!=0xf0) //去抖动只能用while ,只有松开手才会执行下面的,才会有数码显;
{////一松开手,就相当于把P3口的电平改变了;所以去抖不能在switch前
temp=P3
temp=temp&0xf0 //不能不要,只有松开手,才会退出这个循环;
}
return num
}
void display(uchar num)
{
P0=table[num-1]
dula=1
dula=0
}
下面的是郭天祥老师写的
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit dula=P2^6
sbit wela=P2^7
sbit key1=P3^4
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,0}
uchar num,temp,num1
void delay(uint z)
{
uint x,y
for(x=zx>0x--)
for(y=110y>0y--)
}
uchar keyscan()
void display(uchar aa)
void main()
{
num=17
dula=1
P0=0
dula=0
wela=1
P0=0xc0
wela=0
while(1)
{
display(keyscan())
}
}
void display(uchar aa)
{
dula=1
P0=table[aa-1]
dula=0
}
uchar keyscan()
{
P3=0xfe
temp=P3
temp=temp&0xf0
while(temp!=0xf0)
{
delay(5)
temp=P3
temp=temp&0xf0
while(temp!=0xf0)
{
temp=P3
switch(temp)
{
case 0xee:num=1
break
case 0xde:num=2
break
case 0xbe:num=3
break
case 0x7e:num=4
break
}
while(temp!=0xf0)
{
temp=P3
temp=temp&0xf0
}
}
}
P3=0xfd
temp=P3
temp=temp&0xf0
while(temp!=0xf0)
{
delay(5)
temp=P3
temp=temp&0xf0
while(temp!=0xf0)
{
temp=P3
switch(temp)
{
case 0xed:num=5
break
case 0xdd:num=6
break
case 0xbd:num=7
break
case 0x7d:num=8
break
}
while(temp!=0xf0)
{
temp=P3
temp=temp&0xf0
}
}
}
P3=0xfb
temp=P3
temp=temp&0xf0
while(temp!=0xf0)
{
delay(5)
temp=P3
temp=temp&0xf0
while(temp!=0xf0)
{
temp=P3
switch(temp)
{
case 0xeb:num=9
break
case 0xdb:num=10
break
case 0xbb:num=11
break
case 0x7b:num=12
break
}
while(temp!=0xf0)
{
temp=P3
temp=temp&0xf0
}
}
}
P3=0xf7
temp=P3
temp=temp&0xf0
while(temp!=0xf0)
{
delay(5)
temp=P3
temp=temp&0xf0
while(temp!=0xf0)
{
temp=P3
switch(temp)
{
case 0xe7:num=13
break
case 0xd7:num=14
break
case 0xb7:num=15
break
case 0x77:num=16
break
}
while(temp!=0xf0)
{
temp=P3
temp=temp&0xf0
}
}
}
return num
}
你的搜芹问题是这样的辩亏你每次返回之前应该把相应的扫描线也置高
否则程序第二次执行的时候 就会世灶毕扫描错误
f(PinA==FALSE)
PinA=TRUE
Pin2=TRUE///////
return 2}
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)