Single chip microcomputer TDS water quality detection source program

Publisher:梦中徐来Latest update time:2020-12-21 Source: 51heiKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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

[1] [2]
Keywords:MCU Reference address:Single chip microcomputer TDS water quality detection source program

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

How to implement custom download in operation in STC microcontroller
Users of STC microcontrollers must have had this experience: when burning a program, they must first click the download command, power off, power on, and perform a cold start. The whole process is quite tedious. Here is a custom download method (no need to power off, no need to load the user download file every time).
[Microcontroller]
How to implement custom download in operation in STC microcontroller
[MCU framework][bsp layer][cx32l003][bsp_i2c] I2C/IIC hardware configuration and use
Introduction to I2C I2C is a two-wire bidirectional serial bus that provides a simple and efficient method for exchanging data between devices. The I2C standard is a true multi-host bus with conflict detection and arbitration mechanisms. It prevents data conflicts when two or more hosts request control of the bus at t
[Microcontroller]
[MCU framework][bsp layer][cx32l003][bsp_i2c] I2C/IIC hardware configuration and use
Analysis of Freescale MCU PWM module (2)
Continue to introduce the PWM module of Freescale HCS12 series microcontroller (4) PWM Prescale Select Register PWMPRCLK selects independent prescaler factors for Clock A and B. Read: Any time Write: Any time The bits of the register can be written at any time, and if the polarity is changed while the PWM signa
[Microcontroller]
Analysis of Freescale MCU PWM module (2)
C language tutorial for single chip microcomputers Lesson 5 Constants
In the previous section, we learned about the data types supported by the KEIL C51 compiler. How are these data types used in the definition of constants and variables? Is there anything to pay attention to? Let's take a look. Wow! You still can't distinguish between constants and variables. Constants are quantities th
[Microcontroller]
C language tutorial for single chip microcomputers Lesson 5 Constants
Lightweight menu for microcontroller
Sometimes I need to use a microcontroller to write some larger programs, but there is no need to use some operating systems. I wrote the following lightweight menu state machine, equipped with a display device and 5 inputs (up, down, left, right and press ) Let’s take a look at the renderings first The above ABC,
[Microcontroller]
Study STM32 summary of single chip microcomputer (msp430, c8051, etc.) general learning method
1. A board has the necessary power supply lines and the necessary simulation download and debug lines (such as J-link for STM32)   2. Install the development environment: keil4 (c51 or ARM series registration), it seems that there is also msp430 series. First, make sure what series the board is. IAR EWARM is (ARM
[Microcontroller]
[51 MCU learning process record] 7 Interrupt timer counter 0 understanding before operation
Disclaimer: is all about my own learning and practice. I am just a rookie. All arguments and opinions only represent me. I cannot be sure that they are the truth of this technology. My purpose is to learn and have the possibility to become an experience that can be shared with others. Therefore, if there are mistakes
[Microcontroller]
[51 MCU learning process record] 7 Interrupt timer counter 0 understanding before operation
Design of kitchen control based on PIC microcontroller
    With the continuous development of intelligent home appliance control technology, multifunctional and intelligent kitchen controllers have become the mainstream of kitchen appliance development. Compared with traditional single kitchen equipment controllers, multifunctional kitchen controllers have the advantages o
[Microcontroller]
Design of kitchen control based on PIC microcontroller
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号