找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 4469|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

[求助]求高手指點(diǎn)下

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:46696 發(fā)表于 2012-11-29 14:27 | 只看該作者 回帖獎勵 |倒序?yàn)g覽 |閱讀模式

寫的程序,但是便宜一直有錯(cuò),是計(jì)算器程序,麻煩哪位大神能指點(diǎn)下。

 

 

(錯(cuò)誤: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用來存放運(yùn)算符的值   scan作為是否按鍵的標(biāo)志位(按下就為1沒按為0)
void delay(uchar n);       //延時(shí)Z毫秒
void display(long f);    //用六位數(shù)碼管顯示long值
uchar keyscan();         //鍵盤掃描并把掃描得到的值返回   
void displayerror();     //顯示錯(cuò)誤操作提示信息

void delay(uchar n)         //延時(shí)n ms(晶振12Mhz)
{
 uchar i;
 while(n--)
  for(i=125;i>0;i--);//1ms
}

uchar keyscan()             //掃描鍵盤,返回的值高四位相應(yīng)位表列,低表行。若未按鍵則返回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)  //將用相應(yīng)位表示的按鍵號轉(zhuǎn)化為數(shù)值編碼
{
 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用于判斷每次輸入的數(shù)是否超過六位,e為錯(cuò)誤操作標(biāo)志位(為1表示已錯(cuò)誤操作),jie為顯示計(jì)算結(jié)果標(biāo)志位(為1表示要顯示結(jié)果)
 long a=0,b=0,c=0;      //a存放第一次輸入的數(shù),b存放第二次輸入的數(shù),c存放計(jì)算的結(jié)果
 display(0);           //初始化顯示
 delay(1000);         //延時(shí)1000毫秒
 while(1)
 {
  //beep=1;             //關(guān)閉蜂鳴器
  val=keyscan();     //把掃描得到的值賦給val
  if(scan==1)        //一旦按下鍵我就對其操作
  {
   scan=0;         //把按鍵標(biāo)志位scan復(fù)位
   if(val==10)     //如果按下的為復(fù)位鍵
   {
    a=0;b=0;c=0;fuhao=0;jie=0;e=0;i=0;j=0;display(0);
   //復(fù)位操作(初始化)  (顯示是不能停)
    continue;           //直接進(jìn)入下一次循環(huán)
   }
   else if(val>=11&&val<=15&&i==0&&fuhao==0)//如果第一次按下的不是數(shù)字鍵
   {
    display(0);        //數(shù)碼管顯示不能停
    continue;        //直接進(jìn)入下一次循環(huán)
   }
 
   else if(val>=12&&val<=15&&fuhao==0&&i!=0)//輸入數(shù)字之后按下的第一個(gè)運(yùn)算符
   {
    fuhao=val;        //把掃描得到運(yùn)算符值賦給fuhao標(biāo)志位
    i=0;             //一旦輸入運(yùn)算符就把數(shù)字輸入計(jì)數(shù)i清零
    display(0);       //數(shù)碼管顯示不能停
   }
   else if(fuhao!=0&&val>=11&&val<=15)   //只要按下等于或者運(yùn)算符之前按了數(shù)字鍵和運(yùn)算符就顯示計(jì)算結(jié)果
   {
    jie=1;            //計(jì)算結(jié)果標(biāo)志位jie為1(表示要顯示計(jì)算結(jié)果c)
    if(fuhao==12)      //如果輸入的是運(yùn)算符‘+’
    {
     c=a+b;          //把運(yùn)算的結(jié)果賦給c
     if(c>999999)     //如果計(jì)算結(jié)果超出數(shù)碼管的顯示范圍
     {
      displayerror();     //顯示出錯(cuò)信息
      e=1;             //出錯(cuò)信息標(biāo)志位置1
     }
     else       
     {
      display(c);     //不超出顯示范圍就顯示結(jié)果
     }
    }
    else if(fuhao==13)     //如果輸入的運(yùn)算符是‘-’
    {
     if(a<b)
     { 
      displayerror();
     }
     else
     {
      c=a-b;
      display(c);
     }
    }
    else if(fuhao==14)       //如果輸入的運(yùn)算符是‘*’
    {
     c=a*b;
     if(c>999999)
     {
      displayerror();
      e=1;
     }
     else
     {
      display(c);
     }
    }
    else          //如果輸入的運(yùn)算符是‘/’
    {
     c=a/b;
     display(c);
    }
   }
   else if(val>=0&&val<=9)     //如果按下的為數(shù)字鍵
   {
    if(fuhao==0)      //如果是第一次按下數(shù)字鍵
    {
     a=a*10+val;      //把前面顯示的值左移一位再加當(dāng)前輸入的數(shù)字存放到a(0到9)
     i++;       //每輸入一個(gè)數(shù)字,數(shù)字計(jì)數(shù)i加1
     if(i>6)          //如果連續(xù)輸入數(shù)字超過六位
     {
      displayerror();e=1;   //顯示出錯(cuò)信息且錯(cuò)誤標(biāo)志位置1
     }
     else
     {
      display(a);     //顯示得到的a
      continue;     //進(jìn)入下次次循環(huán)
     }
    }
    else            //第二次按下數(shù)字鍵
    {
      b=b*10+val;      //把前面顯示的值左移一位再加當(dāng)前輸入的數(shù)字存放到b(0到9)
      j++;       //第二次輸入數(shù)字的計(jì)算變量j加1
      if(j>6)         //如果輸入超出數(shù)碼管顯示范圍
      {
       displayerror(); e=1;
      }
      else
      {
       display(b);
       continue;
      }
    }
   }
 
  }
  else           //如果沒按下鍵(也要顯示)
  {
   if(e==1)      displayerror();//如果出錯(cuò)標(biāo)志位為1就顯示出錯(cuò)信息
   else if(fuhao==0)         display(a);  //如果還沒輸入運(yùn)算符(到目前為止還只是輸入數(shù)字)就顯示a 
   else if(fuhao!=0&&jie==0) display(b);  //如果輸入數(shù)字后又輸了運(yùn)算符且沒輸入運(yùn)算符和等于就顯示b
   else if(jie==1)           display(c);  //如果輸入了結(jié)果標(biāo)志位就顯示計(jì)算結(jié)果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)      //以科學(xué)計(jì)數(shù)法顯示
 {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表示出錯(cuò)信息
{ 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);
    }
}

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表