標(biāo)題: 智能循跡小車前進(jìn)后退代碼 [打印本頁(yè)]

作者: 合同方    時(shí)間: 2018-3-26 15:34
標(biāo)題: 智能循跡小車前進(jìn)后退代碼


單片機(jī)源程序如下:
  1. #include<reg51.h>
  2. #define ucahr unsigned char
  3. #define uint unsigned int
  4. #define uchar unsigned char
  5. sbit BZ=P3^5;
  6. sbit P00=P0^0;
  7. sbit P01=P0^1;
  8. sbit P02=P0^2;
  9. sbit P03=P0^3;
  10. void delay(uchar x)
  11. {
  12. uchar y;
  13. for(;x>0;x--)
  14.   for(y=120;y>0;y--) ;
  15. }

  16. void main()
  17. {
  18. while(1)
  19. {
  20. P00=1;
  21. P01=0;
  22. P02=1;
  23. P03=0;
  24. if(BZ==0)
  25. {
  26. P00=0;
  27. P01=1;
  28. P02=0;
  29. P03=1;
  30. delay(100);
  31. }
  32. }
  33. }
復(fù)制代碼







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