小車測試程序
0.png (52.38 KB, 下載次數: 15)
下載附件
2018-9-19 00:32 上傳
論文:
0.png (34.92 KB, 下載次數: 19)
下載附件
2018-9-19 00:35 上傳
單片機源程序如下:
- /**************************Timer0*********************************************/
- #include <REGX51.H>
- #include <intrins.h>
- #define RightSenser P1_4 //左巡線
- #define LeftSenser P1_5 //右巡線
- unsigned char a,b,k,j;de;
- void delay10ms() //延時函數
- {
- for(a=100;a>0;a--)
- for(b=225;b>0;b--);
- }
- //********************************************************
- //********************************************************
- main()
- {
- delay10ms();
- delay10ms();
- delay10ms();
- delay10ms();
- while(1)
- {
- P1_0 = 1 ;
- P1_1 = 1 ;
- P1_2 = 1 ;
- P1_3 = 1;
-
- if((!RightSenser) && LeftSenser) // 如果右邊假,左邊真
- {
-
- P1_0 = 0 ;
- P1_1 = 1 ;
- P1_2 = 1 ;
- P1_3 = 1;
- delay10ms();
- delay10ms();
- }
- if(RightSenser && (!LeftSenser)) // 如果左邊假,右邊真
- {
- P1_2 = 0 ;
- P1_3 = 1;
- P1_0 = 1 ;
- P1_1 = 1 ;
-
- delay10ms();
- delay10ms();
- }
- if((RightSenser) && (LeftSenser)) // 如果左邊假,右邊真
- {
- P1_0 = 0 ;
- P1_1 = 1 ;
- P1_2 = 0 ;
- P1_3 = 1;
-
-
- for (de=0; de<100; de++); // 延時
- }
- if((!RightSenser) && (!LeftSenser)) // 如果左邊假,右邊真
- {
- P1_0 = 0 ;
- P1_1 = 1 ;
- P1_2 = 1 ;
- P1_3 = 0;
-
-
-
- delay10ms();
- delay10ms();
- delay10ms();
- }
- }
- }
復制代碼
所有資料51hei提供下載:
小車測試程序.rar
(1.14 MB, 下載次數: 22)
2018-9-18 22:24 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|