超聲波避障小車編程程序_第1頁
超聲波避障小車編程程序_第2頁
超聲波避障小車編程程序_第3頁
超聲波避障小車編程程序_第4頁
超聲波避障小車編程程序_第5頁
全文預覽已結(jié)束

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領

文檔簡介

附錄:超聲波避障小車程序源代碼#include"warterlight.h"#include"steer.h"#include<reg52.h>voiddelay_ms(unsignedintms);externvoidwrite_com(unsignedchardat,unsignedchartest_flag);externvoidwrite_date(unsignedchardat);externvoiddisplay(void);externvoidinit1602();externvoidforward();externvoidstop();externvoidturn_left();externvoidturn_right();externvoidbackward();unsignedchardistance;sbitso=P3人4;sbitled=P1A5;voiddisplay(void){unsignedcharge,shi,bai,d;d=(unsignedchar)distance;bai=d/100;ge=d%10;shi=d/10%10;write_com(0x80+0x0b,0);write_date(bai+0x30);write_date(shi+0x30);write_date(ge+0x30);}voidmain(void){chari;unsignedintk=0,j=0;so=0;init1602();//液晶初始化while(1){k=0;/*產(chǎn)生約5us的脈沖*/so=1;i++;i++;i++;so=0;delay_nus(50);/*延時一段時間,度過不穩(wěn)定期*/while(so)//脈沖來了{k++;//表征脈沖的寬度}if(k){distance=k/10;display();if(distance>10){led=1;for(j=3;j>0;j--){forward();}}else{led=0;turn_left();}}}}#include"steer.h"#include<reg52.h>sbitP1_O=PMO;sbitP1_1=P1A1;voiddelay_nus(unsignedinti){i=i/10;while(--i);}voidforward(){P1_0=1;delay_nus(1300);P1_0=0;P1_1=1;delay_nus(1700);P1_1=0;delay_nus(20000);TR1=1;}voidstop(){P1_0=1;delay_nus(1500);P1_0=0;P1_1=1;delay_nus(1500);P1_1=0;delay_nus(20000);TR1=1;}voidbackward(){P1_0=1;delay_nus(1700);P1_0=0;P1_1=1;delay_nus(1300);P1_1=0;delay_nus(20000);}voidturn_left(){unsignedinti;for(i=30;i>0;i--){P1_0=1;delay_nus(1300);P1_0=0;P1_1=1;delay_nus(1300);P1_1=0;delay_nus(20000);}}voidturn_right(){unsignedinti;for(i=30;i>0;i--){TR1=0;P1_0=1;delay_nus(1700);P1_0=0;P1_1=1;delay_nus(1700);P1_1=0;delay_nus(20000);TR1=1;}}#include"waterlight.h"#include<reg52.h>#defineuintunsignedint#defineucharunsignedcharvoiddelay_ms(uintms);voidinit1602(void);voidwrite_com(uchardat,uchartest_flag);voidwrite_date(uchardat);voiddisplay(void);voidbusy(void);sbitLcd_rs=P2人2;sbitLcd_rw=P2A1;sbitLcd_en=P2A0;ucharcodeTAB1[]="distancecm";voiddelay_ms(uintms){uintx,y;for(x=ms;x>0;x--)for(y=70;y>0;y--);}voidwrite_com(uchardat,uchartest_flag){uchartemp;if(test_flag==1)busy();Lcd_rw=0;Lcd_rs=0;P0=0x0f;//置高temp=0xf0&dat;P0=temp;Lcd_en=1;Lcd_en=1;Lcd_en=0;P0=0x0f;temp=(0x0f&dat)<<4;P0=temp;Lcd_en=1;Lcd_en=1;Lcd_en=0;}voidwrite_date(uchardat){uchartemp;busy();Lcd_rw=0;Lcd_rs=1;P0=0x0f;temp=0xf0&dat;P0=temp;Lcd_en=1;Lcd_en=1;Lcd_en=0;P0=0x0f;temp=(0x0f&dat)<<4;P0=temp;Lcd_en=1;Lcd_en=1;Lcd_en=0;}voidinit1602(void){uchari;Lcd_rw=0;delay_ms(20);Lcd_en=0;write_com(0x28,0);delay_ms(1);write_com(0x28,0);delay_ms(1);write_com(0x28,0);delay_ms(1);write_com(0x28,1);write_com(0x08,1);write_com(0x0c,1);write_com(0x06,1);write_com(0x01,1);write_com(0x80+0x00,0);for(i=0;i<16;i++){write_date(TABl[i]);//寫第一行}

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論