c - 无法解释的 "Error C141: syntax error"在 Arduino 上的 C 中

标签 c arduino syntax-error

<分区>

我最近才开始对 Arduino 进行编程,但我遇到了一些奇怪的语法错误,在我最初的一些练习中我根本不理解这些错误。

这是第一个:

#include <REG552.h>

#define LEDS P4;
#define SWITCH P5;

sbit led1 = P4^0;
sbit led2 = P4^1;
sbit led3 = P4^2;
sbit led4 = P4^3;
sbit led5 = P4^4;
sbit led6 = P4^5;
sbit led7 = P4^6;
sbit led8 = P4^7;

void main() {
    while(1){
        if(SWITCH == 0x0F){
            led1 = 0;
            led2 = 0;
            led3 = 0;
            led4 = 0;
            msec(1000);
            led1 = 1;
            led2 = 1;
            led3 = 1;
            led4 = 1;
        }
        if (SWITCH == 0xF0){
            led5 = 0;
            led6 = 0;
            led7 = 0;
            led8 = 0;
            msec(3000);
            led5 = 1;
            led6 = 1;
            led7 = 1;
            led8 = 1;
        }else
            LEDS = SWITCH;
    }
}

void msec(unsigned int tt){
    unsigned char jj;
    while (tt-- > 0){
        for (jj=0;jj<125;jj++){;}
        }
    }
}

我在第 17 行遇到两个语法错误,一个在 '==' 附近还有一个在 ')' 附近.不知道为什么。

这是第二个:

#include <REG552.h>

#define LEDS P4;
#define SWITCH P5;

sbit switch1 = P5^0;

void main() {
    while(1){
        if (switch1 = 0){
            LEDS = 0x01;
            LEDS = LEDS >> 1;
            if else (switch1 = 1){
                LEDS = 0x01;
                LEDS = LEDS << 1;
            }
        }
    }
}

我在第 15 行遇到两个语法错误,一个在 '=' 附近还有一个在 '<<' 附近.再次不知道为什么。 有人可以请教我这件事吗?我不能尝试以这种方式在我的 arduino 上运行任何构建。

最佳答案

不要在宏中使用分号。

#define LEDS P4;
#define SWITCH P5;

关于c - 无法解释的 "Error C141: syntax error"在 Arduino 上的 C 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21159211/

相关文章:

c - 扫描名称和奇怪的字符串: Files

c - 返回一个数组

c++ - 有没有办法定义和发送单个 BIT

Matlab:奇怪的尝试访问错误...索引必须是 pos。整数或逻辑

php - PHP解析/语法错误;以及如何解决它们

c - 具有前向声明副作用的 typedef?

c - 在 C 中从 shell 声明全局 CHAR 数组

Bash、串行 I/O 和 Arduino

try-catch - Arduino 中的 try/catch block

java - 如何在文件阅读器中使用 `for`?