51 MCU Thermometer 2.0 Version ds18b20 + 0.96 inch OLED IIC Display

Publisher:AsawenLatest update time:2021-01-04 Source: 51hei Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere


The 51 single-chip thermometer LCD1602 display was successful, so the challenge was to use OLED display

main.c


#include"oled.h"

#include"ds18b20_1.h"


void Timer0Init(void);

//void Gao_Wen(void);

//void GaoDiInit(void);                     


sbit Deng=P1^0; //LED灯

sbit FengMing=P1^1; //Buzzer

sbit GD=P3^0; //Two functions: lower the upper temperature limit and turn off the LED light

sbit GF=P3^1; //Two functions: increase the low temperature limit and turn off the buzzer

sbit GW=P3^2; //Upper temperature limit increases

sbit DW=P3^3; //lower limit temperature decreases


//unsigned char GaoWen_Y[]={"GW:"}; //high limit temperature display

//unsigned char DiWen_Y[]={"DW:"}; //low limit temperature display


int GaoWen=40; ​​//High limit temperature

int DiWen=-20; //low limit temperature

char flag=0; //One second flag

char b=0; //Internal flag of timer;



/*******************************Main program area************************************/



int main()

{

        bit ack;

        bit k=1; //After the temperature exceeds the limit, the light and buzzer will be turned off and will not sound anymore. However, after the temperature falls below the limit and exceeds the limit again, the buzzer will still sound.

        int Zhen=0,Xiao=0;

        unsigned char temp[10];

        char len=0;

        int wenDu=0; //Receive temperature

//        LCD_Init();

        Deng=0; //LCD initialization

        OLED_Init();

        Start18B20(); //Temperature sensor initialization

        Timer0Init(); //T0 timer initialization

        Delay10ms();


// LCD_WeiZhi(1,0);

// LCD_XianShi(GaoWen_Y);

// LCD_WeiZhi(1,9);

// LCD_XianShi(DiWen_Y);

// GaoDiInit();

        OLED_ShowChinese(0,0,10,16);

        OLED_ShowChinese(18,0,13,16);

        OLED_ShowChar(36,0,':',16);

       

        OLED_ShowChinese(0,2,8,16);

        OLED_ShowChinese(18,2,10,16);

        OLED_ShowChinese(36,2,11,16);

        OLED_ShowChinese(54,2,12,16);

        OLED_ShowChar(70,2,':',16);

       

        OLED_ShowChinese(0,4,9,16);

        OLED_ShowChinese(18,4,10,16);

        OLED_ShowChinese(36,4,11,16);

        OLED_ShowChinese(54,4,12,16);

        OLED_ShowChar(70,4,':',16);

//        OLED_ShowString(0,2,"GW:",16);

//        OLED_ShowString(64,2,"DW:",16);

        OLED_Num(78,2,GaoWen,3,16);

        OLED_Num(78,4,DiWen,3,16);

       

        while(1)

        {


                if(flag==1) //Refresh temperature in 1 second

                {

                        flag=0;

                        ack=Read18B20(&wenDu);

                  if(ack)

                        {

                                Zhen=wenDu>>4;

                                Xiao=wenDu&0x0f;

                                len=OLED_Xian_Zheng(Zhen,temp);

                                temp[len++]='.';

                                Xiao=(Xiao*100)*0.0625;

                                temp[len++]=Xiao/10+'0';

//                                temp[len++]=Xiao%10+'0';

                                while(len<5)

                                {

                                        temp[len++]=' ';

                                }

                                temp[len]='';

// LCD_WeiZhi(0,0);

// LCD_XianShi(temp);

                                OLED_ShowString(44,0,temp,16);

                        }

                        Start18B20();

                }

                OLED_Num(78,2,GaoWen,3,16);

                OLED_Num(78,4,DiWen,3,16);

                if((Zhen>=GaoWen||Zhen<=DiWen)&&k)

                {

                        Deng=1;

                        FengMing=0;       

                }


                if(Zhen>DiWen&&Zhen                {

                        Deng=0;

                        FengMing=1;

                        k=1;

                }

                if(GD==0)

                {

                        Delay10ms();

                        if(GD==0)

                        {

                                if(Deng==0)

                                {

                                        Gao Wen--;

//                                        Delay400ms();

// GaoDiInit();

//OLED_Num(20,2,GaoWen,3,16);

                                }

                                else

                                {

//                                        Delay400ms();

                                        Deng=0;       

                                        k=0;

                                }

                        }                                       

                }

                if(GF==0)

                {

                        Delay10ms();

                        if(GF==0)

                        {

                                if(FengMing==1)

                                {

                                        DiWen++;

//                                        Delay400ms();

// GaoDiInit();

//                                        OLED_Num(84,2,DiWen,3,16);

                                }

                                else

                                {

//                                        Delay400ms();

                                        FengMing=1;

                                        k=0;

                                }       

                        }               

                }

        }

}

/************************************Timer initialization******************************/

        void Timer0Init(void) //50 milliseconds@12.000MHz

{

        EA=1;

        ET0=1;

        EX0=1;

        EX1=1;

        IT0=1;

        IT1=1;

  IP=0;

        PT0=1;

        TMOD &= 0xF0; //Set timer mode

        TMOD |= 0x01; //Set timer mode

        TL0 = 0x00; //Set the initial timing value

        TH0 = 0x4C; //Set the initial timing value

        TF0 = 0; // Clear TF0 flag

        TR0 = 1; //Timer 0 starts timing

}

/******************************T0 interrupt**********************************/

void IT0_1(void) interrupt 1

{

        TL0 = 0x00; //Set the initial timing value

        TH0 = 0x4C; //Set the initial timing value

        b++;

        if(b>=20)

        {

                b=0;

                flag=1;

        }

}


/***************************High limit temperature increase****************************************/

void Gao(void) interrupt 0

{

        GaoWen++;

        if(GaoWen>128)

        {

                GaoWen=128;

                FengMing=0;

                Delay100ms();

                FengMing=1;       

        }

// GaoDiInit();

//OLED_Num(20,2,GaoWen,3,16);


}

/*******************************Lower limit temperature decreases********************************/

void Di(void) interrupt 2

{

        DiWen--;

        if(DiWen<-55)

        {

                DiWen=-55;

                FengMing=0;

                Delay100ms();

                FengMing=1;       

        }

//        OLED_Num(84,2,DiWen,3,16);

// GaoDiInit();

//OLED_Num(84,2,GaoWen,3,16);


}


Reference address:51 MCU Thermometer 2.0 Version ds18b20 + 0.96 inch OLED IIC Display

Previous article:Design and production of digital temperature display based on single chip microcomputer
Next article:51 MCU uses DAC0832 to program the output of square wave, sawtooth wave, triangle wave, sine wave

Recommended ReadingLatest update time:2024-11-16 13:47

51 MCU implements printf function
Using the printf function is very convenient when debugging, so it is very necessary to implement this function first during the development process. After sorting out the online information, I found that it is very simple to implement the printf function. First, add the stdio.h header file, and then add the following
[Microcontroller]
How to design a more energy-efficient OLED power supply
It is the so-called organic light-emitting diode. Its biggest feature is that it is a self-luminous body, so it does not need a backlight (Backlight) and a color filter (Color Filter) and other structures, so it can be thinner than LCD. In addition, the advantages of wider viewing angle, fast response speed, low dri
[Power Management]
How to design a more energy-efficient OLED power supply
Timer and counter in 51 single chip microcomputer
From the structure diagram of the timer/counter above, we can see that the 16-bit timer/counter is composed of two 8-bit dedicated registers, namely: T0 is composed of TH0 and TL0; T1 is composed of TH1 and TL1. Its access address is 8AH-8DH. Each register can be accessed separately. These registers are used to st
[Microcontroller]
Timer and counter in 51 single chip microcomputer
51 single chip microcomputer electronic clock program
This is an electronic clock program made with microcontroller simulation software. The circuit diagram is below: #include reg52.h #include intrins.h #include stdlib.h #define uint unsigned int #define uchar unsigned char sbit RS=P2^0; sbit RW=P2^1; sbit E=P2^ 2; sbit BF=P0^7; sbit d=P2^3; unsigned char
[Microcontroller]
51 single chip microcomputer electronic clock program
AT89C51 microcontroller assembly language to write alarm signal program
Use P1.0 to output 1KHz and 500Hz audio signals to drive the speaker as an alarm signal. It is required that the 1KHz signal sound for 100ms and the 500Hz signal sound for 200ms, alternating between them. ; Use P1.0 to output 1KHz and 500Hz audio signals to drive the speaker ;Requires 1KHz signal to ring for 100ms
[Microcontroller]
51 single chip microcomputer - digital tube static display
1. Find the corresponding control port from the schematic diagram This time, we want to display the value on the digital tube. Similarly, first find the control port corresponding to the digital tube in the development board schematic diagram.         It is found that if the digital tube is to work, LEDS0
[Microcontroller]
51 single chip microcomputer - digital tube static display
Basic operation of 8051 microcontroller
1. P0   1.1 Composition   1.2 Make input port   1.3 Make output port 2.P1   2.1 Composition   2.2 Make input port   2.3 Make output port 3.P2   3.1 Composition   3.2 Make input port   3.3 Make output port 4. P3   4.1 Composition   4.2 Make input and output ports 5. Summary 51 microcontroller parallel GPIO, divided int
[Microcontroller]
Basic operation of 8051 microcontroller
Design of digital ultrasonic distance meter based on AT89C51 single chip microcomputer
Ultrasonic waves are often used to measure distances due to their strong directivity, slow energy consumption, and long propagation distance. For example, distance meters and level meters can be realized through ultrasonic waves. Ultrasonic distance measurement is mainly used in reversing radars, construction sites, a
[Microcontroller]
Design of digital ultrasonic distance meter based on AT89C51 single chip microcomputer
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号