最近编了个键盘线反转法的程序,郁闷了好半天啊,写了个子函数display(),主函数调用的时候不小心写成了dispaly(),程序竟然没有报错,只是个warning,情何以堪啊。。。。
#include
#define uchar unsigned char
#define uint unsigned int
unsigned char code table[]={
0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,
0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0xbf}; //共阳极数码管显示,最后一位是“—”
unsigned char code jianpan[]={
0xee,0xde,0xbe,0x7e,0xed,0xdd,0xbd,0x7d,
0xeb,0xdb,0xbb,0x7b,0xe7,0xd7,0xb7,0x77}; //键盘编码
uchar key;
void delay(uint z)
{ //1ms延时函数
unsigned int x,y;
for(x=z;x>0;x--)
for(y=114;y>0;y--);
}
uchar display() //返回键码值函数
{
uchar scan,scan1,scan2,i;
P1=0xf0;
scan1=P1;
if(scan1!=0xf0)
{
delay(10);
scan1=P1;
if(scan1!=0xf0)
{
P1=0x0f;
scan2=P1;
scan=scan1|scan2;
for(i=0;i<16;i++)
{
if(scan==jianpan)
{
key=i;
return(key);
}
}
}
}
else
P1=0xff;
return(16);
}
void main()
{
uchar cc;
P0 = 0xbf;
P2=0xfe;
P1=0xff;
while(1)
{
P1=0xf0;
cc=display(); /************这句程序里面的display改为dispaly之后,程序只是warning,但是得不到结果***********/
while(P1==0xf0);
P0=table[cc];
}
}
0
|
|
|
|