|
有小車(chē)循跡
有紅外遙控
有聲控小車(chē)
有超聲波避障
電路原理圖如下:
單片機(jī)源程序如下:
- #include<reg52.h>
- #define uchar unsigned char
- #define uint unsigned int
- sbit pwm=P2^7; //P2.7為PWM腳。
- uchar count,angle; //計(jì)數(shù)和角度。
- void delay_100us() //100us延時(shí),相當(dāng)于0.1ms
- {
- uchar j;
- for(j=0;j<31;j++)
- {
- ;
- }
- }
- void toji()
- {
- while(count<200) //count少于200時(shí),無(wú)限循環(huán),相當(dāng)于20ms為一個(gè)周期
- {
- if(count<angle) //count少于角度。
- {
- pwm=1; //pwm輸出高電平。
-
-
- }
-
- else //其它情況
- {
- pwm=0; //pwm輸出低電平。
- }
- delay_100us(); //延時(shí)100us,相當(dāng)于0.1ms
- count++; //count自加1。
- }
- count=0; //當(dāng)count經(jīng)歷200次后,count歸0
- }
- void main()
- {
- count=0;
- while(1)
- {
- angle=5; //角度為5ms
- toji(); //調(diào)用舵機(jī)子程序。
-
- }
- }
復(fù)制代碼
所有資料51hei提供下載:
03 小車(chē)程序與電路.rar
(3.23 MB, 下載次數(shù): 53)
2020-12-22 09:38 上傳
點(diǎn)擊文件名下載附件
|
|