gpt4 book ai didi

c - 在嵌入式 C 中显示 "expected expression before while"

转载 作者:行者123 更新时间:2023-11-30 20:34:23 24 4
gpt4 key购买 nike

考虑:

#include <avr/io.h>

int main(void)
{
DDRB = 0b11111111; // PORTB as output port connected to motors;
DDRC = 0b0000000; // PORTC Input port connected to sensors;
int left_sensor = 0;
int right_sensor = 0;
while(1)
{
left_sensor = PINC&0b00000001;
right_sensor = PINC&0b00001000;
if((left_sensor==0b0000000) && (right_sensor==0b0000000))
{
PORTB = 0b00000000;
}
else if((left_sensor==0b00000001) && (right_sensor==0b00001000))
{
PORTB = 0b00010010;
}
else if((left_sensor==0b0000000) && (right_sensor==0b0001000))
{
PORTB = 0b00000010;
}
else if((left_sensor==0b00000001) && (right_sensor==0b0000000))
{
PORTB = 0b00010000;
}
}
}

它显示“while 之前的预期表达式”。我已经尝试了一切,但没有得到任何解决方案。

错误:

Expected Expression before 'while'

编译器:Atmel Studio 7

最佳答案

如果我复制并粘贴您问题中的代码,请删除 AVR 特定行并尝试编译它,我会得到以下结果:

source_file.c: In function ‘main’:
source_file.c:4:10: error: stray ‘\315’ in program
int right_sensor=0;
^
source_file.c:4:10: error: stray ‘\276’ in program
source_file.c:5:10: error: expected ‘,’ or ‘;’ before ‘while’
while(1)
^

删除带有 right_sensor 声明的行并重写它可以解决问题 - 该行中似乎有一些奇怪的非打印字符。

关于c - 在嵌入式 C 中显示 "expected expression before while",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42732920/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com