Simulation and source code of a simple automatic tracking car based on single chip microcomputer control

Publisher:CelestialMagicLatest update time:2019-11-14 Source: 51hei Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

This task requires the design and production of a simple automatic tracking car based on single-chip microcomputer control. The car uses AT89C51 as the control core, and uses the single-chip microcomputer to generate PWM waves to control the speed of the car. Use infrared photoelectric sensors to detect black tracks on the road surface, and feed back the road detection signal to the single-chip microcomputer. The single-chip microcomputer analyzes and judges the collected signals, and promptly controls the drive motor to adjust the steering of the car, so that the car can automatically drive along the black track, achieving the purpose of automatic tracking of the car. Heating is represented by a red light-emitting diode. The red light is on to indicate heating, and the red light is off to indicate that heating is stopped.

The attachments include: proteus simulation diagram, C source code, hex file.

The microcontroller source program is as follows:

#include

#define uchar unsigned char

#define uint unsigned int

unsigned char zkb1=0; //**Duty cycle of the left motor**//

unsigned char zkb2=0; //**Duty cycle of the right motor**//

unsigned char t=0; //**Timer interrupt counter**//

sbit RSEN1=P1^0;

sbit RSEN2=P1^1;

sbit LSEN1=P1^2;

sbit LSEN2=P1^3;

sbit IN1=P0^0;

sbit IN2=P0^1;

sbit IN3=P0^2;

sbit IN4=P0^3;

sbit ENA=P0^4;

sbit ENB=P0^5;

//****************Delay function********************//

void delay(int z)   

{   while (z--);  }

//**********Initialize timer, interrupt***********//

void init()

{  TMOD=0x01;

   TH0=(65536-100)/256;

   TL0=(65536-100)%256;

   EA=1;

   ET0=1;

   TR0=1;

}

//***********Interrupt function + pulse width modulation***********//

void timer0() interrupt 1

{ if(t     THIS=1;

  else 

     THIS=0;

  if(t      ENB=1;

  else 

      ENB=0;

            t++;

  if(t>=100)

    {t=0;}

}

//******************Direct******************//

void qianjin()

{ zkb1=30;

    zkb2=30;

}

//***************Left turn function 1***************//

void turn_left1()

{ zkb1=0;

    zkb2=50;

}

//***************Left turn function 2***************//

void turn_left2()

{ zkb1=0;

    zkb2=60;

}

//***************Right turn function 1***************//

void turn_right1()

{ zkb1=50;

    zkb2=0;

}

//***************Right turn function 2***************//

void turn_right2()

{ zkb1=60;

    zkb2=0;

}

//***************Tracing function********************//

void xunji() 

{ uchar flag;

  if((RSEN1==1)&&(RSEN2==1)&&(LSEN1==1)&&(LSEN2==1))

    { flag=0; }//*******Direct*******//

   else  if((RSEN1==0)&&(RSEN2==1)&&(LSEN1==1)&&(LSEN2==1))

    { flag=1;} //***Left 1, right 1***//

   else  if((RSEN1==0)&&(RSEN2==0)&&(LSEN1==1)&&(LSEN2==1))

    { flag=2;} //***Left 2, right 2***//

   else if((RSEN1==1)&&(RSEN2==1)&&(LSEN1==0)&&(LSEN2==1))

    { flag=3; }//***turn right 1, turn left 1***//

  else if((RSEN1==1)&&(RSEN2==1)&&(LSEN1==0)&&(LSEN2==0))

    { flag=4; }//***turn right 2, turn left 2***//

  switch (flag)

     { case 0:qianjin();

              break;

        case 1:turn_right1();

              break; 

        case 2:turn_right2();

              break; 

        case 3:turn_left1();

              break; 

        case 4 :turn_left2();

              break;

        default:break;

      }

}

//****************Main program****************//

void main()

{ heat();

  zkb1=30;

  zkb2=30;

  while(1)

  { IN1=1; //******Power on the motor to start******//

     IN2=0;

     IN3=1;

     IN4=0;

     THIS=1;

     ENB=1;

        while(1)

     { xunji(); //*********Tracing the trace**********//

     }

    }

}



Reference address:Simulation and source code of a simple automatic tracking car based on single chip microcomputer control

Previous article:The microcontroller performs different functions by pressing a single button (long or short press)
Next article:Source program circuit diagram of optical drive laser engraving machine based on 51 single chip microcomputer + host computer

Popular Resources
Popular amplifiers
Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号