标题: 这是我写的一个循迹小车的源程序 [打印本页]

作者: zcq050607    时间: 2018-5-2 17:12
标题: 这是我写的一个循迹小车的源程序
这是我做的利用51单片机,还有红外传感器做的一个循迹小车的程序。还有一些智能小车的资料。有需要的同学,请自行下载。


单片机源程序如下:
  1. #include <reg52.h>
  2. #include <intrins.h>

  3. #define uint unsigned int
  4. #define uchar unsigned char
  5. sbit pwm1=P2^6;
  6. sbit pwm2=P2^2;
  7. sbit pwm3=P2^1;
  8. sbit pwm4=P2^0;

  9. sbit en1=P2^4;
  10. sbit en2=P2^5;

  11. sbit s1=P3^6;
  12. sbit s2=P3^7;
  13. uint count,c2;
  14. void delay(int x)
  15. {
  16.   int i,j;
  17.   for(i=0;i<x;i++)
  18.   for(j=0;j<120;j++);
  19. }
  20. void init()
  21. {
  22.         TMOD=0x01;
  23.         TH0=(65536-500)/256;
  24.         TL0=(65536-500)%256;
  25.         EA=1;
  26.         ET0=1;
  27.         TR0=1;
  28. }
  29. void Go()
  30. {
  31.         pwm1=0;
  32.         pwm2=1;
  33.         pwm3=1;
  34.         pwm4=0;
  35. }
  36. void you()
  37. {
  38.         pwm1=0;
  39.         pwm2=1;
  40.         pwm3=0;
  41.         pwm4=1;
  42. }
  43. void zuo()
  44. {
  45.         pwm1=1;
  46.         pwm2=0;
  47.         pwm3=1;
  48.         pwm4=0;
  49. }
  50. void stop()
  51. {
  52.         pwm1=0;
  53.         pwm2=0;
  54.         pwm3=0;
  55.         pwm4=0;       
  56. }

  57. void main()
  58. {
  59.         init();
  60.         while(1)
  61.         {
  62.                 if(s1==0&&s2==0)Go();
  63.                 else if(s1==1&&s2==0)zuo();
  64.                 else if(s1==0&&s2==1)you();

  65.                 else
  66.                 stop();
  67.         }       
  68. }


  69. void t0() interrupt 1
  70. {
  71.         TH0=(65536-500)/256;
  72.         TL0=(65536-500)%256;
  73.         count++;
  74.         c2++;
  75.         if(count==100)count=0;
  76.         if(c2==100)c2=0;
  77.         if(count<35)
  78.         {       
  79.                 en1=1;
  80.                        
  81.         }
  82.         else
  83.         {
  84.                 en1=0;
  85.                        
  86.         }
  87.                 if(c2<35)
  88.         {       
  89.                
  90.                 en2=1;       
  91.         }
  92.         else
  93.         {
  94.                 en2=0;       
  95.         }       
  96. }
复制代码

所有资料51hei提供下载:
智能车.zip (2.99 MB, 下载次数: 13)





作者: ycfLang    时间: 2018-5-2 23:59
有个警告!!!




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1