RS485 interface integrated ultrasonic distance measurement module

Publisher:PeacefulOasisLatest update time:2015-10-26 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
   1. Module Introduction:

   This ultrasonic distance measurement module uses STC11F04E single chip microcomputer as processor, working power supply: DC5V, working current 20mA. The measurement data output mode is RS485 output, the data format is standard ASCII code, the data consists of: space bit (starting bit) + hundreds + tens + ones. There are two working modes: one is continuous measurement mode; the other is query measurement mode.

[Reprint] RS485 interface integrated ultrasonic distance measurement module

 

    Measuring range: 36cm~450cm (blind area 36cm).
During the measurement process, when the echo reflected by the obstacle is not received, "CCC" is output, and when the measurement is lower than the lower limit (within the blind area), "- - -" is displayed. The measurement results are output from the output port on the module, and the output method is RS485 output. The measurement results can be displayed on a computer. The module uses the RS485 interface for communication. The measurement results are transmitted over a long distance. Data can be collected through a computer, and it is very convenient to write communication programs.
   Baud rate: 1200
   Check bit: None
   Data bit: 8
   Stop bit: None
   ASCII code Data format: Space bit (start bit) + hundreds + tens + ones.
   2.  Module usage settings
   The working mode of the ultrasonic module can be set, and the setting results can be saved in the microcontroller inside the module, and will not be lost when the power is off. The setting command format is as follows:

[Reprint] RS485 interface integrated ultrasonic distance measurement module


   Query command format: AT+CL=1-32 (0-32 is the address code of the module. The address of each module can be set independently. Use AT+WD="  " command when setting. The code of each module can be set independently by the user. The setting range is 0-32 and is only valid in query mode). The data format is hexadecimal data.
   3.  Module use
   In order to reduce the size of this ultrasonic ranging module, the ultrasonic ranging element is installed on both sides. The module is 6.2cm long and 2.4cm wide. The module can be used as a ranging module for the application system. It can be used in products such as liquid level detection, parking space detection, and distance measurement. There are mounting holes on the board and a row of 6-pin pins. The test display program example is as follows:
#include                      //header file
#include                     //header file
#define uchar unsigned char             //Define variable type as character type
#define uint unsigned int               //Define variable type as long integer
#define LED P0           //Segment code output end of digital tube
#define LED1 P2_6        //Digital tube position 1
#define LED2 P2_4        //Digital tube position 2
#define LED3 P2_5        //Digital tube position 3
#define sx P2_3        //Digital tube position 3

uchar s,i,pd,jsh,ml[3]={0,0,0},zj,xm0,xm1,xm2,xm3,buffer[3];//Variables used in the program
uchar convert[10]={0xA0,0xBD,0x64,0x34,0x39,0x32,0x22,0xBC,0x20,0x30};////0~9 segment code MCU port P0x.0-P0.7 respectively connects to the A, B, F, D, E, H, C, G segments of the digital tube
void delay(i);        //Delay function
void scanLED();        //Display function
void timeToBuffer();      //Display conversion function
void offmsd();        //Hundreds digit is 0 judgment processing module

void main()         //Main program
{
 EA=1;         //Open general interrupt
 ES=1;         //Serial port interrupt enable
 SCON = 0x50;        //Serial port mode 1, allow receiving
 TMOD = 0x21;        //Timer 1 timing mode 2
 TCON = 0x40;        //Timer 1 starts counting
 TH1 = 0xF3;        //6MHz 1200 baud rate
 TL1 = 0xF3;        //6MHz 1200 baud rate
 TI = 0;         //Serial port send interrupt flag set to 0
 RI =0;         //Serial port receive interrupt flag set to 0 
 TR1=1;          //Start timer 1
 sx=0;
 while(1)
 {
  timeToBuffer();      //Call the conversion segment code function module 
    offmsd();       //Call the hundreds digit to judge the processing module
    scanLED();       //Call the display function
 }
}

void delay(i)        //delay subroutine      
{
   while(--i);        //delay loop
}

void scanLED()                   //Display function module
{
 LED=buffer[0];       //Display the single digit value, the segment code of the single digit is sent to the display port
 LED3=0;         //Single digit code, low level is effective, display
 delay(1);        //Display delay, increase the value, display brightness increases
 LED3=1;         //Turn off the display of single digit display
 delay(20);        //Turn off the display delay, decrease the value to increase the display brightness

 LED=buffer[1];       //Display the tens digit value, send the tens digit segment code to the display port
 LED2=0;         //Tens digit code, low level is valid, display
 delay(1);        //Display delay, increase the value, display brightness increases
 LED2=1;         //Turn off the display of tens digit display
 delay(20);        //Turn off the display delay, decrease the value to increase the display brightness

 LED=buffer[2];       //Display the hundreds digit, the hundreds digit segment code is sent to the display port
 LED1=0;         //Hundreds digit code, low level is valid, display
 delay(1);        //Display delay, increase this value, display brightness increases
 LED1=1;         //Turn off the display of hundreds digit display
 delay(20);          //Turn off the display delay, decrease this value to increase the display brightness
}

