Schematic diagram and complete program download: http://www.51hei.com/bbs/dpj-19526-1.html
The following is part of the program:
#include
unsigned int i=0;
sbit P36=P3^6;
sbit P10=P1^0; //Tracking port
sbit P11=P1^1;
sbit P12=P1^2;
sbit P14=P1^4; //电机口
sbit P15=P1^5;
sbit P16=P1^6;
sbit P17=P1^7;
unsigned char j,time;
unsigned int kop,dr;
unsigned char a[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
unsigned char c[4]={0xff,0xff,0xff,0xff},d[4];
void delay(unsigned char z) //delay subroutine
{
unsigned char j;
while(z--)
for(j=123;j>0;j--);
}
void main()
{
TMOD=0x15; // Turn on the timer and counter
TH0=0x00;
TL0=0x00;
TH1=0XFc; //1ms
TL1=0X18;
EA = 1;
ET0=1;
ET1=1;
TR1 = 1;
TR0 = 1;[page]
while(1)
{
if(P10==0&&P11==0&&P12==0)
{
TR0=0; //Display time stop
P0=d[0];
P2=0XFE;
delay(1);
P0=d[3];
P2=0XFB;
delay(3);
P0=d[2]; //Display speed measurement stop
P2=0XFD;
delay(3);
P0=d[3];
P2=0XF7;
delay(3);
P14=1;P15=1;P16=1; P17=1;
}
}
}
void timer1() interrupt 3 //Interrupt service routine
{
unsigned int qq=0,ww=0;
TH1=0XFc;
TL1=0X18;//1ms
i++;
switch(i%4)
{
case 0:P0=c[0],P2=0XFE;d[0]=c[0];break;
case 1:P0=c[1],P2=0XFD;d[1]=c[1];break;
case 2:P0=c[2],P2=0XFB;d[2]=c[2]; break;
case 3:P0=c[3],P2=0XF7;d[3]=c[3]; break;
default:break;
}
P14=1;P15=1;P16=1; P17=1;
if(P10==0&&P11==0&&P12==0) //The whole is
dr=0;
if(P10==1&&P11==0&&P12==1) //The middle is
dr=1;
if(P10==0&&P11==1&&P12==1) //The left side is
dr=2;
if(P10==1&&P11==1&&P12==0) //The right side is
dr=3;
if(P10==0&&P11==0&&P12==1) //The left two are
dr=4;
if(P10==1&&P11==0&&P12==0) //2 right detections
dr=5;
switch(dr)
{
case 0:P14=1,P15=1,P16=1,P17=1,TR1=0;break; //2 left detections stop
case 1:P14=0,P15=1,P16=0,P17=1;break; //Go straight
case 2:P14=1,P15=1,P16=0,P17=1,ww=1;break; //Turn left
case 3:P14=0,P15=1,P16=1,P17=1,qq=1;break; //Turn right
case 4:P14=1,P15=0,P16=0,P17=1,ww=1;break; //2 left detections turn left
case 5:P14=0,P15=1,P16=1,P17=0,qq=1;break; //Measure right and turn right
}
/*Run out of the runway and remember to return to the runway*/
if(dr==2&&ww==1||dr==4&&ww==1) //Single or double side measurement and run out
{
qq=0;
P14=1;P15=1;P16=0;P17=1;
}
if(dr==3&&qq==1||dr==5&&qq==1)
{
ww=0;
P14=0;P15=1;P16=1;P17=1;
}
if(i==1000) //1s
{
kop=TH0;//Counter counts pulses
kop=kop<<8;
kop=kop+TL0;
kop=kop*15;
c[3]=a[kop/10];
c[2]=a[kop%10];
time++;
c[1]=a[time/10];
c[0]=a[time%10];
i=0;
TH0=0;
TL0=0;
}
}
Previous article:Using 51 single chip microcomputer to make simple PLC
Next article:51 MCU tracking car motor driver PWM
- Popular Resources
- Popular amplifiers
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- STMicroelectronics discloses its 2027-2028 financial model and path to achieve its 2030 goals
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- The first! National Automotive Chip Quality Inspection Center established
- BYD releases self-developed automotive chip using 4nm process, with a running score of up to 1.15 million
- GEODNET launches GEO-PULSE, a car GPS navigation device
- Should Chinese car companies develop their own high-computing chips?
- Infineon and Siemens combine embedded automotive software platform with microcontrollers to provide the necessary functions for next-generation SDVs
- Continental launches invisible biometric sensor display to monitor passengers' vital signs
- Looking for a sound amplification circuit
- [Flower carving hands-on] Interesting and fun music visualization series of small projects (26) - LED hypercube
- The domestic Gaoyun FPGA GWIN-4B development board cannot use the MSPI pin. Please help
- Shanghai is a cold and indifferent society now,,,,,I don't want to say more
- sp485 communication reception is 0x00
- Xunwei 4412 development board Qt network programming-UDP implementation of server and client
- AD Wiring "hitting a wall"! ? ?
- How to solve the three major problems of wireless video surveillance?
- LiteOS Kernel Tutorial 04-Semaphore
- Purgatory Legend-ROM War