標(biāo)題: 兩個傳感器循跡程序(詳細(xì)注釋的單片機程序) [打印本頁]

作者: 空白畫    時間: 2018-2-24 09:01
標(biāo)題: 兩個傳感器循跡程序(詳細(xì)注釋的單片機程序)
兩個傳感器循跡程序(詳細(xì)注釋)
單片機源程序如下:
  1. #include <reg52.h>
  2. #define uint unsigned int
  3. #define uchar unsigned char
  4. sbit left=P2^6;
  5. sbit right=P2^7;
  6. sbit s1=P2^2;
  7. sbit s2=P2^3;
  8. sbit s3=P2^0;
  9. sbit s4=P2^1;
  10. void run()
  11. {
  12.   s1=1;s2=0;//前進
  13.         s3=1;s4=0;
  14. }
  15. void right_run()//右轉(zhuǎn)
  16. {
  17.   s1=1;s2=0;//左輪前進右輪不動
  18.         s3=0;s4=0;
  19. }
  20. void left_run()//左轉(zhuǎn)
  21. {
  22.         s1=0;s2=0;//左輪不動右輪前進
  23.         s3=1;s4=0;
  24. }
  25. void stop_run()
  26. {
  27.         s1=0;s2=0;s3=0;s4=0;
  28. }
  29. void main ()
  30. {
  31.         while(1)
  32. {
  33.         if(left==0&&right==0)
  34. {
  35.         run();
  36. }
  37.   if(left==1&&right==1)
  38. {
  39.         stop_run();
  40. }
  41.   if(left==1&&right==0)
  42. {
  43. left_run();
  44. }
  45.   if(left==0&&right==1)
  46. {
  47. right_run();
  48. }       
  49. }
  50. }
復(fù)制代碼

所有資料51hei提供下載:
兩個傳感器.zip (23.69 KB, 下載次數(shù): 6)







歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1