2014-06-27 66 views
-3

即時得到這些錯誤:錯誤:左值所需的分配,錯誤的左操作數:不被忽略,因爲它空值應該是

error: lvalue required as left operand of assignment 
error: void value not ignored as it ought to be 

基本上我有一個I2C電容性觸摸控制器,我不斷地掃描,然後檢查掃描的數據,然後根據需要做出動作,然後重複。

這裏是我的代碼:

#include <avr/io.h> 
#include <util/delay.h> 
#include "i2cmaster.h" 

#define mpr03x 0x4A 

int main(void) 
{ 
    unsigned char tou; 

    DDRA = 0xff; 
    DDRB = 0xff; 
    PORTA = 0x03; 
    _delay_ms(500); 
    PORTA = 0x00; 

    i2c_init();  //Initialize I2C 

    i2c_start_wait(mpr03x+I2C_WRITE); //Set device address and write mode 
    i2c_write(0x44);     //Write address = 68 
    i2c_write(0x03);     //Calibration = ON, Runmode = 1, Enabled = ELE0, ELE1, ELE2 

    while(1) 
    { 
     PORTA = 0x01; 
     i2c_start_wait(mpr03x=I2C_WRITE); //Set device address and write mode 
     i2c_write(0x00);     //Write address = 68 
     i2c_rep_start(mpr03x+I2C_READ);  // set device address and read mode 
     tou = i2c_readNak; 
     i2c_stop; 

     if(tou == 0x00);     //If no pads are pressed 
     { 
      PORTA = 0x00; 
      _delay_ms(1); 
     } 
     else 
     { 
      if(tou == 0x01);    //If pad 1 is pressed 
      { 
       PORTA = 0x05; 
       if(tou == 0x02);   //If pad 2 is pressed 
       { 
        PORTA = 0x09; 
        if(tou == 0x03);  //If pad 3 is pressed 
        { 
         PORTA = 0x11; 
         _delay_ms(1000); 
        } 
       } 
       else 
       { 
        if(tou == 0x02);  //If pad 2 is pressed 
        { 
         PORTA = 0x09; 
         if(tou == 0x03); //If pad 3 is pressed 
         { 
          PORTA = 0x11; 
          _delay_ms(1000); 
         } 
         else 
         { 
          if(tou == 0x03);//If pad 3 is pressed 
          { 
           PORTA = 0x11; 
           _delay_ms(1000); 
          } 
         } 
        } 
       } 

     } 

    } 
}` 

任何幫助將不勝感激。

+0

總是給出編譯器錯誤的行信息。在這種情況下,很容易找到,但是(沒有那麼多分配):'i2c_start_wait(mpr03x = I2C_WRITE);' - 這應該怎麼做?您正在嘗試爲文字「0x4A」分配一個值。 – mafso

回答

0

這肯定會導致問題:

i2c_start_wait(mpr03x=I2C_WRITE); //Set device address and write mode 
         ^

...因爲mpr03x不是一個變量。

我的假設是在最後一行代碼中沒有實際的反碼,但我會提到它。

正如別人指出,i2c_stop;看起來像一個錯誤。

相關問題