Single chip temperature measurement system (AT89C51, DS18B20 temperature sensor, LCD1602)

Publisher:飘然出尘Latest update time:2022-09-06 Source: csdnKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. Introduction

This system is mainly composed of AT89C51, DS18B20 temperature module and LCD1602.

The general principle is that the temperature data collected by DS18B20 is transmitted to P3.3/INT1 (external interrupt 1) of AT89C51, and finally the current real-time temperature is displayed through LCD1602.


2. Rendering

Simulation diagram

3. Source code

/*Want more projects private wo!!!*/

/***************   writer:shopping.w   ******************/

#include

#include

#define uint unsigned int

#define uchar unsigned char

#define delayNOP() {_nop_();_nop_();_nop_();_nop_();}


sbit DQ = P3^3;

sbit LCD_RS = P2^0;

sbit LCD_RW = P2^1;

sbit LCD_EN = P2^2;


uchar code Temp_Disp_Title[]={"Current Temp :   "};

uchar Current_Temp_Display_Buffer[]={" TEMP:   "};


volatile code Temperature_Char[8] = 

{

  0x0c,0x12,0x12,0x0c,0x00,0x00,0x00,0x00

};


uchar code df_Table[]=

{

  0,1,1,2,3,3,4,4,5,6,6,7,8,8,9,9

};


float CurrentT = 0;

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

float Display_Digit[]={0,0,0,0};

bit DS18B20_IS_OK = 1;


void DelayXus(uint x)

{

  flying i;

while(x--)

{

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

}

}


bit LCD_Busy_Check()

{

  bit result;

LCD_RS = 0;

LCD_RW = 1;

LCD_EN = 1;

delayNOP();

result = (bit)(P0&0x80);

LCD_EN=0;

return result;

}


void Write_LCD_Command(uchar cmd)

{

while(LCD_Busy_Check());

LCD_RS = 0;

LCD_RW = 0;

LCD_EN = 0;

_nop_();

_nop_();

P0 = cmd;

delayNOP();

LCD_EN = 1;

delayNOP();

LCD_EN = 0;

}


void Write_LCD_Data(uchar dat)

{

while(LCD_Busy_Check());

LCD_RS = 1;

LCD_RW = 0;

LCD_EN = 0;

P0 = that;

delayNOP();

LCD_EN = 1;

delayNOP();

LCD_EN = 0;

}


void LCD_Initialize()

{

  Write_LCD_Command(0x01);

DelayXus(5);

Write_LCD_Command(0x38);

DelayXus(5);

Write_LCD_Command(0x0c);

DelayXus(5);

Write_LCD_Command(0x06);

DelayXus(5);

}


void Set_LCD_POS(uchar pos)

{

  Write_LCD_Command(pos|0x80);

}


void Delay(uint x)

{

  while(--x);

}


fly Init_DS18B20()

{

  flying status;

DQ = 1;

Delay(8);

DQ = 0;

Delay(90);

DQ = 1;

Delay(8);

DQ = 1;

return status;

}


fly ReadOneByte()

{

  fly i,dat=0;

DQ = 1;

_nop_();

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

{

DQ = 0;

that >>= 1;

DQ = 1;

_nop_();

_nop_();

if(DQ)

that |= 0X80;

Delay(30);

DQ = 1;

}

return that;

}


void WriteOneByte(volatile dat)

{

  flying i;

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

{

DQ = 0;

DQ = that& 0x01;

Delay(5);

DQ = 1;

that >>= 1;

}

}


void Read_Temperature()

{

  if(Init_DS18B20()==1)

DS18B20_IS_OK=0;

else

{

WriteOneByte(0xcc);

WriteOneByte(0x44);

Init_DS18B20();

WriteOneByte(0xcc);

WriteOneByte(0xbe);

Temp_Value[0] = ReadOneByte(); 

Temp_Value[1] = ReadOneByte();

DS18B20_IS_OK=1;

}

}


void Display_Temperature()

