這是僅僅有一小部分功能的計算器程序,但液晶去沒反應;求各位指出問題;
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit rs=P2^6;
sbit wr=P2^5;
sbit len=P2^7;
uchar annum,num,date;
uchar dis[16];
void delay(uint z)
{
uint x,y;
for(x=z;z>0;x--)
for(y=110;y>0;y--);
}
void write_com(uchar com)
{
rs=0;
P0=com;
delay(5);
len=1;
delay(5);
len=0;
}
void write_date(uchar date)
{
rs=1;
P0=date;
delay(5);
len=1;
delay(5);
len=0;
}
void keyscan()
{
uchar temp,key;
P3=0xfe;
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(10);
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xee:
num=0;
break;
annum++;
case 0xde:
num=1;
annum++;
break;
case 0xbe:
num=2;
annum++;
break;
case 0x7e:
num=3;
annum++;
break;
}
while(temp!=0xf0);
{
P3=temp;
temp=temp&0xf0;
}
}
}
P3=0xfd;
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(5);
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xed:
num=4;
annum++;
break;
case 0xdd:
num=5;
annum++;
break;
case 0xbd:
num=6;
annum++;
break;
case 0x7d:
num=7;
annum++;
break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
}
}
P3=0xfb;
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(10);
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xeb:
num=8;
annum++;
break;
case 0xdb:
num=9;
annum++;
break;
case 0xbb:
num=10;
break;
case 0x7b:
num=11;
break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
}
}
P3=0xf7;
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(10);
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xe7:
num=12;
break;
case 0xd7:
num=13;
case 0xb7:
num=14;
break;
case 0x77:
num=15;
break;
}
while(temp!=0xf0)
{
temp=P3;
temp&0xf0;
}
}
}
}
uchar keysuan(uchar date)
{
if(num==0)
date=date+(num*annum*10);
if(num==1)
date=date+(num*annum*10);
if(num==2)
date=date+(num*annum*10);
if(num==3)
date=date+(num*annum*10);
if(num==4)
date=date+(num*annum*10);
if(num==4)
date=date+(num*annum*10);
if(num==5)
date=date+(num*annum*10);
if(num==6)
date=date+(num*annum*10);
if(num==7)
date=date+(num*annum*10);
if(num==8)
date=date+(num*annum*10);
if(num==9)
{date=date+(num*annum*10);}
return date;
}
void jisuan()
{
write_com(0x80+0x40+16);
dis[0]=date%10+0x30;
dis[1]=date/10%10+0x30;
dis[2]=date/100%10+0x30;
dis[3]=date/1000%10+0x30;
dis[4]=date/10000%10+0x30;
dis[5]=date/100000%10+0x30;
dis[6]=date/1000000%10+0x30;
dis[7]=date/10000000%10+0x30;
dis[8]=date/100000000%10+0x30;
dis[9]=date/1000000000%10+0x30;
dis[10]=date/10000000000%10+0x30;
}
void display()
{
uchar i=0;
write_com(0x80+0x50);
while(dis[i]!='\0')
{
write_date(dis[i]);
i++;
}
i=0;
}
void init()
{
date=0;
wr=0;
write_com(0x38);
write_com(0x0f);
write_com(0x04);
write_com(0x01);
}
void main()
{
init();
while(1)
{
keyscan();
keysuan();
jisuan();
display();
}
}
|