void offmsd()        //judgment processing module when the hundreds digit is 0
{
   if (buffer[2]==0xA0)      //if the value is zero, the hundreds digit is not displayed
   buffer[2] = 0xff;      //the hundreds digit of the digital tube is all 1, i.e. high level, the hundreds digit is not displayed   
}

void serial() interrupt 4 using 3   //Serial port interrupt receiving program
{
 if(RI)         //Serial port interrupt flag is 1 when the serial port receives data
 {
   RI=0;          //Serial port interrupt flag position 0
   pd=SBUF;        //The received data is sent to the intermediate variable pd for storageif
   (pd==0x20)       //Judge whether the received data is 0x20 (this is the code for the space in ASCII code)
 {
     jsh=0;        //The receiving digit counter jsh is set to 0
     pd=0;         //The intermediate variable pd is cleared to 0
 }
 if(jsh==1)        //When the jsh value is 1, it means that the serial port has received the hundreds digit value sent back by the module
 {
  ml[0]=SBUF;       //The hundreds digit value sent back by the module is stored in the ml[0] unit
 }
 else if(jsh==2)       //When the jsh value is 2, it means that the serial port has received the tens digit value sent back by the module
 {
  ml[1]=SBUF;       //The tens digit value sent back by the module is stored in the ml[1] unit
 }
 else if(jsh==3)       //When the jsh value is 3, it means the serial port receives the unit digit value sent back by the module
 {
  ml[2]=SBUF;       //The unit digit value sent back by the module is received by the serial port and stored in the ml[2] unit
     s=ml[0]*100+ml[1]*10+ml[2];    //Calculate the measured distance value s, in centimeters
 }
  jsh++;               //The received digit counter value is increased by 1
 }
}

void timeToBuffer()          //Conversion segment function module
{
   xm0=ml[0]-48;       //The received value is the standard ASCII code, perform decimal conversion, the value of the hundreds
 digitxm1=ml[1]-48;       //The received value is the standard ASCII code, perform decimal conversion, the value of the tens
   digitxm2=ml[2]-48;       //The received value is the standard ASCII code, perform decimal conversion, the value of the ones digitbuffer
 [0]=convert[xm2];     //Convert to the corresponding display code segmentbuffer
 [1]=convert[xm1];     //Convert to the corresponding display code segmentbuffer
 [2]=convert[xm0];     //Convert to the corresponding display code segmentif
   ((ml[0]==67)&&(ml[1]==67))   //Judge the received ASCII code value as "C", indicating that the module cannot receive the echo, and the display is represented by "CC C" at this time
   
     buffer[0]=0xE2;      //The segment code for displaying "C" is 0xE2buffer
  [1]=0xE2;      //The segment code for displaying "C" is 0xE2
  buffer[2]=0xE2;        //The segment code for displaying "C" is 0xE2   
 }
   else if ((ml[0]==45)&&(ml[1]==45))  //Judge that the received ASCII code value is "-", indicating that the module's measurement range is within the blind area. The display at this time is represented by "- - -"
 {
     buffer[0]=0x7F;      //The segment code for displaying "-" is 0x7F
  buffer[1]=0x7F;      //The segment code for displaying "-" is 0x7F
  buffer[2]=0x7F;       //The segment code for displaying "-" is 0x7F
 }
}

Reference address:RS485 interface integrated ultrasonic distance measurement module

Previous article:Working principle of 8051 microcontroller I/O pins
Next article:51 single chip microcomputer uses C language to realize traffic lights

Recommended ReadingLatest update time:2024-11-15 13:39

Maxim Integrated's IO-Link Smart Temperature Sensor Reference Design
    Maxim Integrated's IO-Link smart temperature sensor reference design reduces costs and increases operating time for industrial control and automation applications.         Beijing, China, March 26, 2015. Maxim Integrated Products, Inc. (NASDAQ: MXIM) introduces the MAXREFDES42# IO-Link temperature sensor
[sensor]
Maxim Integrated's IO-Link Smart Temperature Sensor Reference Design
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号