2017-03-11 27 views
-2
#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 while」。 我嘗試了一切,但我沒有得到任何解決方案。它在嵌入式c中顯示「預計表達式」while

錯誤:Expected Expression before 'while'

編譯:愛特梅爾工作室7

+0

我想你會得到這個錯誤,因爲'DDRB'和/或'DDRC'未定義。通過「」回溯並確保包含正確的設備文件。 –

+0

在您的問題中包含編譯器輸出逐字(複製和粘貼),以便我們可以看到確切的錯誤和編譯器調用。使用的編譯器及其版本也可以幫助任何可能回答 – Clifford

+0

Atmel Studio 7的人是IDE而不是編譯器。它可以與各種編譯器一起使用。這不是完整的編譯日誌 - 編譯器診斷對診斷問題和包含您省略的信息很有用。 – Clifford

回答

0

如果我複製&粘貼從你的問題的代碼刪除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聲明並重寫它可以解決問題 - 您似乎有一些奇怪的非打印字符在行中。