51单片机与键盘显示
/**********************************键盘显示子函数**********************************/
void keydisplay(uchar C)
{
WriteCommandLCM(0x0c,1);
DisplayListChar(0,1,str2);
switch(C)
{
case 0:clear();
break;
case 1:prodis();
alldata[rrr]=0;
WriteDataLCM('0');
break;
case 2:prodis();
WriteDataLCM('=');
kind=kind+10;
position2=rrr;
datapc();
remove0();
data3dis();
break;
case 3:prodis();
kind=kind+1; //加法运算, kind=1
position1=rrr;
WriteDataLCM('+');
break;
case 4:prodis();
alldata[rrr]=1;
WriteDataLCM('1');
break;
case 5:prodis();
alldata[rrr]=2;
WriteDataLCM('2');
break;
case 6:prodis();
alldata[rrr]=3;
WriteDataLCM('3');
break;
case 7:prodis();
kind=kind+5; //减法运算, kind=5
position1=rrr;
WriteDataLCM('-');
break;
case 8:prodis();
alldata[rrr]=4;
WriteDataLCM('4');
break;
case 9:prodis();
alldata[rrr]=5;
WriteDataLCM('5');
break;
case 10:prodis();
alldata[rrr]=6;
WriteDataLCM('6');
break;
case 11:prodis();
kind=kind+25; //乘法运算, kind=25
position1=rrr;
WriteDataLCM('*');
break;
case 12:prodis();
alldata[rrr]=7;
WriteDataLCM('7');
break;
case 13:prodis();
alldata[rrr]=8;
WriteDataLCM('8');
break;
case 14:prodis();
alldata[rrr]=9;
WriteDataLCM('9');
break;
case 15:prodis();
kind=kind+125; //除法运算, kind=125
position1=rrr;
WriteDataLCM('/');
break;
default:
break;
}
}
void datapc(void)
{
uchar k;
if((position1==0) || (position2==(position1+1)))
yes=1;
else
{
for(k=0;k<position1;k++)
{
ddata=shi(position1-1-k);
data1=data1+(alldata[k])*ddata;
}
for(k=position1+1;k<position2;k++)
{
ddata=shi(position2-1-k);
data2=data2+(alldata[k])*ddata;
}
if((data1 > 50000) || (data2 > 50000))
{yes=2;}
else
{
switch (kind)
{
case 11:data3=data1+data2;yes=0;
break;
case 15: if(data1<data2)
{
ddata=data1;
data1=data2;
data2=ddata;
fu=1;
}
data3=data1-data2;yes=0;
break;
case35:data3=data1*data2;yes=0;
break;
case 135:data3=data1/data2;yes=0;
break;
default:yes=1;
}
}
}
if(yes==0)
{
love[0]=data3 / 1000000000;
love[1]=data3 / 100000000-love[0]*10;
love[2]=data3 / 10000000-love[0]*100-love[1]*10;
love[3]=data3 / 1000000-love[0]*1000-love[1]*100-love[2]*10;
love[4]=data3 /100000-love[0]*10000-love[1]*1000-love[2]*100-love[3]*10;
love[5]=data3 / 10000-love[0]*100000-love[1]*10000-love[2]*1000-love[3]*100-love[4]*10;
love[6]=(data3 % 10000)/1000;
love[7]=(data3 % 1000)/100;
love[8]=(data3 % 100)/10;
love[9]= data3 % 10;
}
if(kind==135)
{
love[10]=0xfe;
love[11]=((data1 % data2)*10)/data2;
love[12]=((((data1 % data2)*10)%data2)*10)/data2;
love[13]=((((((data1 % data2)*10)%data2)*10)%data2)*10)/data2;
}
}
void remove0(void)
{
uchar k=0;
while((love[k]==0) && (k<=8))
{
love[k]=0xf0;
k++;
}
pfu=k;
}
void data3dis(void)
{
uchar k;
if(yes==0)
{
if(kind==135)
{
for(k=0;k<=13;k++)
{
WriteCommandLCM(0xc2+k,1);
WriteDataLCM(love[k]+0x30);
}
}
else
{
for(k=0;k<=9;k++)
{
WriteCommandLCM(0xc6+k,1);
WriteDataLCM(love[k]+0x30);
}
if(fu==1)
{
WriteCommandLCM(0xc5+pfu,1);
WriteDataLCM('-');
}
}
}
else
if(yes==1)
error();
else
if(yes==2)
out();
}
void clear(void)
{
uchar k;
while(((~P1) & 0xf0)!=0);
for(k=7;k<=15;k++)
{
WriteCommandLCM(k+0x80+0x40,1);
WriteDataLCM(' ');
}
for(k=7;k<=15;k++)
{
WriteCommandLCM(k+0xc0,1);
WriteDataLCM(' ');
}
rrr=0xff;
kind=yes=position1=position2=0; //清运算类型标志
fu=pfu=0;
data1=data2=0; //清数据
data3=0;
}
void prodis(void)
{
rrr=6;
rrr++;
if(rrr==15)
{rrr=7;}
WriteCommandLCM(rrr+0x80+0x40,1);
while(((~P1) & 0xf0)!=0);
}
哪位大哥帮忙看下红色字段表达的是个啥意思 小弟完全看不懂~
顶起,值得收藏