2013-06-05 34 views
0

這是我的反向泊車項目......這段代碼沒有使用IF語句。當我在代碼中放置IF語句時,我的硬件不響應。 (如果在無效的主要報表...) aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa我的項目不能在mikroC中工作

感謝您的幫助!

sbit LCD_RS at RD0_bit; 
sbit LCD_EN at RD1_bit; 
sbit LCD_D4 at RD2_bit; 
sbit LCD_D5 at RD3_bit; 
sbit LCD_D6 at RD4_bit; 
sbit LCD_D7 at RD5_bit; 

sbit LCD_RS_Direction at TRISD0_bit; 
sbit LCD_EN_Direction at TRISD1_bit; 
sbit LCD_D4_Direction at TRISD2_bit; 
sbit LCD_D5_Direction at TRISD3_bit; 
sbit LCD_D6_Direction at TRISD4_bit; 
sbit LCD_D7_Direction at TRISD5_bit; 
//inicializacija LCD modula 

char message1[] = "Distance:"; 

char *dis = "000.0"; 

unsigned int dist; 
float temp_value; 
float x; 
float y; 

void Display_Distance() { 
if (dist/10000) 
    dis[0] = dist/10000 + 48;   //stotice 
else 
     dis[0] = ' '; 
dis[1] = (dist/1000)%10 + 48;  // desetica 
dis[2] = (dist/100)%10 + 48;  // enica 
dis[4] = (dist/10)%10 + 48;  // decimalka 
Lcd_Out(2, 1, dis);    // izpis distance na LCD 
} 


void main() { 
Lcd_Init(); 
Lcd_Cmd(_LCD_CLEAR); 
Lcd_Cmd(_LCD_CURSOR_OFF); 
Lcd_Out(1,1,message1); 
Lcd_Chr(2,7,'C'); 
Lcd_Chr(2,8,'m'); 


do { 
    x = (float)ADC_Read(2); //vrednost iz analognega kanala, kamor je senzor priklopljen 
    y = (((x*5)/1023));  //pretvorba v volte 
    if(y>0){ 
       temp_value = (((log10(y))/(log10(0.98)))+62.6);  //funkcija grafa 



      if(y<=0.8 && y>0.65) 
         temp_value = temp_value+10; 
      else if(y<=0.65 && y>0.6) 
        temp_value = temp_value+17.5; 
      else if(y<=0.6 && y>0.55) 
        temp_value = temp_value+13; 
      else if(y<=0.55 && y>0.5) 
        temp_value = temp_value+3.5; 
      else if(y>=2 && y<2.5) 
        temp_value = temp_value+1.3; 
      else if(y>=2.5 && y<2.8) 
        temp_value = temp_value+4.5; 



       temp_value=temp_value*10000; 
       dist = temp_value/1000; 
       dist = dist*10; 
       Display_Distance();     
       Delay_ms(1000); 
       } 
} while(1); 
} 

回答

0

不得不在我的一個項目上處理這個if語句如果沒有大括號使用時不能正確分支。解決方案是在if/else語句之後使用大括號,即使後面只有一條語句。這是編譯器的一個錯誤。

  if(y<=0.8 && y>0.65) 
        temp_value = temp_value+10; 
     else if(y<=0.65 && y>0.6) 
       temp_value = temp_value+17.5; 

變得

  if(y<=0.8 && y>0.65){ 
        temp_value = temp_value+10; 
     } 
     else if(y<=0.65 && y>0.6){ 
       temp_value = temp_value+17.5; 
     } 

如果程序簡單地崩潰,檢查生成的HEX/ASM。

相關問題