寫的程序,但是便宜一直有錯,是計算器程序,麻煩哪位大神能指點下。
(錯誤:JISUANQI.C(221): error C211: call not to a function
JISUANQI.C(221): error C208: 'function': too many actual parameters
JISUANQI.C(222): error C187: not an lvalue
JISUANQI.C(238): error C211: call not to a function
JISUANQI.C(238): error C208: 'function': too many actual parameters
JISUANQI.C(239): error C187: not an lvalue
JISUANQI.C(251): error C211: call not to a function
JISUANQI.C(251): error C208: 'function': too many actual parameters
JISUANQI.C(252): error C187: not an lvalue
Target not created)
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int;
uchar code a[]={0xF7,0xFB,0xFD,0xFE};
unsigned char code table[16]={0xee,0x82,0xdc,0xd6,0xb2,0x76,0x7e,0xc2,0xfe,0xf6,0xee,0xee,0xee,0xee,0xee,0xee,};
uchar fuhao=0,scan=0; //全局變量fuhao用來存放運算符的值 scan作為是否按鍵的標志位(按下就為1沒按為0)
void delay(uchar n); //延時Z毫秒
void display(long f); //用六位數碼管顯示long值
uchar keyscan(); //鍵盤掃描并把掃描得到的值返回
void displayerror(); //顯示錯誤操作提示信息
void delay(uchar n) //延時n ms(晶振12Mhz)
{
uchar i;
while(n--)
for(i=125;i>0;i--);//1ms
}
uchar keyscan() //掃描鍵盤,返回的值高四位相應位表列,低表行。若未按鍵則返回0
{
uchar row,col;
uchar j,m;
P1=0xF0;
if((P1&0xF0)!=0xF0)
{
delay(1);
if((P1&0xF0)!=0xF0)
col=~(P1|0x0F); //確定列
j=0;
P1=a[j];
while(j<=3)
{
if((P1&0xF0)!=0xF0)
{
row=~a[j]; //確定行
break;
}
else
{j++;P1=a[j];}
}
m=row+col;
return(m);
}
else
return(0);
}
uchar coding(uchar m) //將用相應位表示的按鍵號轉化為數值編碼
{
uchar k;
switch(m)
{
case (0x08+0x80): k=0;break;//0
case (0x08+0x40): k=1;break;//1
case (0x08+0x20): k=2;break;//2
case (0x08+0x10): k=3;break;//3
case (0x04+0x80): k=4;break;//4
case (0x04+0x40): k=5;break;//5
case (0x04+0x20): k=6;break;//6
case (0x04+0x10): k=7;break;//7
case (0x02+0x80): k=8;break;//8
case (0x02+0x40): k=9;break;//9
case (0x02+0x20): k=10;break;//加法
case (0x02+0x10): k=11;break;//減法
case (0x01+0x80): k=12;break;//乘法
case (0x01+0x40): k=13;break;//除法
case (0x01+0x20): k=14;break;//清零
case (0x01+0x10): k=15;break;//等于
}
scan=1;
return(k);
}
void main()
{
uchar val=0,j=0,i=0,jie,e=0; //i,j用于判斷每次輸入的數是否超過六位,e為錯誤操作標志位(為1表示已錯誤操作),jie為顯示計算結果標志位(為1表示要顯示結果)
long a=0,b=0,c=0; //a存放第一次輸入的數,b存放第二次輸入的數,c存放計算的結果
display(0); //初始化顯示
delay(1000); //延時1000毫秒
while(1)
{
//beep=1; //關閉蜂鳴器
val=keyscan(); //把掃描得到的值賦給val
if(scan==1) //一旦按下鍵我就對其操作
{
scan=0; //把按鍵標志位scan復位
if(val==10) //如果按下的為復位鍵
{
a=0;b=0;c=0;fuhao=0;jie=0;e=0;i=0;j=0;display(0);
//復位操作(初始化) (顯示是不能停)
continue; //直接進入下一次循環
}
else if(val>=11&&val<=15&&i==0&&fuhao==0)//如果第一次按下的不是數字鍵
{
display(0); //數碼管顯示不能停
continue; //直接進入下一次循環
}
else if(val>=12&&val<=15&&fuhao==0&&i!=0)//輸入數字之后按下的第一個運算符
{
fuhao=val; //把掃描得到運算符值賦給fuhao標志位
i=0; //一旦輸入運算符就把數字輸入計數i清零
display(0); //數碼管顯示不能停
}
else if(fuhao!=0&&val>=11&&val<=15) //只要按下等于或者運算符之前按了數字鍵和運算符就顯示計算結果
{
jie=1; //計算結果標志位jie為1(表示要顯示計算結果c)
if(fuhao==12) //如果輸入的是運算符‘+’
{
c=a+b; //把運算的結果賦給c
if(c>999999) //如果計算結果超出數碼管的顯示范圍
{
displayerror(); //顯示出錯信息
e=1; //出錯信息標志位置1
}
else
{
display(c); //不超出顯示范圍就顯示結果
}
}
else if(fuhao==13) //如果輸入的運算符是‘-’
{
if(a<b)
{
displayerror();
}
else
{
c=a-b;
display(c);
}
}
else if(fuhao==14) //如果輸入的運算符是‘*’
{
c=a*b;
if(c>999999)
{
displayerror();
e=1;
}
else
{
display(c);
}
}
else //如果輸入的運算符是‘/’
{
c=a/b;
display(c);
}
}
else if(val>=0&&val<=9) //如果按下的為數字鍵
{
if(fuhao==0) //如果是第一次按下數字鍵
{
a=a*10+val; //把前面顯示的值左移一位再加當前輸入的數字存放到a(0到9)
i++; //每輸入一個數字,數字計數i加1
if(i>6) //如果連續輸入數字超過六位
{
displayerror();e=1; //顯示出錯信息且錯誤標志位置1
}
else
{
display(a); //顯示得到的a
continue; //進入下次次循環
}
}
else //第二次按下數字鍵
{
b=b*10+val; //把前面顯示的值左移一位再加當前輸入的數字存放到b(0到9)
j++; //第二次輸入數字的計算變量j加1
if(j>6) //如果輸入超出數碼管顯示范圍
{
displayerror(); e=1;
}
else
{
display(b);
continue;
}
}
}
}
else //如果沒按下鍵(也要顯示)
{
if(e==1) displayerror();//如果出錯標志位為1就顯示出錯信息
else if(fuhao==0) display(a); //如果還沒輸入運算符(到目前為止還只是輸入數字)就顯示a
else if(fuhao!=0&&jie==0) display(b); //如果輸入數字后又輸了運算符且沒輸入運算符和等于就顯示b
else if(jie==1) display(c); //如果輸入了結果標志位就顯示計算結果c
else display(0); //其余就初始化顯示
}
}
}
void display(long f) //以測出的頻率串行輸出
{unsigned long x;
unsigned char a[5]={0,0,0,0,0},i=0,j;
if(f!=0){
if((f<10000)&&(f>1)) //正常顯示
{if(f>1000)f=f-1; //軟件修正頻率偏差
while(f<1000)
{f=f*10;
i++;
}
x=f*10;
a[4]=x%10;
if(a[4]>=5)f=f+1;;
x=f;
a[1]=x%10;
a[2]=(x/10)%10;
a[3]=(x/100)%10;
a[4]=(x/1000)%10;
for(j=0;j<5;j++)
{a[j]=table(a[j]);}
a[i+1]++;
a[0]=0;
}
else if(f>=10000) //以科學計數法顯示
{while(f>=1000)
{f=f/10;
i++;
}
x=f;
a[4]=(unsigned char)((float)((f-x))*10);
if(a[4]>=5)x++; //四舍五入
a[2]=x%10;
a[3]=(x/10)%10;
a[4]=(x/100)%10;
a[0]=i+2;
for(j=0;j<5;j++)
{a[j]=table(a[j]);}
a[4]++;
a[1]=0x7c;
}
else
{x=f*10000; //頻率值小于1
if((x%10)>=5)x=x+10; //四舍五入
x=x/10;
a[1]=x%10;
a[2]=(x/10)%10;
a[3]=(x/100)%10;
a[4]=(x/1000)%10;
for(j=0;j<5;j++)
{a[j]=table(a[j]);}
a[4]++;
a[0]=0;
}
}
for(j=0;j<5;j++) //串行
{SBUF=a[j];
while(TI==0);}
}
void displayerror() //最高位顯示E表示出錯信息
{ unsigned char a[5]={0,0,0,0,0},i=0,j;
for(j=0;j<5;j++)
{a[j]=0x7c;
SBUF=a[j];
while(TI==0);
}
}
| 歡迎光臨 (http://m.raoushi.com/bbs/) | Powered by Discuz! X3.1 |