【问题标题】:error: lvalue required as left operand of assignment, error: void value not ignored as it ought to be错误:需要左值作为赋值的左操作数,错误:应忽略的无效值
【发布时间】:2014-06-27 17:54:14
【问题描述】:

我收到这些错误:

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

基本上我有一个 i2c 电容式触摸控制器,我会不断扫描它,然后检查扫描的数据,然后在需要时执行 d 操作,然后重复。

这是我的代码:

#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);
                            }
                        }
                    }
                }

        }

    }
}`

任何帮助将不胜感激。

【问题讨论】:

  • 总是给出编译器错误的行信息。不过,在这种情况下,很容易找到(没有那么多作业):i2c_start_wait(mpr03x=I2C_WRITE);——这应该做什么?您正在尝试为文字 0x4A 赋值。

标签: c void avr lvalue avrdude


【解决方案1】:

这肯定会出问题:

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

...因为mpr03x 不是变量。

我的假设是最后一行的代码中实际上并没有反引号,但我还是会提到它。

正如其他人指出的那样,i2c_stop; 看起来像是一个错误。

【讨论】:

    猜你喜欢
    • 2011-12-20
    • 2011-03-04
    • 2017-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-01
    相关资源
    最近更新 更多