微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 嵌入式设计讨论 > MCU和单片机设计讨论 > 求帮忙找问题

求帮忙找问题

时间:10-02 整理:3721RD 点击:

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

}


这是啥啊,上传代码,不能这么传,看的头晕

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top