2 lzxppp lzxppp 于 2014.12.16 12:09 提问

我是初学者,问问这个程序哪有问题?

各位盆友,我想用lcd162显示矩阵键盘扫描值,结果一上电一直显示000000000,我是初学者,不会改 求各位大神帮忙改
#include
#define uchar unsigned char
#define uint unsigned int
unsigned char code table[]={'0','1','2','3','4','5','6','7','8',
'9','A','B','C','D','E','F'};//转换成液晶显示的字符

uchar num,temp;

sbit dula=P2^6;
sbit wela=P2^7;
sbit lcden=P2^5;
sbit lcdrs=P1^0;
sbit lcdwr=P1^1;

uchar keyscan();
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}

void write_com(uchar com)
{
lcdrs=0;
P0=com;
delay(5);
lcden=1;
delay(5);
lcden=0;

}
void write_date(uchar date)
{
lcdrs=1;
P0=date;
delay(5);
lcden=1;
delay(5);
lcden=0;
}

void init ()
{

 wela=0;
 dula=0;
 lcdwr=0;
 lcden=0;
 write_com(0x38);
 write_com(0x0f);
 write_com(0x06);
 write_com(0x01);
 write_com(0x80);

}

void main ()
{
init ();

while (1)
{
uchar keyscan();

   write_date(table[keyscan()]);

   delay(20);

}
}
uchar keyscan() //键盘扫描函数,返回一个值num
{

        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;//必须重新读取P3口的值,否则temp将一直不等于0xf0
                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;

}

1个回答

devmiao
devmiao   Ds   Rxr 2014.12.16 13:19
lzxppp
lzxppp 不一样 我的是用lcd显示的 你说的例子是用数码管显示的,我实在没找到我的错误在哪 求各位帮忙看看
3 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!