問題如下: 如果只是打開電源燒錄上去(電源開關(guān)有三檔,第一檔是關(guān)閉,第二檔是用于調(diào)試,不轉(zhuǎn)動車輪,第三檔打開讓車輪轉(zhuǎn)動),調(diào)試得到的返回值和執(zhí)行是沒有問題的。 但是當(dāng)開啟第三檔,讓車輪轉(zhuǎn)動后,就會同時執(zhí)行if和else,并且else得到的值永遠(yuǎn)是0. 請各位高手指點(diǎn)下,謝謝各位大神
- void main()
- {
- int xx; //儲存超聲波測距的值
- uart_Init(); //初始化串口
- while(1)
- {
- xx=GetF_juli(); //獲取超聲波測距的值
- if(xx>30)
- {
- printf("%d\n",xx); //輸出獲取的值,用于調(diào)試
- Forward(); //執(zhí)行前進(jìn)
- Delay_nms(100); //延遲
- }
- else
- {
- back(); //執(zhí)行后退
- printf("%d\n",xx); //輸出獲得的值,用于調(diào)試
- delay_nms(100); //延遲
- }
- }
- }
復(fù)制代碼
|