这是我的反向停车项目...此代码在没有 IF 语句的情况下工作。当我将 IF 语句放入代码中时,我的硬件没有响应。(IF 语句在 void main...)
感谢帮助!
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);
}