本文介绍了无法解释的“错误 C141:语法错误"在 Arduino 上的 C 语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近才开始对 Arduino 进行编程,但我遇到了一些奇怪的语法错误,在我的第一个练习中我根本不明白这些错误.

I've been getting into programming an Arduino just recently and I'm getting some weird Syntax errors which I dont understand at all in some of my first exercises.

这是第一个:

#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 行遇到两个语法错误,一个靠近 '==',另一个靠近 ')'.不知道为什么.

Here im getting two syntax errors on line 17, one near '==' and one near ')'. No clue why.

这是第二个:

#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 上运行任何构建.

Here Im getting two syntax error on line 15, one near '=' and one near '<<'. Again no clue why.Could someone please enlighten me on the matter? I can't try and run any builds on my arduino this way .

推荐答案

不要在宏中使用分号.

#define LEDS P4;
#define SWITCH P5;

这篇关于无法解释的“错误 C141:语法错误"在 Arduino 上的 C 语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 15:53