Abstract: This paper describes the performance and characteristics of the AT89C2051 microcontroller, and ultrasonic distance measurement principle of the analysis of the essence, that the design ideas and rangefinder issues need to be considered, given the program to achieve a soft ultrasonic distance measurement, hardware design system block diagram. The design system has been adjusted, the measurement accuracy of 0.1 meters.
Key words: ultrasound; transducer; distance; AT89C2051
Key words: TM930.9 Document ID: B Article ID :1006 -6977 (2000) 12-0031-04
Mainly used in parking sensor ultrasonic distance measurement, construction sites and some industrial sites, such as: level, well depth, pipe length and other occasions. At present, the general ASIC design using ultrasonic range finder, but the high cost of ASIC, and no display, very easy to use. This paper describes a microcontroller to the core GSM97C2051 AT89C2051 or low-cost, high precision, miniature ultrasonic range finder digital display hardware and software design. Proof of actual use of the instrument is stable and good performance.
An ultrasonic ranging principle
Been detected by ultrasonic ranging launch ultrasonic echo reflected from an obstacle to measure the transmit and receive echoes of the time difference t, and then find the distance S = Ct / 2, where the C for the ultrasonic wave velocity.
Because ultrasound is a sound wave, the speed of sound C and the temperature, Table 1 shows the speed of sound in several different temperatures. In use, if the temperature changes little, you can view the speed of sound is basically unchanged. If the distance measurement precision is high, the temperature compensation method should be adopted correction. Speed of sound determined, as long as measured from the time of ultrasonic, the distance can be obtained. This is the mechanism of ultrasonic range finder. The system block diagram shown in Figure 1.
Table 1 Relationship between sound velocity and temperature table
Temperature (?) -30-20-100102030100
Velocity (m / name) 313319325323338344349386
2 AT89C2051 functional characteristics
2k bytes AT89C2051 is a high-performance programmable EPROM microcontroller. It is with the industry standard MCS-51 instructions and pin-compatible, so it is a powerful microcontroller, many embedded control applications, it provides a highly flexible and effective solutions. AT89C2051 has the following characteristics: 2k bytes EPROM, 128 bytes of RAM, 15 ? I / O lines, two 16-bit timer / counter, five vector two interrupt architecture, a full two-way serial port, and includes precision analog comparator, and on-chip oscillator, a voltage 4.25V to 5.5V operating range and 12MHz/24MHz operating frequency, and also offers an array of secondary encryption program memory locking, power down and clock circuit. In addition, AT89C2051 also supports two software selectable power saving mode. Idle, CPU stops, and let the RAM, timer / counters, serial port and interrupt system to continue working. Power-down the contents of RAM can be saved, but can chip oscillator to stop to prohibit all other functions until the next hardware reset.
AT89C2051 has two 16-bit timer / counter register Timer0t Timer1. As a timer, an increase of 1 per machine cycle registers, such registers to count machine cycles. Because a machine cycle of 12 oscillator periods, so the oscillator frequency count rate is 1 / 12. As a counter, the register in the corresponding external input pin P3.4/T0 and P3.5/T1 appeared from 1 to 0 change by 1. Two machine cycles because of the need to identify changes in a 1 to 0, so the maximum count rate is the oscillator frequency, 1 / 24, the external input can P3.2/INT0 and P3.3/INT1 programming, ease of measurement pulse width of the door.
Full use of resources within the AT89C2051 chip can in rare cases, the external circuit constitutes a functional ultrasonic ranging system.
3 System hardware design
Ultrasonic range finder of the hardware circuit shown in Figure.

