1. The system is based on the low-power AT89S51 single-chip microcomputer. The multivibrator composed of the LCD555 timer generates a wave of a certain frequency, and then the I/O interface of the single-chip microcomputer captures the high and low level readout frequencies, and then converts them into resistance values through program algorithm processing. DS18B20 is used as the temperature acquisition module. After data conversion and processing by the host, the temperature value is displayed on the character LCD 1602 display. This design has a simple structure and flexible use, and has great use and research value.
2. Instructions for use: Burn the program to the microcontroller. At this time, disconnect the Bluetooth serial port first. After downloading the program, connect the Bluetooth module, put the probe into the water, open the Bluetooth serial port assistant on the mobile phone, search and pair the Bluetooth, press the button to send data, and the mobile phone will receive the corresponding measurement data.
3. Result: The TDS value of the water quality is measured and the relevant measurement value can be obtained on the mobile phone through Bluetooth transmission
The microcontroller source program is as follows:
/*******************************************************************************
--------------------------------------------------------------------------------
* Experiment name: TDS display test
* Experimental description: LCD1602 displays TDS.
* Connection method: See connection diagram
* Note :
*******************************************************************************/
#include #include"lcd.h" #include"temp.h" unsigned char code buf3[]={"evaluation:Suggested filteringnn"}; unsigned char code buf2[]={"evaluation:Slight solute in waternn"}; unsigned char code buf1[]={"evaluation: less solute in waternn"}; unsigned char code buf4[]={"Warningnn"}; long caculate_TDS(int temp); void LcdDisplay(int temp); void TDSDisplay(int temp); void send(); void PutString(unsigned char *TXStr); unsigned int count; sbit key=P1^4; sbit key1=P1^3; unsigned int FreResultFlag; unsigned int FreNum; /******************************************************************************* * Function name: Timer0 * Description: Interrupt program, re-assign the value to start timing after the timing time is up, and invert the state of the LED. ********************************************************************************/ void time0(void) interrupt 1 { unsigned char i; TH0=(65536-46083)/ 256; TL0=(65536-46083)% 256; i++; if(i==20) { i=0; count=TH1*256+TL1; TH1=0x00; TL1=0x00; } } /******************************************************************************* * Function name: main * Function: Main function * Input : None * Output: None *******************************************************************************/ void main() { unsigned char flag=1; TMOD=0x51; TH0=(65536-46083)/ 256; TL0=(65536-46083)% 256; TH1 = TL1 = 0; EA=1; ET0=1; TR0 = 1; TR1 = 1; LcdInit(); //Initialize LCD1602 LcdWriteCom(0x88); //Write address 80 indicates the initial address LcdWriteData('C'); while(1) { //LcdDisplay(); // Delay1ms(1000); // refresh once every 1s if( FreResultFlag ) { FreNum = (TH1 * 256 + TL1); TH1 = 0; TL1 = 0; FreResultFlag = 0; TR1 = 1; TR0 = 1; LcdDisplay(Ds18b20ReadTemp()); TDSDisplay(caculate_TDS(Ds18b20ReadTemp())); send(); UsartConfiguration(); } } } /******************************************************************************* * Function name: LcdDisplay() * Function: LCD displays the temperature read * Input: v * Output: None *******************************************************************************/ void LcdDisplay(int temp) //lcd display { unsigned char datas[] = {0, 0, 0, 0, 0}; //define array float tp; if(temp< 0) //When the temperature value is negative { LcdWriteCom(0x80); //Write address 80 indicates the initial address LcdWriteData('-'); //Display negative //Because the temperature read is the complement of the actual temperature, subtract 1 and then invert it to get the original code temp=temp-1; temp=~temp; tp=temp; temp=tp*0.0625*100+0.5; //Leave two decimal points and *100, +0.5 is rounded, because the decimal point is rounded when the C language floating point number is converted to an integer //The number behind is automatically removed, regardless of whether it is greater than 0.5, and after +0.5, the number greater than 0.5 is increased by 1, and the number less than 0.5 is increased by 1. //Calculated by ?.5, still after the decimal point. } else { LcdWriteCom(0x80); //Write address 80 indicates the initial address LcdWriteData('+'); //Display positive tp=temp; //Because the data processing has a decimal point, the temperature is assigned to a floating point variable //If the temperature is positive, then the original code of the positive number is the complement code itself temp=tp*0.0625*100+0.5; //Leave two decimal points and *100, +0.5 is rounded, because the decimal point is rounded when the C language floating point number is converted to an integer //The number behind is automatically removed, regardless of whether it is greater than 0.5, and after +0.5, the number greater than 0.5 is increased by 1, and the number less than 0.5 is increased by 1. // Add 0.5, or after the decimal point. } datas[0] = temp / 10000; datas[1] = temp % 10000 / 1000; datas[2] = temp % 1000 / 100; datas[3] = temp % 100 / 10; datas[4] = temp % 10; LcdWriteCom(0x82); //Write address 80 indicates the initial address LcdWriteData('0'+datas[0]); //Hundreds digit LcdWriteCom(0x83); //Write address 80 indicates the initial address LcdWriteData('0'+datas[1]); //ten digits LcdWriteCom(0x84); //Write address 80 indicates the initial address LcdWriteData('0'+datas[2]); //unit LcdWriteCom(0x85); //Write address 80 indicates the initial address LcdWriteData('.'); //Display '.' LcdWriteCom(0x86); //Write address 80 indicates the initial address LcdWriteData('0'+datas[3]); //Display decimal point LcdWriteCom(0x87); //Write address 80 indicates the initial address LcdWriteData('0'+datas[4]); //Display decimal point } /******************************************************************************* * Function name: TDSDisplay() * Function: LCD displays the read * Input: v * Output: None *******************************************************************************/ void TDSDisplay(int TDS) //lcd display { unsigned char datas[] = {0, 0, 0, 0, 0, 0}; //define array // float tp; // if(temp< 0) // when the temperature value is negative // { // LcdWriteCom(0x80+0x40); //Write address 80 indicates the initial address // LcdWriteData('-'); //Display negative // //Because the temperature read is the complement of the actual temperature, subtract 1 and then invert it to get the original code // temp=temp-1; // temp=~temp; // tp=temp; // temp=tp*0.0625*100+0.5; // //Leave two decimal points and *100, +0.5 is rounded, because the decimal point is rounded when the C language floating point number is converted to an integer // //The number behind is automatically removed, regardless of whether it is greater than 0.5, and after +0.5, the number greater than 0.5 is increased by 1, and the number less than 0.5 is increased by 1. // //Calculated by ?.5, still after the decimal point. // // } // else // { // LcdWriteCom(0x80+0x40); //Write address 80 indicates the initial address // LcdWriteData('+'); //Display positive // tp=temp; //Because the data processing has a decimal point, the temperature is assigned to a floating point variable // //If the temperature is positive, then the original code of the positive number is the complement code itself // temp=tp*0.0625*100+0.5; // //Leave two decimal points and *100, +0.5 is rounded, because the decimal point is rounded when the C language floating point number is converted to an integer // //The number behind is automatically removed, regardless of whether it is greater than 0.5, and after +0.5, the number greater than 0.5 is increased by 1, and the number less than 0.5 is increased by 1. // //Add 0.5, or after the decimal point. // } datas[0] = TDS / 100000; datas[1] = TDS % 100000 / 10000; datas[2] = TDS % 10000 / 1000; datas[3] = TDS % 1000 / 100; datas[4] = TDS % 100 / 10; datas[5] = TDS % 10 ; LcdWriteCom(0x81+0x40); //Write address 80 indicates the initial address
Previous article:51 MCU Basic Calculator
Next article:Four-way buzzer based on Puzhong Technology 51 single-chip microcomputer
Recommended ReadingLatest update time:2024-11-15 16:24
- Popular Resources
- Popular amplifiers
- Wireless Sensor Network Technology and Applications (Edited by Mou Si, Yin Hong, and Su Xing)
- Modern Electronic Technology Training Course (Edited by Yao Youfeng)
- Modern arc welding power supply and its control
- Small AC Servo Motor Control Circuit Design (by Masaru Ishijima; translated by Xue Liang and Zhu Jianjun, by Masaru Ishijima, Xue Liang, and Zhu Jianjun)
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
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- 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
- [RVB2601 Creative Application Development] - Speed and swing control of air conditioning fan (1)
- Reasons for the Sync with database failed and compile chipwatcher failed errors in Anlu TangDynasty
- Today at 10:00 AM, live broadcast with prizes: Future perception is predicted by me - the latest application of sensors in the Internet of Things
- I need help. I am using AD17 to learn how to draw a 4-layer board. Is there any good teaching guide?
- Switching Power Supply Interest Group 18th Task
- 5V to 1.8
- Also on the G-question of the electronic competition
- Basic Concepts of A/D and D/A
- How to use CoolMOS in a continuous conduction mode totem pole power factor correction circuit
- Dear masters, please answer this for me. I am waiting.