Codevision AVR中的错误

时间:2017-04-12 21:21:33

标签: c syntax-error avr codevisionavr

我在codevision中对计算器进行编码,我得到了这个Err:

  

错误:C:\ cvavr \ BIN \ Thrust Calculator \ TC.c(112):')'预期

这个错误与我的代码的这一部分有关(来自bot的第4行):

intnum1 = (int atoi(num1[q])) * 10^(i-q-1) + intnum1; 

有什么问题?

这是我的代码:

#include <mega32.h>
#include <alcd.h>
#include <delay.h>
#include <string.h>



//defining PTND.i
#define C0 PIND.4
#define C1 PIND.5
#define C2 PIND.6
#define C3 PIND.7



flash char shift[4] = {0b11111110,0b11111101,0b11111011,0b11110111};
flash char layout[16] = {'7','8','9','/',
                         '4','5','6','*',
                         '1','2','3','-',
                         'C','0','=','+'};   


    char keypad(void);
    int  fnum1(void);
    char num1[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
    char num2[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
    int i,q, intnum1 = 0;
    int t;  


void main(void)    
{

    DDRD = 0X0F;
    PORTD = 0XF0;
    lcd_init(16);
    keypad();

while (1)
      {


      }
}


/*   keypad function   */

char keypad(void) 
{       
int row = 0, position = 0;

    while (1)
    {
    for(row=0; row<4; row++)
        {
         int COLUMN = -1;

         PORTD = shift[row];  

        //finding column 
         if(C0 == 0) {COLUMN = 0;}
         if(C1 == 0) {COLUMN = 1;}
         if(C2 == 0) {COLUMN = 2;}
         if(C3 == 0) {COLUMN = 3;} 

         //know if sm clik the btn 
         if(COLUMN != -1) 
         {               

           //calculating the position
           position = row*4 + COLUMN;  

           //do nothing during the pushing
           while(C0 == 0) {}
           while(C1 == 0) {}
           while(C2 == 0) {}
           while(C3 == 0) {} 

           //C as lcd clear          
           if(layout[position] == 'C') lcd_clear();
         else 

           //return the keypad value   
           return layout[position];
         }        
        delay_ms(50); 
        } 
    }            
}


int fnum1(void)
{

        if( keypad() != '') 
           {  
           num1[i] = keypad();
           i = i + 1;
           }      

        if ( keypad() == '=')
          {   
           for( t = 0 ; t <= i ; t++) 
           {
             lcd_putchar(num1[t]); 
           }
          }

        for( q = 0 ; q <= i ; q++) 
          {
            intnum1 = (int atoi(num1[q])) * 10^(i-q-1) + intnum1; 
          } 
           lcd_putchar(keypad());
           return intnum1;       

}

如果sm能回答我,我将不胜感激:)

1 个答案:

答案 0 :(得分:0)

intnum1 = (int atoi(num1[q])) * 10^(i-q-1) + intnum1;确实是问题所在。

你到底想要做什么?如果您想将整个结果投射到int,那么您想要的是:

intnum1 = (int) (atoi(num1[q])) * (10^(i-q-1))) + intnum1; 

我不确定此处需要哪些操作顺序,但您希望将整个结果转换为int以将其存储在intnum1中。