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条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥15 如何修改pca中的feature函数
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况