Required devices: Ultrasonic module
The circuit connection diagram is as follows: Ultrasonic ranging subfunction:
{
unsigned int temp1, temp2; //Define two unsigned integer variables to store distance values
delay(50); //delay
INPUT = 0;
TMR1ON = 1;
while(OUTPUT); //When the ultrasonic output pin outputs a low level, turn off timer 0 and stop timing
TMR1ON = 0;
temp1 = TMR1L; //Assign the lower 8 bits of TMR1 to the temp1 variable
temp2 = TMR1H; //Assign the upper 8 bits of TMR1 to the temp2 variable
temp2 = (temp2 << 8) + temp1; //Shift temp2 left by 8 bits and add temp1
TMR1L = 0; //The low 8 bits of TMR1 are cleared to prepare for the next distance measurement
//Distance = time/2 * speed
//Distance: distance; time: temp2/2 in μs; speed: 340m/s
//Pay attention to the units here, and need to convert them so that the final distance unit is cm/s
distance = temp2 * 1.7/100; //There is a certain error, which can be filled by software. According to the actual measured value, add or subtract an error value to the expression on the right.
return distance; //Return the distance value measured by ultrasound. Here, distance is a global variable and can be used in other programs, such as the LCD display part, which can be passed as an actual parameter to its corresponding program for display.
}
Finally: I really appreciate Google's interview question: Use 3 sentences to explain to the old lady what a database is. Jobs said: "The best thing is to focus on simplicity" because simple things are harder to do than complex things.
Previous article:Design of digital vortex flowmeter based on single chip microcomputer
Next article:A brief discussion on the relationship between RAM and assembly program in PIC8-bit microcontroller
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Teaching flowchart template sharing
- Does anyone know why bluenrg_2 adds +2 to the feature value when subscribing to it?
- In the 51 MCU serial communication mode 1, what kind of clock does timer 1 provide to the serial port module?
- Why does the Ethernet interface circuit need to be connected to GND through resistors and capacitors?
- Automotive External Amplifiers
- Award-winning live broadcast | Firmware upgrade solution for Renesas MCU
- Into space: Solid-state power amplifiers aid space exploration
- Frequency deviation definition and measurement method
- Load Modulation High Efficiency Linear Microwave Circuits—Base Station PA and Doherty
- Compile QT5 application with qt creator