{

  flying i;

uchar t = 150, of = 0;

if((Temp_Value[1]&0xf8)==0xf8)

{

Temp_Value[1] = ~Temp_Value[1];

Temp_Value[0] = ~Temp_Value[0]+1;

if(Temp_Value[0]==0x00)

Temp_Value[1]++;

of = 1;

}

Display_Digit[0] = df_Table[Temp_Value[0]&0x0f];

CurrentT = ((Temp_Value[0]&0xf0)>>4) | ((Temp_Value[1]&0x07)<<4);

Display_Digit[3] = CurrentT/100;

Display_Digit[2] = CurrentT%100/10;

Display_Digit[1] = CurrentT%10;

Current_Temp_Display_Buffer[11] = Display_Digit[0] + '0';

Current_Temp_Display_Buffer[10] = '.';

Current_Temp_Display_Buffer[9]  = Display_Digit[1] + '0';

Current_Temp_Display_Buffer[8]  = Display_Digit[2] + '0';

Current_Temp_Display_Buffer[7]  = Display_Digit[3] + '0';

if(Display_Digit[3] == 0)

Current_Temp_Display_Buffer[7]  = ' ';

if(Display_Digit[2] == 0&&Display_Digit[3]==0)

Current_Temp_Display_Buffer[8]  = ' ';

if

{

if(Current_Temp_Display_Buffer[8]  == ' ')

Current_Temp_Display_Buffer[8]  = '-';

else if(Current_Temp_Display_Buffer[7]  == ' ')

Current_Temp_Display_Buffer[7]  = '-';

else 

Current_Temp_Display_Buffer[6]  = '-';

}

Set_LCD_POS(0x00);

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

{

Write_LCD_Data(Temp_Disp_Title[i]);

}

Set_LCD_POS(0x40);

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

{

Write_LCD_Data(Current_Temp_Display_Buffer[i]);

}

Set_LCD_POS(0x4d);

Write_LCD_Data(0x00);

Set_LCD_POS(0x4e);

Write_LCD_Data('C');

}


void main()

{

  LCD_Initialize();

Read_Temperature();

Delay(50000);

Delay(50000);

while(1)

{

Read_Temperature();

if(DS18B20_IS_OK) 

Display_Temperature();

DelayXus(100);

}


}

Keywords:MCU Reference address:Single chip temperature measurement system (AT89C51, DS18B20 temperature sensor, LCD1602)

Previous article:Single chip perpetual calendar (LCD12864, DS18B20, DS1302)
Next article:Single chip real-time clock circuit (LCD1602, DS1302)

Recommended ReadingLatest update time:2024-11-25 04:23

Artly has made another breakthrough in the field of automotive electronics. AT32 MCU is widely used in ADAS surround view systems
With the rapid development of urbanization and the improvement of people's living standards, the number of urban motor vehicles has increased rapidly, and road traffic safety issues have become increasingly prominent. Many times, this is due to the driver's safety awareness, illegal driving, road conditions, fatigue d
[Automotive Electronics]
Artly has made another breakthrough in the field of automotive electronics. AT32 MCU is widely used in ADAS surround view systems
Design program of electronic speed and mileage anti-theft alarm based on 51 single chip microcomputer
    //************************************************ ************     //Title: 4x4 keyboard input function // Function description: char gotkey(void) // Input data from the 4*4 keypad and return 0~9, and other data. //*********************************************************** //Time delay function //***************
[Microcontroller]
Fire control system signal acquisition test based on STM32 microcontroller
The fire control system is a system that controls the aiming and firing of artillery. The fire control computer is the core of the fire control system and plays an important role in completing the fire control solution and guiding the firing of anti-aircraft artillery. Since the fire control system has many signals
[Microcontroller]
Fire control system signal acquisition test based on STM32 microcontroller
STM32 MCU (10) Digital tube output experiment [supplement] Static (common anode) + dynamic (common cathode)
Note: When using the Puzhong Technology Development Board for testing, you need to unplug the Boot1 socket Reference manual, circuit diagram, etc. See  STM32 MCU Learning (1) Total Learning Materials + Reference Manual + LED Light   Static digital tube experiment /***************************************************
[Microcontroller]
LED display design based on STC89C52 microcontroller
With the widespread application of LED displays in the advertising field, control systems are also gradually developing. Since the control system is developed based on an embedded microprocessor, the microcontroller plays a very important role in it. The control of LED display screens is relatively complex, especially
[Microcontroller]
LED display design based on STC89C52 microcontroller
A remote temperature monitoring system based on single chip microcomputer and FPGA
Temperature has different degrees of influence on industrial and agricultural production and national defense. There are many kinds of power equipment failures, but most of them are accompanied by heating, and the loss of an accident is huge; in industries such as textiles, food, and tobacco, high temperatures can e
[Embedded]
A remote temperature monitoring system based on single chip microcomputer and FPGA
Low-Cost Digital Thermometer Using a Single-Chip Microcontroller
In many applications, the ability to sense and display temperature is desirable or absolutely necessary. Temperature probes, thermostats, CPU monitors, and process control equipment are some of these applications. The illustration shows a simple system for temperature sensing and display. The circuit requires only a mi
[Microcontroller]
Design of Audio Signal Analyzer Based on DSPIC30F6014A Single Chip Microcomputer
At present, most audio signal processors are not only large in size but also expensive, and are difficult to be popularized in some special aspects. Embedded system analyzers are small and reliable, so the development of audio analysis instruments based on special function microcontrollers is the basis of speech recogn
[Microcontroller]
Design of Audio Signal Analyzer Based on DSPIC30F6014A Single Chip Microcomputer
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号