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 else THIS=0; if(t 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**********// } } }
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
- Learn ARM development(14)
- Learn ARM development(15)
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Today's live broadcast: TE will explain the design trends of smart antennas and sensor application cases in the Internet of Things
- msp430 implements a key matrix scan and UART transmission
- MSP430 ADC acquisition filter
- 【GD32E231 DIY】USART0 uses DMA to send and receive, without using CPU
- Soil moisture measurement circuit diagram
- [2022 Digi-Key Innovation Design Competition] Material Unboxing - ESP32-S2 and ESP32-S3
- 【Silicon Labs BG22-EK4108A Bluetooth Development Evaluation】+Mobile phone control LED and button status display
- [AT-START-F425 Review] USB to CAN VI Complete Dynamic Settings for Transceiver
- [CC1352P Review] BLE Program Framework
- EEWORLD University ---- Robotics