Temperature measurement DSB1820 lcd1602 liquid crystal display

Publisher:fengtingLatest update time:2015-02-09 Source: 51heiKeywords:DSB1820  lcd1602 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
The LCD1602display.h header file used in the program can be obtained from my other article: http://www.51hei.com/mcu/3292.html is the same file
#include
#include
#include "LCD1602display.h"
sbit DQ=P2^0; //ds18b20
uint wendu=0;
uchar num,num1;
uint temperature=0;
uchar code range[]="===TEMPERTURE===";
uchar code ASCII[]="0123456789.";
uchar code table0[]="ROME TEMP:00.0C ";
uchar code table1[]=" ERRO !!! ";
uchar temp[3]={0,0,0};
//********************Delay
void delay1ms(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=114;y>0;y--);
}
//*************************Initialize
bit init_DS18B20()
{
bit flag; //Store the flag of whether DS18B20 exists, flag=0 means it exists; flag=1 means it does not existDQ
=1;
_nop_(); //Pull up
DQ=0 first;
for(num=0;num<200;num++); //Require to maintain 480~960us
DQ=1; //Release data linefor
(num=0;num<10;num++); //Wait for DS18B20 to respondflag
=DQ; //Responsefor
(num=0;num<200;num++); //Delay long enough (this delay function is to prevent entering a dead end due to lack of signal)
DQ=1; //Release data linereturn
(flag); //Return detection success flag
}
//*******************************Write temperature
datavoid DS18B20_WR_CHAR(uchar byte) // Write low bit first
{
for(num1=0;num1<8;num1++)
{
DQ=1;
_nop_();
DQ=0; // Start writing sequence when the data line is pulled down from high to
lowfor(num=0;num<5;num++);//Wait for 15us
DQ=byte&0x01;
for(num=0;num<15;num++); // Delay about 45us, DS18B20 samples from the data line during about 15~45usbyte
>>=1;
for(num=0;num<1;num++);// Delay 3us, at least 1us recovery period is required between two write sequences
}
DQ=1;//Release data line
}
//**********************************Read temperature data
uchar DS18B20_RD_CHAR() // Read low bit first
{
uchar byte=0;
for(num1=0;num1<8;num1++)
{
DQ=1;
_nop_();
DQ=0; //Give a low pulse
_nop_();
DQ=1;
for(num=0;num<5;num++); //Delay about 15us, so that the host can sample within 15us
byte>>=1;
if(DQ==1)
byte|=0x80;
else
byte|=0x00;
for(num=0;num<1;num++);//Delay 3us, there must be a recovery period greater than 1us between the two read timings
} return ( byte )
;
}
//**** ...temperatureh=0; if(init_DS18B20()==0) { DS18B20_WR_CHAR(0xcc); DS18B20_WR_CHAR(0x44); delay1ms(1000); if(init_DS18B20()==0) { DS18B20_WR_CHAR(0xcc); DS18B20_WR_CHAR(0xBE); _nop_ (); temperaturel=DS18B20_RD_CHAR(); temperatureh=DS18B20_RD_CHAR();















temperature=(temperatureh*256+temperaturel)*0.625;
init_DS18B20();
}
//return (temperature);
}
}
//********************** ********Temperature display
void display_DS18B20()
{
temp[2]=temperature/100%10;
temp[1]=temperature%100/10;
temp[0]=temperature%10;

DisplayListChar(0, 1, table0);
DisplayOneChar(10, 1, ASCII[ temp[2] ] );
DisplayOneChar(11, 1, ASCII[ temp[1] ] );
DisplayOneChar(12, 1, ASCII[10] );
DisplayOneChar(13 , 1, ASCII[ temp[0] ] );
}
//************************************Main function
main( )
{
InitLCM();
DisplayListChar(0,0,range);
DisplayListChar(0,1,table0);
while(1)
{
if( init_DS18B20()==0)
{
DS18B20_WENDU();
display_DS18B20();
}
}
}
Keywords:DSB1820  lcd1602 Reference address:Temperature measurement DSB1820 lcd1602 liquid crystal display

Previous article:C51 MCU serial communication
Next article:Design of digital voice thermometer

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号