lzxppp 2014-12-16 04:09 采纳率: 0%
浏览 1989

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

各位盆友,我想用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条回答

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码