51 MCU CO2 detection display program data

Publisher:东土大唐88Latest update time:2017-09-02 Source: elecfans Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

This is a 51 single-chip CO2 detection display program data. The T (TXD) of the carbon dioxide sensor MH-Z19 module is connected to the RXD of the single-chip microcomputer, the R (RXD) is connected to the TXD of the single-chip microcomputer, the V+ is connected to the 5v positive pole of the single-chip microcomputer, and the V- is connected to the ground of the single-chip microcomputer (serial TTL communication requires connecting these four wires); the measurement voltage is 5V; the single-chip microcomputer model is STC89C52, the LCD display model is LCD1602, and the circuit connection is according to the test diagram; the serial communication baud rate is 9600, and the crystal oscillator must be 11.0592M, otherwise it will cause communication failure; the sensor needs to be preheated for 3 minutes when powered on.

51 MCU CO2 detection display program data

51 MCU CO2 detection display program data

#include"reg52.h"

#include"stdio.h"

#include"intrins.h"

#include"lcd1602.H"

#define uchar unsigned char

#define uint unsigned int

#define long unsigned long 

uchar code tab[9]={0xff,0x01,0x86,0x00,0x00,0x00,0x00,0x00,0x79};

uchar  date[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

 

void delayms(uint xms)

{

uint x,y;

for(x=xms;x>0;x--)

for(y=110;y>0;y--);

}

 

 void send(uchar dat) //Send one byte    

 {

  SBUF=dat;

  while(!IF);

  IF = 0;

 }

 

 

void main(void)

{

 uint  tmp;

 flying i;

 TMOD=0x20; // T1 timing mode 2

 SCON=0x40; //Serial working mode 1

 PCON=0x00; //Not doubled

 TH1=TL1=0xfd; //Assign initial value to timer 1 to ensure baud rate is 9600

 TR1=1; //Start timer 1

 REN=1; // Allow serial port to receive

init_1602(); //LCD initialization

delayms(10);

 ES=1; //Open serial port interrupt

 EA=1; //Open the general interrupt

while(1)

{

 for(i=0;i<9;i++) //Send data to the co2 sensor

   {

    send(tab[i]);

   }

  delayms(1000); // Delay one second to refresh the measured data

   

             tmp=date[2]*256+date[3]; //Calculate the CO2 concentration

if(tmp>9999)

tmp=0;   

        WRITE_LCD1602_COM(0x80+8);

if((tmp/1000)>0)

        WRITE_LCD1602_DAT(LCD1602_Table[tmp/1000]);

        else WRITE_LCD1602_DAT(' '); 

             WRITE_LCD1602_DAT(LCD1602_Table[tmp00/100]);

        WRITE_LCD1602_DAT(LCD1602_Table[tmp0/10]);

        WRITE_LCD1602_DAT(LCD1602_Table[tmp]);

}

   }

 void serial()interrupt 4 //Serial port interrupt service function

  {

   static uchar j;

   ES=0; //Disable interrupts

   if(!RI);

   RI=0; //Clear reception completion mark

   date[j]=SBUF; 

   if(date[0]==0xff) //Judge the first received bit as the data sent by the sensor

      j++;

  else

      j=0;

   if(j==9) //Receive 9 bytes of data sent by the sensor

     j=0; 

   ES=1; //Enable serial port interrupt

   

  }

//////////////////////////////////////////////////////////////////////////////////////////////

lcd1602.H:

#define uchar unsigned char

#define uint unsigned int           

sbit RS=P2^5;

sbit RW=P2^6;

sbit EN=P2^7;

uchar LCD1602_Table[]="0123456789";

//LCD1602 display scale //0123456789abcdef

uchar code DIS_TIM[16] = {" PPM="}; //Display temperature and humidity

uchar code DIS_STA[16] =   {"  Test is   oK! "}; //

uchar code DIS[16] =       {"alarm       ppm"}; //

extern void delayms(uint xms);

void WRITE_LCD1602_DAT(uchar date)

{

EN=0;

RS=1;

P0=date;

EN=1;

delayms(2);

EN=0;

}

void WRITE_LCD1602_COM(uchar date)

{

EN=0;

RS=0;

P0=date;

EN=1;

delayms(2);

EN=0;

}

void init_1602()

{

  unsigned char i;

RW=0;

WRITE_LCD1602_COM(0x38);

WRITE_LCD1602_COM(0x0c);

WRITE_LCD1602_COM(0x06);

WRITE_LCD1602_COM(0x01);

WRITE_LCD1602_COM(0x80);

for(i=0;i<8;i++)

WRITE_LCD1602_DAT(DIS_TIM[i]);

}


Reference address:51 MCU CO2 detection display program data

Previous article:Single chip microcomputer DTH11 temperature and humidity measurement simulation
Next article:51 single chip washing machine control board and C language program

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号