学习51 准备写用数码管显示做计算器 程序中有子函数互相调用 扫描一个时报错另一个
uchar KeyPro()
{
uint key_v;
switch(KeyScan())
{
case 0xee: key_v=0; break;
case 0xde: key_v=1; break;
case 0xbe: key_v=2; break;
case 0x7e: key_v=3; break;
case 0xed: key_v=4; break;
case 0xdd: key_v=5; break;
case 0xbd: key_v=6; break;
case 0x7d: key_v=7; break;
case 0xeb: key_v=8; break;
case 0xdb: key_v=9; break;
case 0x7b: break;
case 0xe7: num=add(shi_1,ge_1); break;
case 0xd7: num=sub(shi_1,ge_1); break;
case 0xb7: num=mul(shi_1,ge_1); break;
case 0x77: num=div(shi_1,ge_1); break;
}
return key_v;
}
/***********************************************************************/
/*加法*/
/*//////////////////////////////*/
int add(uint shi_1,uint ge_1)
{
if(flag==3)flag=0;
while(1)
{
led1=0;
switch(flag)
{
case 1: shi_2=KeyPro(); break;
case 2: ge_2=KeyPro(); break;
}if(flag==2) break;
}
shu1=shi_1*10+ge_1;
shu2=shi_2*10+ge_2;
shu=shu1+shu2;
z++;
return (shu);
}
/*减法*/
/*//////////////////////////////////////////////////////*/
int sub(uint shi_1,uint ge_1)
{
if(flag==3)flag=0;
while(1)
{
led2=0;
switch(flag)
{
case 1: shi_2=KeyPro(); break;
case 2: ge_2=KeyPro(); break;
}if(flag==2) break;
}
shu1=shi_1*10+ge_1;
shu2=shi_2*10+ge_2;
shu=shu1-shu2;
z++;
return (shu);
}
/*乘法*/
/*////////////////////////////////////////////////////*/
int mul(uint shi_1,uint ge_1)
{
if(flag==3)flag=0;
while(1)
{
led3=0;
switch(flag)
{
case 1: shi_2=KeyPro(); break;
case 2: ge_2=KeyPro(); break;
}if(flag==2) break;
}
shu1=shi_1*10+ge_1;
shu2=shi_2*10+ge_2;
shu=shu1*shu2;
z++;
return (shu);
}
/*除法*/
/*////////////////////////////////////////////////////*/
int div(uint shi_1,uint ge_1)
{
if(flag==3)flag=0;
while(1)
{
led4=0;
switch(flag)
{
case 1: shi_2=KeyPro(); break;
case 2: ge_2=KeyPro(); break;
}if(flag==4) break;
}
shu1=shi_1*10+ge_1;
shu2=shi_2*10+ge_2;
shu=shu1/shu2;
z++;
return (shu);
}