AT89C2051 external pin P1.6 output pulse width of 250µs, the carrier 10 to 40kHz pulse burst to the form added to the transformer primary push-pull, the Boost launched to promote the ultrasonic transducer out. The launch at the same time, P1.7 outputs a high start charging the capacitor C4. Launch high end of flipping is low, C4 began to R2, R3, and the discharge voltage divider composed of the comparator output to the negative side. Ultrasonic receiving transducer receives the reflected ultrasonic obstacle to zoom in to the amplifier, which is a high-gain, low noise amplifier, in the amplified echo signal detector will detect the positive input to the comparator end. Launch P1.7 output level can inhibit the comparator flip, so that you can inhibit the firing of the ultrasonic transmitter to the receiver directly caused by radiation error detection.
Figure 3 is a waveform diagram of ultrasonic ranging principle, can be seen from the figure, measured echo and the time interval between the transmit pulse, using S = Ct / 2 the distance can be calculated and then displayed on the LCD. Of course you can set the number of keys used to control the working status of the circuit. Limit the maximum measurable distance of the system there are four factors: the magnitude of ultrasonic reflection and texture, reflection and the angle between the incident wave and the receiving transducer sensitivity. Receiving transducer for the direct reception of sound pulses to determine the smallest measurable distance.
4 System Software Design
AT89C2051 microcontroller and its development and application system is the language simple and portable, strong communication skills, presentation flexible, structured design, and can control the computer hardware to generate the code of high quality, easy to use, and many other advantages. Ultrasonic range finder is designed with AT89C51 microcontroller development. It is modular, the main program, launch routine, check Xiang to receive routine, regular routines, display routines and other modules.
Figures 4 and 5, respectively, and measuring the main program block diagram of a subroutine. The system's main work in the keying cycle, when you press the measurement button, launch the main program calls subroutine start, check to receive subroutine, time subroutine, and the measurement results with the display routines are displayed on the LCD screen .
Must be noted that, due to the LCD to use the same port P3, so must all use bit operations will cause LCD does not display properly. In addition, the system can also add temperature sensors to monitor ambient temperature, the data listed in Table 1 may be procedures to be compensation for temperature. To enhance the reliability of the system should adopt some special measures on the hardware and software. Due to space limitations, the following gives only part of the program, interested may contact the author.
# Pragma DB OE CD OT (5, SPEED) ROM (LARGE) IV
/ * Connect the required libraries * /
# Include
# Include
# Include
/ * Define the data type * /
typedef unsingned char byte;
typedef unsigned int word
# Define uchar unsigned char
# Define unint unsigned int
# Define ulong unsigned long
/ * Define system constants * /
# Define TRUE 1
# Define FALSE 0
# Define C = 340 / * Velocity * /
/ * Define function bit * /
sbit bflag = ACC7;
sbit VOLCK = P1 ^ 5;
sbit MING = P3 ^ 5;
sbit QUIET = P1 ^ 3;
sbit BACK = P1 ^ 2;
/ * Define display buffer * /
uchar idata ON [16 ]={',' L ',' E ',' N ',' G ',' T ',' H','=',' 8','.',' 8'8 ',' m','','',''};
/ * Main program with the delay subroutine * /
woid main-delay (void)
{
register i;
TRO = 1;
for (i = 0; i <15; i + +)
{
TH0 = 0;
TL0 = 0;
Do {} while (! TF0);
TF0 = 0;
}
TR0 = 0;
}
* / Generic delay subroutine * /
void delay (void)
{
unint i;
for (i = 0; i <200; i ++){;}
}
/ * Keyboard delay routine * /
void key-delay (void)
{
unint i;
for (i = 0; i <200; i ++){;}
}
/ * Initialize the program * /
void start_main ()
{
tegister i;
uchar a [16 ]={'',' L ',' E ',' N ',' G ',' T ',' H','=,' 8','.',' 8 ',' 8 ',' m','','',''};
for (i = 0; <16; i + +)
{ON [i] = a [i];}
nitlcd ();/* initialize LCD * /
display (ON); / * update display * /
}
/ * Main program * /
void main ()
{
register s, keycode;
long idata t;
start-main ();/* initialization * /
main-delay ();/* delay * /;
if (keycoed = = true)
{
keycode = key-scan-wait ();
/ * Determine whether there is measurement key is pressed * /
t = measure ();*/ measurement * /
S = 0.5 * t * C; * / conversion * /
Decode-bcd (s.0x09);
/ * Replacement of the measurement results into the display buffer * /
init-lcd ();/* initialize LCD * /
display (ON); / * update display * /
}
}
5 Conclusion
Although the circuit with a single timer can also measure the transmission time of ultrasound, but the use of AT89C2051 microcontroller simplifies design, easy operation and intuitive readings. The practical tests proved the system to meet the requirements of the majority of occasions ranging.